Why is Nginx so mature that Python has various web frameworks such as web. py?

Source: Internet
Author: User
Tags failover nginx reverse proxy
0 reply content: nginx is the server, and web. py is the web application framework.

In short, the former encapsulates the processing of network I/O, and the latter is responsible for the specific application logic. The solution is different. Image point: a request comes. nginx first blocks the request and finds that it wants something ready-made (static file). Then it directly returns the ready-made static file to the client, this is very fast. If it is another request, it will be handed over to the web. py solution, web. after the py solution is complete, it only generates the content to be returned. It does not perform network I/O on its own, but is processed by nginx.

How nice it is to handle the network and concurrency with peace of mind. By the way, you can drop simple requests directly. Another logic that focuses on applications.

Of course, nginx can do more than this, and for the convenience of development, web. py and other frameworks are built into a simple web server.

As for tornado, there are both web application frameworks and web servers, and this server uses a high-performance single-thread non-blocking asynchronous model, which is an exception. Nginx is a server dominated by static content and front-end proxy. Various Python frameworks are used to implement dynamic logic.

Nginx listens to client connections, directly responds to static requests (images, css, js, etc.), and then sends dynamic requests through FastCGI (web. py) or the proxy (Tornado) is forwarded to the backend server for processing. Nginx itself is written in C, with high code efficiency and support for dynamic balancing, which is more stable and efficient than directly using Python for large-scale requests.

The Web. py framework sometimes comes with a server for development, but this server (like SimpleHTTPServer In the Python standard library) cannot cope with high load situations and should not be used in the production environment.

Tornado and Twisted-based servers compete with Nginx. These servers are designed to directly connect to the client and support some protocols that are not supported by Nginx reverse proxy, such as WebSocket. In a project that is complex enough and has many modules, Nginx may support static files. Tornado supports the comet service, and then one end acts as a proxy for more combinations of business logic. Nginx wants to do more proxy and balanced failover, but it is unlikely that it will pass through a large volume of failover. It is like a parent who only has authority but does not have the ability to do things, and then plays a role as a parent.

In contrast, many practical frameworks, such as web. py, are the child of a program running in the backend, handling various types of businesses.

Why does nginx not do anything about it? The estimation is not good, because it is difficult to use a program to solve all the business tasks. At that time, it will become another language interpreter ...... Large but not feasible. However, it is unlikely that my child will be able to take care of his family growth, because the important thing to handle business operations is scalability and table strength.

So they split up .... Generally, flask or django is used. Application FrameworkBoth use uswgi ServerDeployment, but uswgi does not Direct Client ConnectionTherefore, nginx + uswgi is usually used to connect the client to send requests to uswgi to improve the efficiency, so that the uswgi does not exist. Slow ioProblems, such as static and dynamic separation. The answer to Tornado and other high rankings is also clear. Web server? The nginx author is crying !!!!!! I/O is a good performance, and I/O is used as a production server?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.