[EMAIL PROTECTED] wrote:
Nathan,

So this is server wide control and monitoring. I'm wondering if it would be possible to do something like an incr type control, where you could have a loop and signal it to run once, or some number of times, and then pause.

(Oh, wait, maybe the eval subcommand runs the script once?) So I guess I should ask if there is a way to begin a loop in a paused state?
"ns_loop_ctl eval <script>" is exactly how you would implement something like this. You could imagine pausing the loop and injecting some code that would "wait" on a condition variable that was set elsewhere.
On the examples: it seems like you would have to be pretty lucky to catch a loop executing, this must be for finding loops which are misbehaving and getting out of them without restarting the server.
Exactly right - on certain applications we have a number of detached threads which degenerate to "while 1" situations, where this technique is useful. We were also curious as to how long each "spin" of certain loops was taking.
It would also be nice if the info subcommand provided the number of spins or loop iterations already performed. This might allow some form of automatic detection and canceling of loops gone wild.
It does:

<loop_id> <thread_id> <elapsed_time> <number_spins> <state> <script>

0 41973248 1149519792:592471 9 running {ns_while 1 {ns_sleep 1:0}}

You could imagine writing your own code to detect these run-away cases. Maybe 
something like this:

proc detectBadLoops {} {
   set maxSpins 1000000

   foreach loopId [ns_loop_ctl list] {
       #
       # Catch to avoid race condition around loops which
       # may have completed under your feet.
       #

       catch {
           set loopInfo [ns_loop_ctl info $loopId]
           set spins [lindex $loopInfo 3]

           if {$spins > $maxSpins} {
               ns_loop_ctl cancel $loopId
           }
       }
   }

   ns_sleep 5:0
}

ns_thread begindetached detectBadLoops

...something like that at least... ;-)
Anyway, pretty interesting code.
Hopefully to someone other then us! ;-)

- n
tom jackson

On Monday 05 June 2006 08:11, Nathan Folkman wrote:
In AOLserver 4.5 the following new Tcl APIs are provided:

    "ns_for"
    "ns_foreach"
    "ns_while"
    "ns_loop_ctl"

The usage is exactly the same as the "nsloopctl" module I checked in,
and which I documented in the README file. The only difference between
the two is that "nsloopctl" will actually "redefine" Tcl's "for",
"foreach", and "while" commands, while the new AOLserver 4.5 APIs
require you to use the new commands explicitly. Forgot we had added it
to the core, so I'll remove - sorry about the confusion. ;-)

Here's a quick example:

    server1:nscp 4> ns_thread begindetached "while 1 {ns_sleep 1:0}"

    server1:nscp 5> ns_loop_ctl list

    server1:nscp 6> ns_thread begindetached "ns_while 1 {ns_sleep 1:0}"

    server1:nscp 7> ns_loop_ctl list
    0

    server1:nscp 8> ns_loop_ctl info 0
    0 41973248 1149519792:592471 9 running {ns_while 1 {ns_sleep 1:0}}

    server1:nscp 9> ns_loop_ctl pause 0
    1

    server1:nscp 10> ns_loop_ctl resume 0
    1

    server1:nscp 11> ns_loop_ctl cancel 0
    1

    server1:nscp 12>  ns_loop_ctl list

If you want to gather statistics about existing "for", "foreach", and
"while" loops, simply rename those commands and have them instead point
to the new commands:

for -> ns_for
foreach -> ns_foreach
while -> while


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> 
with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: 
field of your email blank.


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> 
with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: 
field of your email blank.

Reply via email to