#189755 - 2008-09-19 04:32 PM
Improve speed in my script
|
edjekroketje
Fresh Scripter
Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
|
My problem is somewhat similar to JLMartinez's. I too have a script that loads very sluggish. True we've got a lot of "if ingroup" statements. I will put some parts of it here for you to see. Any comment on what it is supposed to do is given with each part of code. I will only put parrts here, most of it is the same.
;Versie : 2.14
;Datum : 19-09-2008
;Laatste wijziging : Adobeupdater disabled Clear out lines used no more
;Door : Ed
;
if @dos=("4.10") goto 98 else goto normal
;----------------------------------------------
:98
; run win98.bat
call "98.kix"
goto end
;----------------------------
:normal
;SETCONSOLE("HIDE")
$start="@time"
$ver="2.13"
$dos="@dos"
;----------------------------
setconsole("hide")
SETTIME "\\AS-07"
$ASERVER="AS-01"
$BSERVER="AS-02"
$CSERVER="AS-03"
$DSERVER="AS-04"
$ESERVER="AS-05"
$FSERVER="AS-06"
$GSERVER="AS-07"
$HSERVER="AS-08"
$ISERVER="AS-09"
$JSERVER="AS-10"
$KSERVER="ATS-01"
$LSERVER="ATS-02"
;Adobe Updater switch off ---------------------------
Call "Adobe.kix"
;Home Mapping X ---------------------------------------
USE x: /d
USE x: "\\$ASERVER\Home$\@USERID"
;groups mappings-------------------------------
IF INGROUP("U_USER_ADMINIST")
USE H: /d
USE H: "\\$ASERVER\GROEP\ADMINIST"
ENDIF
IF INGROUP("U_MAN_ADMINIST")
USE H: /d
USE H: "\\$ASERVER\GROEP\ADMINIST"
ENDIF
IF INGROUP("U_USER_APPBEHEER")
USE J: /d
USE J: "\\$ASERVER\GROEP\APPBEHEER"
USE K: /d
USE K: "\\$ASERVER\GROEP\ADMINIST"
ENDIF
IF INGROUP("U_USER_AUTOMAT")
USE H: /d
USE H: "\\$ASERVER\GROEP\AUTOMAT"
USE S: /d
USE S: "\\$ASERVER\DEV"
ENDIF
First part: Comment on version and recent changes, first check is done on OS, wich fires a totally different script. This is done because otherwise some of the mappings could not be made. If you're on an XP machine it skips to :normal, connects X: to your homeshare, and starts making group connections, based on group membership. Where possible multiple mappings for one group are bundled.
For printer connections a different script is launched like this:
;Printers---------------------------
;Nieuwe printer script aanroepen ---
call "08printers.kix"
;Nieuwe printer script aanroepen ---
;Printers---------------------------
IF INGROUP ("P_arena_101")
ADDPRINTERCONNECTION("\\$ASERVER\arena_101_blanco")
ADDPRINTERCONNECTION("\\$ASERVER\arena_101_logo")
ADDPRINTERCONNECTION("\\$ASERVER\arena_101_A3")
; SETDEFAULTPRINTER("\\$ASERVER\arena_101_Blanco")
ELSE
DELPRINTERCONNECTION("\\$ASERVER\arena_101_Blanco")
DELPRINTERCONNECTION("\\$ASERVER\arena_101_Logo")
DELPRINTERCONNECTION("\\$ASERVER\arena_101_A3")
ENDIF
This happens for about 30 printers, each with minimum 2 queues.
This system does have its advantages, we transfer users from one printer to another by just putting them from one group into another.
Mart told me to get rid of the gotos and batchfiles. I'd like to know if there is a better way for that?
_________________________
Still thinking about a good signature
|
Top
|
|
|
|
#189759 - 2008-09-19 05:00 PM
Re: Improve speed in my script
[Re: Glenn Barnas]
|
edjekroketje
Fresh Scripter
Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
|
How long is "a long time"? How many resources are mapped? How many external scripts are run? Do you run scripts that rely on resources before they are mapped? Do you call batch files to perform tasks that can be done natively in Kix? How do you process group and OU logic? Are you doing it repeatedly, or just making the decisions once? Goto's won't generally affect performance, but make the code hard to follow and support. You can get rid of goto by, for example:
; only run the win98 code for older systems, then exit
If @DOS = '4.10'
Call 'win98.kix'
Exit 0
EndIf
My login script (on my web site) is so tightly optimized that I need to make it wait so the user can verify that it ran. It processes about 30 resources and runs 3 external commands in under 4 seconds, including all of the group and ou-specific mapping logic. On the WAN, it takes about 9 seconds to run. Clearly, anything more than 15-20 seconds indicates that there is room for optimization. Glenn I will put in a measurement, but roughly around 20 seconds. Around 7 objects out of 50 possible are mapped, all based on group membership. A seperate group for each resource as well. Will get back on you with the exact time, then we know how much difference improvements can make. Thanks for the bit of code as well. To my opinion there are not so many goto's in the code. If there are three goto's than that's it.
I'll get back to you about the time it takes for the script in whole to complete.
Edited by edjekroketje (2008-09-19 05:01 PM)
_________________________
Still thinking about a good signature
|
Top
|
|
|
|
#189761 - 2008-09-19 05:05 PM
Re: Improve speed in my script
[Re: edjekroketje]
|
Indigoseth
Getting the hang of it
Registered: 2007-11-16
Posts: 78
|
I know there is a script / code you can add to your scripts to guage the exact time it taks for your script to run.
Unfortunatly i don't remember what it was.
If anyone remembers by this post please post for him if you know where to find it.
If i find it, and no one has posted it i will put it up here for you.
Thanks
Indigo
|
Top
|
|
|
|
#189762 - 2008-09-19 05:09 PM
Re: Improve speed in my script
[Re: Indigoseth]
|
Indigoseth
Getting the hang of it
Registered: 2007-11-16
Posts: 78
|
Ok i found it,
its called DeltaTime:
Put this in your code from the start and end, and it will show you how long it takes to run your code.
You can also used this to pin-point what section of your code is taking a while, so you can narrow down what the issue is.
Take Care
Indigo
;FUNCTION DeltaTime()
;
;AUTHOR Jochen Polster (jochenDOTpolsterATgmxDOTnet)
;
;VERSION 1.1 04/07/2004 - Fixed for NoVarsInStrings = 0N
; Milliseconds can now be omitted (if Zero) in one of the strings
;
;ACTION Calculates the time difference between two given times
;
;SYNTAX DeltaTime(Start,End)
;
;PARAMETERS Start (Required)
; - String value representing the starttime
; Format hh:mm:ss[:ms]
;
; End (Required)
; - String value representing the ending time
; Format hh:mm:ss[:ms]
;
;REMARKS Highest possible delta Value is 23:59:59:999 !
; If the diff gets higher , the result will be incorrect.
;
;RETURNS The difference between Start - and Endtime in 'hh:mm:ss[:ms]'
;
;DEPENDENCIES KiXtart 4.0
;
;EXAMPLES call "PATH\DeltaTime.udf"
; $start = @time + ':' + @msecs
; for $i = 0 to 15000
; $ = @scriptdir
; next
; $end = @time + ':' + @msecs
; ? 'Start time : $start' ?
; ? 'End time : $end' ?
; $Duration = DeltaTime($start,$end)
; ? 'Duration : $Duration' ? ?
;
; $start = "21:59:59" ? 'Backup Started : $start' ?
; $end = "01:00:01" ? 'Backup Ended : $end' ?
; $d = DeltaTime($start,$end)
; ? 'Backup Duration : $d' ?
;
; get $k
function DeltaTime($Start,$End)
dim $, $s, $e, $MS_Start, $MS_End, $S_Start, $S_End, $total, $deltaH, $deltaM, $deltaS, $deltaMS, $i
$s = split($Start,":")
$e = split($End,":")
if ubound($s) <> ubound($e)
if ubound($s) > ubound($e)
redim preserve $e[ubound($e)+1]
$e[ubound($e)] = "000"
else
redim preserve $s[ubound($s)+1]
$s[ubound($s)] = "000"
endif
endif
for $i = 0 to ubound($s)
$s[$i] = val($s[$i])
$e[$i] = val($e[$i])
next
if ubound($s) = 3
$MS_Start = $s[3] + $s[2] * 1000 + $s[1] * 60000 + $s[0] * 3600000
$MS_End = $e[3] + $e[2] * 1000 + $e[1] * 60000 + $e[0] * 3600000
select
case $MS_Start > $MS_End
$total = 86400000 - ($MS_Start - $MS_End)
case $MS_Start < $MS_End
$total = $MS_End - $MS_Start
case 1
$DeltaTime = "00:00:00:000" exit 1
endselect
$deltaH = $total / 3600000
$total = $total - $deltaH * 3600000
$deltaM = $total / 60000
$total = $total - $deltaM * 60000
$deltaS = $total / 1000
$deltaMS = $total - $deltaS * 1000
else
$S_Start = $s[2] + $s[1] * 60 + $s[0] * 3600
$S_End = $e[2] + $e[1] * 60 + $e[0] * 3600
select
case $S_Start > $S_End
$total = 86400 - ($S_Start-$S_End)
case $S_Start < $S_End
$total = $S_End - $S_Start
case 1
$DeltaTime = "00:00:00" exit 1
endselect
$deltaH = $total / 3600
$total = $total - $deltaH * 3600
$deltaM = $total / 60
$deltaS = $total - $deltaM * 60
endif
$deltaH = right('0' + $deltaH, 2)
$deltaM = right('0' + $deltaM, 2)
$deltaS = right('0' + $deltaS, 2)
if ubound($s) = 3
$deltaMS = right('00' + $deltaMS, 3)
$DeltaTime = "" + $deltaH + ":" + $deltaM + ":" + $deltaS + ":" + $deltaMS
else
$DeltaTime = "" + $deltaH + ":" + $deltaM + ":" + $deltaS
endif
endfunction
|
Top
|
|
|
|
#189776 - 2008-09-21 01:47 PM
Re: Improve speed in my script
[Re: Glenn Barnas]
|
edjekroketje
Fresh Scripter
Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
|
This works here at home where i also use KIX. I have now to get this nice piece of code from Glenn in at work, and than see how long it takes to run there. I'll give an update as soon as i have the time
_________________________
Still thinking about a good signature
|
Top
|
|
|
|
#189783 - 2008-09-22 09:05 AM
Re: Improve speed in my script
[Re: Lonkero]
|
edjekroketje
Fresh Scripter
Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
|
hmm... speed improvements would in your case come from the network load. as example, instead of addprintercon, you could first check if the printer is already connected, thus removing possible driver download overload.
OK, now there's a thing that could work. Thanks Lonkero! To accomplish a check on existance of a certain connection, it is best to check on the presence of the printerconnection in the registry. I think i'm gonna dive into that one first. This is how it looks at the moment: IF INGROUP ("P_arena_101")
ADDPRINTERCONNECTION("\\$ASERVER\arena_101_blanco")
ADDPRINTERCONNECTION("\\$ASERVER\arena_101_logo")
ADDPRINTERCONNECTION("\\$ASERVER\arena_101_A3")
; SETDEFAULTPRINTER("\\$ASERVER\arena_101_Blanco")
ELSE
DELPRINTERCONNECTION("\\$ASERVER\arena_101_Blanco")
DELPRINTERCONNECTION("\\$ASERVER\arena_101_Logo")
DELPRINTERCONNECTION("\\$ASERVER\arena_101_A3")
ENDIF
Let's just sort out what needs to be there to skip this whole driver installation.
_________________________
Still thinking about a good signature
|
Top
|
|
|
|
#189786 - 2008-09-22 11:43 AM
Re: Improve speed in my script
[Re: Glenn Barnas]
|
edjekroketje
Fresh Scripter
Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
|
Actually, something as simple as
$STime = @TICKS
; your code goes here...
'This script took ' CDbl(@TICKS - $STime) / 1000.0 ' seconds to run.' ?
is all you need. Glenn Thanks for very simple solution. Can i display this value in the messagebox i'm already having?
_________________________
Still thinking about a good signature
|
Top
|
|
|
|
#189787 - 2008-09-22 11:47 AM
Re: Improve speed in my script
[Re: edjekroketje]
|
edjekroketje
Fresh Scripter
Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
|
I have redirected output to a file, so that i can at least see how long the script runs. Without any changes i'm having around 45 seconds. That's al mighty long time if you're waiting for it...
_________________________
Still thinking about a good signature
|
Top
|
|
|
|
#189788 - 2008-09-22 01:57 PM
Re: Improve speed in my script
[Re: edjekroketje]
|
edjekroketje
Fresh Scripter
Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
|
I have now put this in: IF INGROUP ("P_arena_103")
KeyExist("HKEY_CURRENT_USER\Printers\Connections\,,AS-01,Arena_103_Blanco\standaard")
if @error="0"
ADDPRINTERCONNECTION("\\$ASERVER\arena_103_blanco") ? "Arena_103_Blanco nieuw geinstalleerd"
endif What this does is check for a value in the registry, if it is there, it will skip. I have tried this on my own account, so i only did the printers that i have connected, not the ones that i don't have, but are checked every run. I think i have to do the same for all the delprinterconnection commands as well... Will try and test more tomorrow or later this week
_________________________
Still thinking about a good signature
|
Top
|
|
|
|
#189845 - 2008-09-24 01:19 PM
Re: Improve speed in my script
[Re: edjekroketje]
|
edjekroketje
Fresh Scripter
Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
|
Turns out this does not quite do the complete trick. You have to skip the lines that are not necasarry (spelling correct?) otherwis the system will look for a connection that isn't there. For testing purposes i have removed all the lines i'm not using in my case. This gives me a running time of 6,484 seconds. I think that is a real improvement. Now let's make a new template and a new printerscript (or put it in the main script @user.kix)
_________________________
Still thinking about a good signature
|
Top
|
|
|
|
#189935 - 2008-09-29 05:01 PM
Re: Improve speed in my script
[Re: Lonkero]
|
edjekroketje
Fresh Scripter
Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
|
you mean 6 and half seconds or 6500 seconds? Oh no! It's only 6 and a half seconds now!
_________________________
Still thinking about a good signature
|
Top
|
|
|
|
#189936 - 2008-09-29 05:04 PM
Re: Improve speed in my script
[Re: Lonkero]
|
edjekroketje
Fresh Scripter
Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
|
hmm... you should add some printout before doing the call's to external files and after them... What do you mean by that?
BTW. Calling the other script is done to keep the old commands for deleting the printers in, and install the new printers from a new fresh script. The windows 98 script is different from the standard script we use so i thought it was easier to maintanin when it was a seperate file
_________________________
Still thinking about a good signature
|
Top
|
|
|
|
#189952 - 2008-10-01 09:24 AM
Re: Improve speed in my script
[Re: Lonkero]
|
edjekroketje
Fresh Scripter
Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
|
I mean, you should log which part takes how much time, so you know which part is worth improving. That's right, luckily i've found out that making the printerconnections takes the most time. It turned out that i kept making connections that were already there! Obviously there is no need for that. You only want to make the connection when it's not there and skip making the connection once you already have it. So far so good. If a person moves to another office, we just take him or her out of the original printer group, and into another. After a logout and in the new printer connection is there to use.
I'm trying to get this to work by looking at the presence of a key in the registry with the "KEYEXIST" function. I have to check why it is not working. Something to do with the @error i think.
_________________________
Still thinking about a good signature
|
Top
|
|
|
|
#189994 - 2008-10-02 03:53 PM
Re: Improve speed in my script
[Re: edjekroketje]
|
edjekroketje
Fresh Scripter
Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
|
For some strange reason this does not work:
IF INGROUP ("P_printer_###_***")
KeyExist("HKEY_CURRENT_USER\Printers\Connections\,,AS-01,printer_###_***\")
if $Returncode = 0
ADDPRINTERCONNECTION("\\$ASERVER\printer_###_blanco") ? "printer_###_*** nieuw geinstalleerd"
endif
else
Keyexist ("HKEY_CURRENT_USER\Printers\Connections\,,AS-01,printer_###_***\")
if $Returncode = 1
DELPRINTERCONNECTION("\\$ASERVER\printer_###_blanco") ? "printer_###_*** verwijderd"
endif
endif
This is copied from the template i'm using. I'm connecting/disconnecting about 50 printers this way. I cannot imagine that this will be too much for Kixtart to handle in terms of mermory etc.
Here is a of the report i'm getting: Opened 'printers.log' from edscprinters.kix at 2008/10/02 15:33:13
0
Arena_101_Blanco nieuw geinstalleerd00
Arena_101_Kleur verwijderd0997
Arena_101_Opstel verwijderd01801
Arena_102_Blanco verwijderd01801
Arena_102_Logo verwijderd01801
Arena_102_A3 verwijderd01801
Arena_102_Kleur verwijderd111001801
Arena_104_Blanco verwijderd01801
Arena_104_Logo verwijderd01801
Arena_104_Supver verwijderd01801
Arena_104_Kidsclub verwijderd01801
Arena_104_A3 verwijderd01801
Arena_105_Blanco verwijderd01801
Arena_105_Logo verwijderd01801
Arena_105_A3 verwijderd01801
Arena_105_Kleur verwijderd11110997
Arena_121_Blanco verwijderd0997
Arena_121_Logo verwijderd000997
Arena_123_Blanco verwijderd0997
Arena_123_Logo verwijderd0997
Arena_124_Blanco verwijderd0997
Arena_124_Logo verwijderd0997
Arena_125_Blanco verwijderd0997
Arena_125_Logo verwijderd0997
Arena_126_Blanco verwijderd0997
Arena_126_Logo verwijderd0997
Arena_127_Blanco verwijderd0997
Arena_127_Logo verwijderd0997
Arena_128_Blanco verwijderd0997
Arena_128_Logo verwijderd0997
Arena_129_Blanco verwijderd0997
Arena_129_Logo verwijderd0997
Arena_130_Blanco verwijderd0997
Arena_130_Logo verwijderd0997
Arena_131_Blanco verwijderd0997
Arena_131_Logo verwijderd0997
Arena_131_Hand verwijderd000997
Arena_133_Blanco verwijderd0997
Arena_133_Logo verwijderd0997
Arena_134_Blanco verwijderd0997
Arena_134_Logo verwijderd0997
Arena_135_Blanco verwijderd0997
Arena_135_Logo verwijderd0997
Arena_136_Blanco verwijderd0997
Arena_136_Logo verwijderd0997
Arena_137_Blanco verwijderd0997
Arena_137_Logo verwijderd0997
Arena_138_Blanco verwijderd0997
Arena_138_Logo verwijderd0997
Arena_139_Blanco verwijderd0997
Arena_139_Logo verwijderd0997
Arena_140_Blanco verwijderd0997
Arena_140_Logo verwijderd0997
Arena_141_Blanco verwijderd0997
Arena_141_Logo verwijderd0997
Arena_142_Blanco verwijderd0997
Arena_142_Logo verwijderd0997
Arena_143_Blanco verwijderd0997
Arena_143_Logo verwijderd018010997
Rainbow_161_Blanco verwijderd0997
Rainbow_161_Logo verwijderd0997
Rainbow_162_Blanco verwijderd0997
Rainbow_162_Logo verwijderd0997
Toekomst_201_Blanco verwijderd0997
Toekomst_201_Logo verwijderd0997
Toekomst_201_A3 verwijderd0997
Toekomst_221_Blanco verwijderd0997
Toekomst_221_Logo verwijderd0997
Toekomst_222_Blanco verwijderd0997
Toekomst_222_Logo verwijderd0997
Toekomst_223_Blanco verwijderd0997
Toekomst_223_Logo verwijderd0997
Toekomst_224_Blanco verwijderd0997
Toekomst_224_Logo verwijderd0997
Toekomst_225_Blanco verwijderd0997
Toekomst_225_Logo verwijderd0997
Toekomst_226_Blanco verwijderd0997
Toekomst_226_Logo verwijderd0997
Toekomst_227_Blanco verwijderd0997
Toekomst_227_Logo verwijderd0997
Toekomst_228_Blanco verwijderd0997
Toekomst_228_Logo verwijderd0997
Toekomst_229_Blanco verwijderd0997
Toekomst_229_Logo verwijderd0997
Toekomst_230_Blanco verwijderd0997
Toekomst_230_Logo verwijderd0997
Toekomst_231_Blanco verwijderd0997
Toekomst_231_Logo verwijderd-1
The printerscript took 37,765 seconds to run. I'm kinda stuck here. Any help is greatly appreciated
Edited by edjekroketje (2008-10-02 03:54 PM)
_________________________
Still thinking about a good signature
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 557 anonymous users online.
|
|
|