请求不在gunicorn工作人员之间分发

时间:2014-04-13 03:09:46

标签: 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)
])

在控制台中输出(我在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

我已经尝试过将IOLoop.add_timeout与异步一起使用,在这种情况下没有比这更好的了。通过阅读我意识到,gunicorn甚至可能以某种方式向内部寻找并解释异步装饰器意味着它可以将它们全部放在一个线程中,所以我回到了我在这里所展示的内容。为了我的理智,我已经pastebinned完成了我未完成的版本。

总之,为什么没有枪手在工人之间分配我的请求?

1 个答案:

答案 0 :(得分:5)

好吧,显然浏览器正在造成这种情况。通过查看wireshark我已经确定至少firefox(我假设chrome正在做同样的事情)是在URL相同时序列化请求。也许这是因为如果它们可以缓存,它可以重复使用它们。

相关问题