admin
admin
3661 0 0

使用Tornado 避免阻塞的一些方法

《How I stopped worrying about IO blocking Tornado》
http://www.peterbe.com/plog/worrying-about-io-blocking
部分代码:

class MyHandler(tornado.web.RequestHandler):
    @[asynchronous](/name/asynchronous) 
    @[gen.engine](/name/gen.engine) 
    def get(self):
        http_client = AsyncHTTPClient()
        response = yield gen.Task(http_client.fetch, "http://example.com")
        stuff = do_something_with_response(response)
        self.render("template.html", **stuff)

在nginx 配置里给管理员专配通道

upstream aroundtheworld_backends {
    server 127.0.0.1:10001;
    server 127.0.0.1:10002;
    server 127.0.0.1:10003;
}

upstream aroundtheworld_admin_backends {
    server 127.0.0.1:10004;
}

server {
    server_name aroundtheworldgame.com;
    root /var/lib/tornado/aroundtheworld;
    ...

    try_files /maintenance.html @[proxy;](/name/proxy;) 

    location /admin {
        proxy_pass http://aroundtheworld_admin_backends;
    }

    location @[proxy](/name/proxy) {
        proxy_pass http://aroundtheworld_backends;
    } 

    ...
}
0

See Also

Nearby


Discussion

Login Topics