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

By admin at 2013-12-08 10:49 • 1680次点击
admin

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

class MyHandler(tornado.web.RequestHandler):
    @[asynchronous](/member/asynchronous) 
    @[gen](/member/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](/member/proxy) ;

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

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

    ...
}

Tornado, 阻塞, 避免, 方法, 使用


目前尚无回复
登录 后发表评论