Page 1 of 1 1
Topic Options
#189242 - 2008-08-24 04:17 AM Asynchronous Script Execution
MySpoonIs2Big Offline
Fresh Scripter

Registered: 2008-08-24
Posts: 11
I was recently asked to breathe new life into a dying script. One thing I would like to do with the script is reorganize it so that things the user depends on (ex. mapped drives) are taken care of immediately, and anything the user does not rely on or interact with can be performed in the background with another script. I was planning on using the "RUN" command to do this, but I have a few questions about how this would work:

If I issue several "RUN" statements in a row, each one will spawn a new Windows process, correct? So, theoretically (and I'm not relying on this assumption by any means), if a workstation has more than one processor, two of the "subscripts" could be executing simultaneously? Which would make it a bad idea for me to attempt to write to a single file with both "subscripts?"

Top
#189245 - 2008-08-24 01:28 PM Re: Asynchronous Script Execution [Re: MySpoonIs2Big]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
I do this often to process large amouts of data. Shawn has confirmed the process and also uses the logic to run many concurrent threads. It has no bearing on the number of processors in a system.

On a P3-800 MHz system where I first tested this a few years ago, I ran 25-30 concurrent threads, processed about 400 jobs in 15 minutes at 100% CPU load. The newer systems don't even break a sweat.

Basically, what I do is:
  • Create an array of tasks to run
  • Run the first 25 in the list
  • Monitor the task load, and when it drops below a threshold, I run a few more tasks. I'm rarely concerned about running at 100% CPU load for short durations.

So - basically, the answer is yes - you can run several tasks.

If this is a login process, you might want to give my login script a try. It does the drive & printer mapping first so those resources are available, then can display text message files for user notification, and then run any number of commands via Shell, Run, or Call. Using Call even allows you to utilize the variables and UDFs in the main script, or from script to script.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#189246 - 2008-08-24 01:57 PM Re: Asynchronous Script Execution [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Had to re-read your last statement AFTER my morning coffee...

If you are using other executables, they'll be multiple files. If you are planning on running multiple Kix scripts, you'd need individual script files - OR - some mechanism to tell Kix which "module" within the single script file to perform. I doubt that the second method will prove reliable enough, or have any benefit to make it worthwhile.

Simply - map your resources, then issue a string of Run commands, one after the other.
 Code:
Run 'avupdate.exe'                ; update antivirus def
Run 'bginfo.exe blah blah'        ; update background with PC data
Run 'kix32.exe kixscript2.kix'    ; run a concurrent kix process to tweak settings

As you see, to benefit from this with other kix scripts, you need to run a separate instance of Kix32. Of course, that will isolate one script from another, so you'll need to pass any needed arguments to it on the command line ($ARG="value"). There will be no way to return data to the main script, since Run spawns a child process via Exec rather than a Fork method. There's no communication path back in this mode. Your scripts can create logs or use INI files if they need to communicate with one another. Of course, that opens issues of concurrent file access.. so its best to only use tasks that are truly independent.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#189249 - 2008-08-24 11:38 PM Re: Asynchronous Script Execution [Re: Glenn Barnas]
MySpoonIs2Big Offline
Fresh Scripter

Registered: 2008-08-24
Posts: 11
Thanks for your response! I was somewhat worried that I would be waiting a few days.

 Originally Posted By: Glenn Barnas

[...]

Basically, what I do is:
  • Create an array of tasks to run
  • Run the first 25 in the list
  • Monitor the task load, and when it drops below a threshold, I run a few more tasks. I'm rarely concerned about running at 100% CPU load for short durations.

[...]


While it sounds like your script performs a lot more tasks than mine is going to, that is still the exact way I was planning on going about it.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 937 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.052 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org