Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the core of Tornado in Python

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail what is the core of Tornado in Python. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

The core of Tornado is ioloop and iostream. The former provides an efficient Imax O event loop, while the latter encapsulates a non-blocking socket. The coveted efficient asynchronous execution can be achieved by adding the network Ithumb O event to ioloop, using non-blocking socket and matching the corresponding callback function.

A brief introduction to Tornado

Tornado, whose full name is Tornado Web Server, is a Web server and Web application framework written in Python language, which is used by FriendFeed in its website FriendFeed. After it was acquired by Facebook, the framework was opened to the public as open source software in September 2009.

2. Characteristics of Tornado:

As a Web framework, it is a lightweight Web framework with asynchronous non-blocking IO processing.

As a Web server, Tornado has excellent anti-load capability. The official deployment of Tornado using nginx reverse proxy is compared with other Python web application frameworks. As a result, the maximum number of views exceeds the second place and nearly 40%.

3. Tornado performance:

Tornado has excellent performance. It attempts to solve the C10k problem, that is, dealing with concurrency greater than or equal to 10,000.

The Tornado framework and the server work together to form a full-stack alternative to WSGI. Using tornado network framework or tornaod http server in WSGI container alone has some limitations. In order to maximize the performance of tornado, it is recommended to use both tornaod network framework and HTTP server.

IV. Application scenarios

1. Large number of users and high concurrency

Such as second-kill rush to buy, shopping for a treasure on Singles Day, and train tickets for the Spring Festival

2, a lot of HTTP persistent connections

Use the same TCP connection to send and receive multiple HTTP requests / replies instead of opening a new connection for each new request / reply.

For HTTP 1.0, you can add Connection: Keep-Alive to the requested header (Header).

Fourth, Tornado development direction:

Tornado takes a small but sophisticated direction, focusing on superior performance, and is best known for its asynchronous non-blocking design.

HTTP server

Asynchronous programming

WebSockets

Fifth, the basic web framework module of tornado

RequestHandler

Encapsulates all the information and methods corresponding to a request. Write (response message) is a way to write response information. For each http request method (get, post, etc.), write the corresponding processing logic into the member method with the same name (for example, the corresponding get request method, the corresponding processing logic is written in the get () method). If there is no member method corresponding to the request method, a "405: Method Not Allowed" error will be returned.

Application

The core application class of the Tornado Web framework is the interface with the server, in which the routing information table is stored, and the first parameter its initialization receives is a list of routing information mapping tuples; its listen (port) method is used to create an http server instance and bind to a given port

This is the end of this article on "what is the core of Tornado in Python". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report