Cra*_*sta 1 asynchronous tornado gunicorn
我正在尝试使用龙卷风编写一个应用程序,使用gunicorn处理工作线程.我创建了下面显示的代码,但是尽管启动了多个工作程序,但它并没有共享请求.一名工人似乎一直处理所有请求(不是间歇性的).
码:
from tornado.web import RequestHandler, asynchronous, Application
from tornado.ioloop import IOLoop
import time
from datetime import timedelta
import os
class MainHandler(RequestHandler):
def get(self):
print "GET start"
print "pid: "+str(os.getpid())
time.sleep(3)
self.write("Hello, world.<br>pid: "+str(os.getpid()))
print "GET finish"
app = Application([
(r"/", MainHandler)
])
Run Code Online (Sandbox Code Playgroud)
在控制台中输出(我在3秒窗口内轻松刷新了3个浏览器选项卡,但它们仍然使用相同的进程并按顺序运行):
2014-04-12 20:57:52 [30465] [INFO] Starting gunicorn 18.0
2014-04-12 20:57:52 [30465] [INFO] Listening at: http://127.0.0.1:8000 (30465)
2014-04-12 20:57:52 [30465] [INFO] Using worker: tornado
2014-04-12 20:57:52 [30474] [INFO] Booting worker with pid: 30474
2014-04-12 20:57:52 [30475] [INFO] Booting worker with pid: 30475
2014-04-12 20:57:52 [30476] [INFO] Booting worker with pid: 30476
2014-04-12 20:57:52 [30477] [INFO] Booting worker with pid: 30477
GET start
pid: 30474
GET finish
GET start
pid: 30474
GET finish
GET start
pid: 30474
GET finish
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用异步的IOLoop.add_timeout,在这种情况下没有比这更好的了.通过阅读,我意识到gunicorn甚至可能以某种方式向内看并解释异步装饰器意味着它可以将它们全部放在一个线程中,所以我回到了我在这里展示的内容.为了我的理智,我已经把未经编辑的版本粘贴到我所做的事情上.
总之,为什么gunicorn不会在工人之间分配我的请求?
好吧,显然浏览器正在造成这种情况.通过查看wireshark我已经确定至少firefox(我假设chrome正在做同样的事情)是在URL相同时序列化请求.也许这是因为如果它们可以缓存,它可以重用它们.