简体   繁体   中英

Tornado performance issue with coroutine

I got performance issue after using coroutine, code is simple as official document:

class MainHandler(tornado.web.RequestHandler):
    @tornado.gen.coroutine
    def get(self):
        httpClient = tornado.httpclient.AsyncHTTPClient()
        yield httpClient.fetch('http://google.com/', method = 'GET')

Test command is:

wrk -t12 -c400 -d30s http://10.0.0.10:2002/

I can only get 66 requests per second, if I remove httpClient.fetch() , I can get 1659 requests per second. Tornado is running single process on E5-2666 v3 @ 2.90GHz, CPU usage of this process all goes 100%.

I'm using Tornado v4.4.1, python 2.7.

By default, AsyncHTTPClient won't await more than 10 concurrent requests. So if each fetch takes about 150ms between start and finish, for example, that would limit you to about 66 fetches per second total. Since each MainHandler.get awaits an AsyncHTTPClient.fetch , that means that get is bottlenecked too.

Raise the maximum clients like so, at the very beginning of your program:

tornado.httpclient.AsyncHTTPClient.configure(None, max_clients=1000)

Do that right after all your imports and before you create any AsyncHTTPClients.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM