Tornado has been used as the HTTP server for several services developed in the project. I have also asked why Tornado, and the answer is that Tornado has the best concurrency performance and is the most lightweight compared to Tornado, Flask, and Django. Today, I had some spare time and suddenly had an obsessive-compulsive attack. I want to know whether Tornado is really stronger in concurrency than Django. Why are the advantages of Django’s middleware overlooked?

1. Tornado vs Django

The overall idea is to list the advantages and disadvantages of the framework collected, and then verify them. The advantages and disadvantages collected from other posts are summarized as follows:

Tornado: Advantages: Lightweight, asynchronous, non-blocking IO handling, excellent load resistance, coroutines provide excellent processing performance Disadvantages: No ORM, few support and templates, lack of backend support, and not as fast as Django for small projects. Tornado’s so-called “drawback” is due to its design philosophy, which is that it is a small but elegant HTTP server plus a lightweight web framework, where high concurrency processing is what it is really good at

Django: Advantages: large and complete framework, fully automated management backend brings high development efficiency, rich components disadvantage: thick, and its own ORM coupling analysis: Django provides convenience, also means that Django built-in ORM and other modules within the framework of the coupling degree. Applications must use Django’s built-in ORM, or they won’t be able to take advantage of the framework’s ORM-based benefits. It is theoretically possible to switch its ORM module, but this is equivalent to tearing down and redecorating the house after it has been renovated, rather than removing the hair and redecorating the house from the ground up. Django’s selling point is its high development efficiency and limited performance expansion

2. Django performance

The other day I wrote a post about Django: Portal uses JMeter to pressure the authentication interface to see how Django performs. Using a CentOS machine with dual core and 8GB memory, 200 concurrent test results:

TPS is only 2.6, with a maximum delay of 77s

3. Performance of Tornado

For more details, see my other post: Portal Of course, the measured environment resources are exactly the same, here only posted results:

The maximum delay is 484ms and the TPS reaches 126

4. Selection conclusion

This wide gap in concurrency performance certainly has something to do with Django’s use of the default SQLite, but it also partly reflects Django’s ORM + template mechanism, which provides rich templates at the expense of performance. However, the performance comparison posted on the post shows that Django has more concurrency than Tornado. I don’t know if the data is reliable.

5. Write it at the end

I wanted to introduce the performance of SANIC, but SANIC only supports Python 3.5+ version, the environment at hand does not meet the requirements, it is difficult to upgrade, here is a pit, we will test and compare the environment later. Looking at the data of other posts, SANIC’s concurrency performance may exceed Tornado’s, which needs to be verified later