Grid becomes very slow with 2 instances...

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

jpp
Posts: 34
Joined: Thu Jan 16, 2014 3:04 pm

Grid becomes very slow with 2 instances...

Post by jpp » Mon Feb 17, 2014 5:15 pm

Hi to all !

After a week end in front of HMG grid, i'm near the Burnout ...

I've made a sample pgm to explain my problem.

App and dbf are on a shared folder
if i run the app on a client all is OK ( loading time / Refresh about 500 ms )
if i run the app on another client the loading time / Refresh becomes 13 seconds on the both computers.

I've made test on three differents networks but allways the same and i really dont know what can be wrong
in my program.
you are my only chance, otherwise all i've made since one month will be unusable ....

Thanks a lot ...


/*

*/

#include "hmg.ch"

Function Main

RDDSETDEFAULT( "DBFNTX" )

DEFINE WINDOW Form_D ;
AT 0,0 ;
WIDTH 800 ;
HEIGHT 510 ;
TITLE 'Multiple Index Test' ;
MAIN

DEFINE MAIN MENU
POPUP 'DataBase'
ITEM "Create Test DataBase" ACTION test_database()
ITEM "Test Grid DataBase" ACTION testgrid()
end popup
end menu
end window

activate window form_d

return

proc test_database
LOCAL aStruct := { ;
{ "CODE", "C", 10, 0 }, ;
{ "FIRST" , "C", 30, 0 }, ;
{ "LAST" , "C", 30, 0 }, ;
{ "BIRTH" , "D", 30, 0 } ;
}

if file("test.dbf")
ferase("test.dbf")
endif
DbCreate( "test", aStruct, "DBFNTX", .T. )

for f:=1 to 10000
append blank
repla Code with "CODE "+ str(f,5,0)
repla FIRST with "first "+ str(f,5,0)
repla LAST with "last "+ str(f,5,0)
repla birth with date()+f
next
if file("test1.ntx")
ferase("test1.ntx")
endif
if file("test2.ntx")
ferase("test2.ntx")
endif
if file("test3.ntx")
ferase("test3.ntx")
endif
if file("test4.ntx")
ferase("test4.ntx")
endif

index on code to test1
index on first to test2
index on last to test3
index on first+last to test4

dbcloseall()
return

proc testgrid
local t1:= HB_milliseconds(), t2

DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 800 ;
HEIGHT 510 ;
TITLE 'Multiple Index Test' ;
CHILD ;
ON RELEASE DBCLOSEALL()

use test Shared index test1,test2,test3,test4

DEFINE MAIN MENU
POPUP 'Test'
ITEM 'Order 1 ' ACTION Ordertest(1)
ITEM 'Order 2 ' ACTION Ordertest(2)
ITEM 'Order 3 ' ACTION Ordertest(3)
ITEM 'Order 4 ' ACTION Ordertest(4)
END POPUP
END MENU


@ 10,10 GRID Grid_1 ;
WIDTH 770 ;
HEIGHT 400 ;
HEADERS {'Column 1','Column 2','Column 3','Column 4'} ;
WIDTHS {140,140,140,100};
VALUE { 1 , 1 } ;
ROWSOURCE "Test" ;
COLUMNFIELDS { 'Code' , 'First' , 'Last' , 'Birth' }

END WINDOW

t2:= HB_milliseconds()
msgbox("Loading time " + str(t2-t1,5,0))

CENTER WINDOW Form_1

ACTIVATE WINDOW Form_1

Return



Procedure OrderTest(n)
local t1,t2
t1:= HB_milliseconds()
dbsetorder(n)

Form_1.Grid_1.Refresh
t2:= HB_milliseconds()
msgbox("refrestime " + str(t2-t1,5,0))

Return

jpp
Posts: 34
Joined: Thu Jan 16, 2014 3:04 pm

Re: Grid becomes very slow with 2 instances...

Post by jpp » Mon Feb 17, 2014 6:48 pm

Hi

I'have made an other test, and i am very in trouble

just a simple grid with a dbf on a shared folder, the browse of the database with pagedown is very quick.

if simply open the database and it's index on another pc on the network and the pagedown on the first pc becomes slow ...

i really do not know what to do ...

Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: Grid becomes very slow with 2 instances...

Post by Javier Tovar » Mon Feb 17, 2014 7:05 pm

Hi jpp,

Run your program and apparently runs fast, I think the problem is that you must not delete the database that the previous user already opened, you must open the database with "USE MyDatabase MiAlias ​​NEW SHARED ALIAS" as "sHARED" is to share the dbf's in "RED" mode.

I hope help you.

regards

Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: Grid becomes very slow with 2 instances...

Post by Javier Tovar » Mon Feb 17, 2014 8:34 pm

Hi jpp,

