Skip to content

Instantly share code, notes, and snippets.

@Arbow
Created January 30, 2010 07:43
Show Gist options
  • Save Arbow/290468 to your computer and use it in GitHub Desktop.
Save Arbow/290468 to your computer and use it in GitHub Desktop.
Just like http://gist.github.com/290451, but stackless version
#!/usr/bin/env python
#coding=utf-8
import stackless
import sys
import time
per_thread_requests = 10000
def receive_task():
for i in xrange(0, per_thread_requests):
stackless.tasklet(process_task)()
def process_task():
for i in xrange(0, 10):
channel = stackless.channel()
stackless.tasklet(async_process_task)(channel)
channel.receive()
def async_process_task(channel):
channel.send(0)
def main():
global per_thread_requests
if len(sys.argv) > 1:
per_thread_requests = int(sys.argv[1])
print "=========Stackless Version========="
print " Receive Task Count: 1"
print " Requests Per Receive Task: ", per_thread_requests
print " Request Counts: ", per_thread_requests
begin_time = time.time()
stackless.tasklet(receive_task)()
stackless.run()
consume_time = (time.time() - begin_time) * 1000
print " Consume Time: ", consume_time, " ms"
print " TPS About: ", str(per_thread_requests*1000/consume_time)
print "=========Stackless Version========="
if __name__=='__main__':
main()
"""
Result:
=========Stackless Version=========
Receive Task Count: 1
Requests Per Receive Task: 100000
Request Counts: 100000
Consume Time: 5473.23203087 ms
TPS About: 18270.7401104
=========Stackless Version=========
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment