[英]Tornado connections not closing in freeBSD
I have a tornado web server, something like : 我有一个龙卷风网络服务器,如:
app = tornado.web.Application(handlersList,log_function=printIt)
app.listen(port)
serverInstance = tornado.ioloop.IOLoop.instance()
serverInstance.start()
the handlers are made with tornado.web.RequestHandler
. 处理程序由
tornado.web.RequestHandler
。 When I run the server on freeBSD, sometimes the page/resource takes long time to load, trying to debug I see that when waiting for page to load Tornado didn't create a request object yet, and looking at netstat results, I see a lot of connection with status ESTABLISHED. 当我在freeBSD上运行服务器时,有时页面/资源需要很长时间才能加载,尝试调试我看到在等待页面加载时Tornado还没有创建请求对象,并且查看netstat结果,我看到了很多与状态ESTABLISHED的连接。
So my thought is that there are too many not closed connection, and operating system refuse new connection coming from the same session. 所以我的想法是有太多未关闭的连接,操作系统拒绝来自同一会话的新连接。
Can this be the case? 情况可能如此吗?
I don't do anything in get,post functions after writing, should I somehow shutdown/close the connection before returning? 我在写入后没有做任何事情,发布函数,我应该在返回之前以某种方式关闭/关闭连接吗?
EDIT 1: get/post are synchronous (no @asynchronous) 编辑1:get / post是同步的(没有@asynchronous)
EDIT 2: temporarily fixed by forcing no_keep_alive
编辑2:通过强制
no_keep_alive
临时修复
class BasicFeedHandler(tornado.web.RequestHandler):
def finish(self, chunk=None):
self.request.connection.no_keep_alive = True
tornado.web.RequestHandler.finish(self, chunk)
I'm not sure if keep_alive connections should stay open so long after client closed connection, any way this workaround works. 我不确定keep_alive连接是否应该在客户端关闭连接后保持打开,这种解决方法的任何工作方式。
I found how to do this by looking at HTTPConnection._finish_request
, when no keep-alive this line self.stream.read_until(b("\\r\\n\\r\\n"), self._header_callback)
runs. 我发现如何通过查看
HTTPConnection._finish_request
来执行此操作,当没有保持活动时,此行self.stream.read_until(b("\\r\\n\\r\\n"), self._header_callback)
运行。 what is \\r\\n\\r\\n in this context ? 什么是\\ r \\ n \\ r \\ n在这种情况下?
Try this: 尝试这个:
class Application(tornado.web.Application):
def __init__(self):
...
http_server = tornado.httpserver.HTTPServer(Application(),no_keep_alive=True)
http_server.listen(port)
tornado.ioloop.IOLoop.instance().start()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.