[Stackless] Watchdog, EVE like beNice implementation and how tasklet.capture() works

Juho Mäkinen juho.makinen at gmail.com
Fri Mar 24 13:39:11 CET 2006

I have tried to create similar system what EVE uses (the EVE powerpoint).
The idea is that the tasklets are executed inside Watchdog,
so that if one tasklet goes crazy, the watchdog can notice this
and remove it for debugging. This way the entire process will not
halt if one tasklet goes into infinitive loop, or something.

This is what I have come so far. I'm haven't quite figured out
what tasklet.capture() does. It looks like it's some kind of fork()
function. Could somebody describe in detail what it does?
Anyway, this is the only way I have managed to implement this
kind of functionality. The problem is, that it's quite slow.

The execution time with 1000 tasklets, each doing 1000 beNice
operations, takes nearly six seconds to execute in a P4 2Ghz
machine. Comparing to test_cframe, which takes one second
and test_cframe_nr (which does soft stack switches), whcih takes
0.16 seconds.

Have others tried to implement this kind of functionality?
Or could somebody point me some good trick to make this faster,
or even provide details how CCP has done this?

# start of beNice test
import stackless
from time import time
from stackless import channel,tasklet

niced = []

def taskletTest(n):
  print "tasklet " + n + " started"
  c = 0
  for i in xrange(1000):
    c = c + 1
  print "tasklet " + n + " done with c == " + str(c)

def beNice(n):
  global niced
  t = tasklet().capture()

print "Creating 1000 tasklets, which each does 1000 beNice operations"
for i in xrange(1000):
  stackless.tasklet(taskletTest)("tasklet #" + str(i))

start = time()
for i in xrange(1001):

  # Put the beNice'd tasklets back into running queue
  # so that the watchdog can run them
  for c in niced:
  niced = []

  while stackless.getruncount() != 1:
    t = stackless.run(100000)
    if t:
      print "Watchdog catch: " + str(t)

end = time()
print "execution time: " + str(end-start) + " second"
# end of beNice test

 - Juho Mäkinen

Stackless mailing list
Stackless at stackless.com

More information about the Stackless mailing list