[Stackless] (Performance-)Problem about Stackless-Twisted integration

Ying Zhong zhongying2008 at googlemail.com
Thu Nov 5 00:01:26 CET 2009


Hello,

I am trying to write a multi-user online application with Stackless and 
Twisted. I want the Twisted to do the networking stuff and the Stackless 
behind it to do other tasks. To get them working together, I just wrote 
a script like this:

import time
import stackless
from twisted.internet import task, reactor

test_channel = stackless.channel()
sang = 0
last_time = time.time()
schedule_rate = 10 # define the speed of switching between Stackless and 
Twisted

def scheduleReactor():
  stackless.schedule()

t = task.LoopingCall(scheduleReactor)
t.start(1.0/schedule_rate)

def listenerTasklet():
  while 1:
      test = test_channel.receive()
      global sang, last_time
      sang += 1
      if last_time < time.time() - 1:
          print "sang #%d times in %f sec."%(sang, time.time()-last_time)
          sang = 0
          last_time = time.time()

def sing():
  while 1:
      test_channel.send("System is singing.")

stackless.tasklet(sing)()
stackless.tasklet(listenerTasklet)()
stackless.tasklet(reactor.run)()
stackless.run()

So the reactor is just there and doing "nothing", while the tasklets are 
changing data through a channel. With schedule_rate = 10 I got the 
normal results:
sang #12 times in 1.109000 sec.
sang #11 times in 1.094000 sec.
...
But with schedule_rate = 100, 1000, or even 100000, I always got results 
with the same rate at 65 messages per Sec.:
sang #65 times in 1.015000 sec.
sang #65 times in 1.016000 sec.
...
Is there such a limit? or am I doing something wrong? Yes I also tried 
using another tasklet to force the reactor yield, like 
reactor.callLater(0, stackless.schedule), but the cpu usage will reach 
100%, which is not expected. Please help. Thank you in advance.

Best regards,
Ying





More information about the Stackless mailing list