Forum OpenACS Q&A: Re: decreasing the number of -sched:idleX- threads

Collapse
Posted by Michal Hanckowiak on
thanks Ryan, but
it seems to me that maxthreads parameter
in section ns/server/${server} of etc/config.tcl file
has something to do with threads named "-conn:X"
not with threads named "-sched:idleX" !!!

in my installation of OpenACS with maxthread=3
there are 5 -sched:idle threads
probably consuming a lot of memory...
here is an output of ns_info threads:
-sched:idle4- -sched- -376439952 0 1332174838 p:0xf76e1b3c a:0x4
-sched:idle3- -sched- -325158032 0 1332099238 p:0xf76e1b3c a:0x3
-sched:idle2- -sched- -293602448 0 1332094738 p:0xf76e1b3c a:0x2
-sched:idle1- -sched- -258823312 0 1332092938 p:0xf76e1b3c a:0x1
-sched:idle0- -sched- -165377168 0 1332092068 p:0xf76e1b3c a:0x0
-driver- -main- -164324496 0 1332092043 p:0xf76d42a4 a:0x0
-conn:openacs6::1 -main- -163271824 0 1332092043 ns:connthread {}
-conn:openacs6::2 -main- -162219152 0 1332092043 ns:connthread {}
-conn:openacs6::0 -main- -161166480 0 1332092043 ns:connthread {20424 87.105.235.175 running GET /prywatne/_xowiki/Watki_nsd 0.28197 0}
-sched- -main- -157058192 0 1332091981 p:0xf76e1d08 a:0x0
-main- {} -146516288 1 1332091981 p:0x0 a:0x0

............
best regards,
Michal Hanckowiak

Collapse
Posted by Ryan Gallimore on
Sorry, Michal, I misread. To decrease the number of scheduled threads you need to limit the number of calls to ad_schedule_proc -thread t. You could also call the same proc without -thread t so the scheduled procs are run in the main thread instead of their own thread.

If you grep the code for ad_scheduled_proc (or ns_schedule_proc) you can remove the calls. You will of course, lose this functionality.

A default OpenACS install should not be consuming loads of memory with procs running in scheduled threads.

Also, check out the monitoring package for a list of scheduled procs that are running.

Collapse
Posted by Gustaf Neumann on
Dear Michal,

The scheduled procedures are either executed in the main "-sched-" thread, or - when "ad_schedule_proc -thread t" is used - in a separate worker thread for scheduled procs. These worker threads can be reused by several scheduled procs.

The logic for starting the worker threads for scheduled procs is as follows: when a scheduled proc (with the thread flag) is to be started at a certain time, and there is no idle worker thread for scheduled procs available at this time, an additional worker thread is started. The worker threads are named either -sched:idleNN- (when they are idle) or -sched:NNN- when they are active (the threads are renamed depending on their state).

So, one can reduce the number of the worker threads for scheduled procs by either starting no scheduled procs with the thread flag (there can be at most one job active at one time) or by setting the (repeating) times for the scheduled procs more cleverly. Per default, many repeated threads start e.g. all 30/60 seconds, leading to "collisions" at starting time and multiple worker threads. Scheduling at different times (e.g. don't use multiples of some intervals for repeating threads) reduces the number of collisions.

NaviServer has additionally a config parameter "schedsperthread" that defines a maximum number of scheduled procs per worker thread, leading to a cleanup by terminating threads regularly. On our production site, we have 59 scheduled procs defined, 43 have the thread flag, and we have just 2 idle worker threads for scheduled procs.

Hope this helps!

Best regards
-gustaf neumann

Collapse
Posted by Michal Hanckowiak on
yes, now it is clear for me 😉); !
thanks, Gustaw and Ryan
...........
best regards,
MHanckowiak