Tornado and lock code

I'm trying to move away from CherryPy for the web service I'm working on, and one of the alternatives I'm considering is Tornado. Now most of my queries on the backend look something like this:

  • get post data

  • see if I have it in the cache (access to the database)

  • if you don’t make a few HTTP requests for some other web service, which can take even a few seconds depending on the number of requests

I keep hearing that you cannot block the main tornado cycle; I am wondering if all of the above code is executed in the method post()for RequestHandler, does this mean that I am blocking the code? And if so, what is the appropriate approach to use a tornado with the above requirements.

+3
source share
1 answer

Tornado comes with an asynchronous (actually two iirc) http client ( AsyncHTTPClient ). Use this if you need to perform additional HTTP requests.

Database searches should also be performed using an asynchronous client so as not to block the ioloop / mainloop tornado. I know that there are several clients of a database of clients trading using tornadoes (for example, redis , mongodb ). Mysql lib is included in the tornado distribution.

+1
source

Source: https://habr.com/ru/post/1784545/


All Articles