Home > other >  About python tornado asynchronous congestion
About python tornado asynchronous congestion

Time:09-16

On the Internet to see a lot of reference and so on, but in practice, I found that most are under different uri handler is not blocked, but for the same handler is blocked (including multiple processes) and not clear code, or environment configuration problem,
Post code (python 3.7 | tornado==6.0.3) :
 
The import tornado. Httpserver
The import tornado. Ioloop
The import tornado. Options
The import tornado. Web
The import tornado. Gen
The from datetime import datetime
The from concurrent. Futures import ThreadPoolExecutor

The class IndexHandler (tornado. Web. RequestHandler) :
Def get (self) :
Print (' index, STR (datetime. Now ()))
Self. Write (' Index! % s' % STR (datetime. Now ()))

The class TestHandler (tornado. Web. RequestHandler) :
Async def get (self) :
Await tornado. Gen. Sleep (3)
Print (STR (datetime. Now ()))
The self. The write (STR (datetime. Now ()))


Def server_main () :
Print (' Tornado, Tornado. Version, 'server start! ')
Application=tornado. Web application (

(r/index, IndexHandler),
(r/test ", "TestHandler),
],
The debug=True,
)
Application. The executor=ThreadPoolExecutor (10)
Http_server=tornado. Httpserver. Httpserver (application, max_header_size=104857600)
Http_server. Listen (9999)
Http_server. Start (1)
Tornado. Ioloop. Ioloop. Current (). The start ()


If __name__=="__main__ ':
Server_main ()

(note: under Linux, more CPU processes (http_server. Start (2)), is still blocked)

Congestion:


  • Related