6
我确实知道,CherryPy的是多线程的,也有一个线程池的实现。
所以我想尝试一个显示多线程行为的例子。
现在可以说,我已经在我的一些功能在根类和休息所有的东西都配置
CherryPy的多线程例子
def testPage(self, *args, **kwargs):
current = threading.currentThread()
print 'Starting ' , current
time.sleep(5)
print 'Ending ' ,current
return '<html>Hello World</html>'
现在可以说,我跑我的页面http://localhost:6060/root/testPage在浏览器的3-4标签。
我得到什么结果是
Starting <WorkerThread(CP WSGIServer Thread-10, started 4844)>
Ending <WorkerThread(CP WSGIServer Thread-10, started 4844)>
Starting <WorkerThread(CP WSGIServer Thread-7, started 4841)>
Ending <WorkerThread(CP WSGIServer Thread-7, started 4841)>
Starting <WorkerThread(CP WSGIServer Thread-10, started 4844)>
Ending <WorkerThread(CP WSGIServer Thread-10, started 4844)>
的事情,我可以清楚地了解到它是创造新的线程处理每一个新的请求,但我想不出为什么每次我得到
出发... ending..starting ..ending
为什么不启动... starting..ending..ending有时
因为什么我的假设是,time.sleep会做出一些线程挂起和其他人可以在那个时候执行。
您应该尝试使用特定的软件,例如httperf: httperf --server = 127.0.0.1 --port = 6060 --num-conn = 50 --rate = 10 – 2016-10-18 10:22:03