I modified your program a little, in essence use CDX indices and increase the speed twice, but still, if the refresh is slow GRID., By time I can not do more tests, hopefully someone will help us.

Greetings.

Code: Select all

#include "hmg.ch"

Function Main
Public ccDirData  := "\\Principal\Test2"      //ES LA RUTA DE LA CARPETA DONDE ESTAN LAS DBF Y CDX.

RDDSETDEFAULT( "DBFNTX" )

SET PATH    TO ( ccDirData )
SET DEFAULT TO ( ccDirData )

REQUEST DBFCDX
RddSetDefault( "DBFCDX" )

DEFINE WINDOW Form_D ;
AT 0,0 ;
WIDTH 800 ;
HEIGHT 510 ;
TITLE 'Multiple Index Test' ;
MAIN

DEFINE MAIN MENU 
POPUP 'DataBase'
ITEM "Create Test DataBase" ACTION test_database() 	//
ITEM "Test Grid DataBase" ACTION testgrid()
end popup
end menu
end window

activate window form_d

return 


proc test_database
LOCAL aStruct := { ;
{ "CODE", "C", 10, 0 }, ;
{ "FIRST" , "C", 30, 0 }, ;
{ "LAST" , "C", 30, 0 }, ;
{ "BIRTH" , "D", 30, 0 } ;
}

SET PATH    TO ( ccDirData )
SET DEFAULT TO ( ccDirData )

REQUEST DBFCDX
RddSetDefault( "DBFCDX" )


if file("test.dbf")
ferase("test.dbf")
endif
DbCreate( "test", aStruct, "DBFCDX", .T. )

for f:=1 to 10000
append blank
repla Code with "CODE "+ str(f,5,0)
repla FIRST with "first "+ str(f,5,0)
repla LAST with "last "+ str(f,5,0)
repla birth with date()+f
next
/*
if file(ccDirData+"/test1.ntx")
ferase("test1.ntx")
endif
if file("test2.ntx")
ferase("test2.ntx")
endif
if file("test3.ntx")
ferase("test3.ntx")
endif
if file("test4.ntx")
ferase("test4.ntx")
endif
*/
INDEX ON Code TAG Test1
INDEX ON First TAG Test2
INDEX ON Last TAG Test3
INDEX ON First+Last TAG Test4
/*
index on code to test1
index on first to test2
index on last to test3
index on first+last to test4
*/
dbcloseall()
return
*/

proc testgrid
local t1:= HB_milliseconds(), t2

REQUEST DBFCDX
RddSetDefault( "DBFCDX" )

SET PATH    TO ( ccDirData )
SET DEFAULT TO ( ccDirData )


DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 800 ;
HEIGHT 510 ;
TITLE 'Multiple Index Test' ;
CHILD ;
ON RELEASE DBCLOSEALL()

use test NEW Shared 
      Test->(ORDSETFOCUS('Test1'))
      Test->(ORDSETFOCUS('Test2'))
      Test->(ORDSETFOCUS('Test3'))
      Test->(ORDSETFOCUS('Test4'))
*index test1,test2,test3,test4

DEFINE MAIN MENU 
POPUP 'Test'
ITEM 'Order 1 ' ACTION Ordertest(1)
ITEM 'Order 2 ' ACTION Ordertest(2)
ITEM 'Order 3 ' ACTION Ordertest(3)
ITEM 'Order 4 ' ACTION Ordertest(4)
END POPUP
END MENU


@ 10,10 GRID Grid_1 ;
WIDTH 770 ;
HEIGHT 400 ;
HEADERS {'Column 1','Column 2','Column 3','Column 4'} ;
WIDTHS {140,140,140,100};
VALUE { 1 , 1 } ;
ROWSOURCE "Test" ;
COLUMNFIELDS { 'Code' , 'First' , 'Last' , 'Birth' } 

END WINDOW

t2:= HB_milliseconds()	
msgbox("Loading time " + str(t2-t1,5,0))

CENTER WINDOW Form_1

ACTIVATE WINDOW Form_1

Return



Procedure OrderTest(n)
local t1,t2
t1:= HB_milliseconds()
dbsetorder(n)

Form_1.Grid_1.Refresh
t2:= HB_milliseconds()	
msgbox("refrestime " + str(t2-t1,5,0))

Return

Regards

jpp
Posts: 34
Joined: Thu Jan 16, 2014 3:04 pm

Re: Grid becomes very slow with 2 instances...

Post by jpp » Mon Feb 17, 2014 8:46 pm

hi javier,

thx for your answer and your test . in time i've made the tests as you with dbfcdx, but it's still too slow
in a professional environment.

( i've made the same test with my old clipper, and still really faster in all the ways ! )

I've made an other test to understand the pb,

i have a database in a shared folder in the server.
on a client i open in shared mode the database and i just make a loop
proc main
use test new shared index test1, test2, test3, test4
t1=hb_milliseconds()
dbgotop()
while !eof()
dbskip()
enddo
t2=hb_milliseconds()
msgbox("time to skip " + str(t2-t1,8,0))
dbcloseall()
return

i have a result of 180 ms

now, i just open the database with indexes on an other computer

proc main
use test new shared index test1, test2, test3, test4
msgbox( "wait to close")
dbcloseall()
return

then i re-do the same test on the first computer and the time is about 7000 ms !

I will be very happy if somebody could make the same test, because if the results are the same it is impossible to
program some app in a network share.

this little sample explains why networking's grid with a lot ( 2 or 3 ! ) of users becomes very slow, because grid uses GetDataGridRecCount() , and GetDataGridRecCount() uses 'count to' which is so slow as dbskip when the database is open
on differents computers.

i will go to bed, perhaps the solution will come tomorow .... :(

Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: Grid becomes very slow with 2 instances...

Post by Javier Tovar » Mon Feb 17, 2014 8:57 pm

Hola jpp, antes que te vayas a dormir...

Lo que yo he observado en una aplicación en RED, es que si se puede manejar muy agradablemente, por falta de tiempo ahorita no puedo hacer una aplicación limpia. Yo tengo un sistemita de pruebas en red y parece que esta en una sola maquina, muy rapido, solo que no tengo bases de datos grande, a lo mejor esa es la diferencia. He leido que se pueden hacer trucos para solo cargar parte de la base de datos al momento e irse cargando los demas a la hora de hacer scroll. NO ES QUE SEA DEFICIENTE PROGRAMAR EN RED, ES SOLO CUESTION DE EXPERIENCIA.

Saludos y

Ahora si puedes irte a dormir :D :D :D

Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: Grid becomes very slow with 2 instances...

Post by Javier Tovar » Mon Feb 17, 2014 8:59 pm

Hi jpp, before you go to sleep ...

What I have observed in an application to RED, is that if you can handle very nicely, for lack of time right now I can not do a clean application. I have a test sistemita network and it looks like this on a single machine, very fast, just that I have no big database, maybe that's the difference. I have read that you can do tricks to load only part of the database when loading and leave others when scrolling. BE POOR IS NOT SET IN RED IS ONLY A MATTER OF EXPERIENCE.

greetings and

Now if you can go to sleep

User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: Grid becomes very slow with 2 instances...

Post by dhaine_adp » Tue Feb 18, 2014 9:36 am

Hi JPP,

Just a question regarding network share:
1. What is the speed of your network connection 10/100/1000 Auto/Half/Full Duplex?
2. Did you try mapping the network drive and run the test again?
3. Are they in the same IP segment? Otherwise how many router hop?
4. Lastly I assume your test workstation has no issue about drive fragmentation, no CRCs' and bad sectors.

Pardon me for asking such questions, no offense meant.

Regards,

Danny
Regards,

Danny
Manila, Philippines

User avatar
serge_girard
Posts: 2093
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Grid becomes very slow with 2 instances...

Post by serge_girard » Tue Feb 18, 2014 10:22 am

Jpp,

It's running rather fast here (200-300msecs).

It slows down when I change 10.000 to 100.000 (2100 msecs) but still fast.
Changing to 1 million records: 23.363 msecs (very slow)....



Greetings, Serge

User avatar
gfilatov
Posts: 557
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: Grid becomes very slow with 2 instances...

Post by gfilatov » Tue Feb 18, 2014 10:48 am

jpp wrote:Hi

I'have made an other test, and i am very in trouble

just a simple grid with a dbf on a shared folder, the browse of the database with pagedown is very quick.

if simply open the database and it's index on another pc on the network and the pagedown on the first pc becomes slow ...

i really do not know what to do ...
Hi,

It is a known Windows LAN problem and it is related to your Windows LAN's settings.

The Harbour contrib library HbWin have a special function win_osNetRegOk() for check and set a correct Windows Registry settings for safe networking.

Usage:

Code: Select all

   ?
   ? 'Checking and setting network for Windows'
   ? '----------------------------------------'
   ?
   IF WIN_OSISTSCLIENT() .AND. !WIN_OSNETREGOK() // Note: If Windows Terminal Server client DONOT
                                            //       attempt to set registry.
     ? 'Registry on WTS server is not set correctly for networking.'
     ? 'Please check with System Administrator to set the registry correctly.'
   ELSEIF WIN_OSNETREGOK( .T. )
     ? 'Registry set OK for networking'
   ELSE
     ? 'Failed to set registry - May need "Administrator" rights'
   ENDIF
Hope that useful :o
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein

Post Reply