What is Guicorn?

Source: Internet
Author: User

What is Guicorn?

We'll take a look at it before we answer the question. typical process of Web server [1]1. Establish the link: if there is no connection, establish connection 2. Receive request: Parses the request from the client. 3. Process the request: forward to the predefined processor.                    4. Access to resources, processing resources: access to resource processors according to the request to access resources, resources may exist in the database or the file system medium. Processes the resource return data, typically rendering the template based on the extracted data (the process of populating the template) and then returning the rendered content to 5. Build responses: Build HTTP response messages, including response status codes, response headers, and response entities. The response entity contains the data. 6. Send response: The response is sent to the client, can be done to close the connection 7. Logging we know like Django,flask,tornado these Web application frameworks (Web framework) are responsible for database connection access, page, data generation, session management, URL dispatch and so on. In other words, these Web application frameworks are primarily doing 3rd 4th thing. So 1. 2.5. In these relatively low-level things--who will handle the HTTP protocol? is an HTTP server. So how does the HTTP server work with Web applications betweenFramework communication? This will require WSGIThe WSGI is similar to a protocol that defines the HTTP server and Web application communicate with each otherThe way. 2nd to 3rd, HTTP requests from the HTTP server to the Web application, the middle of the need to communicate through WSGI, the same, from 4th to 5th step, the Web application will respond to the HTTP server, the middle also need to communicate through WSGI. If you feel that Bo Master understanding is not allowed here, please refer to PEP3333 obviously, it's BenefitsIs the decoupling of the Web application framework from the HTTP server. In addition, by providing a unified interface, programmers do not have to care about the underlying processing details of the HTTP protocol, but focus on the development of business logic. back to the question, what is Guicorn?it implements the Wsgi, and it is also an HTTP server. Because Gunicorn implements the WSGI, flask can run on Gunicorn, and can run happily on other servers that implement WSGI. Why do you use it? Django has its own wsgi, the Gunicorn do the Django Wsgi server, can be very flexible to configure the number of workers to increase concurrency, when the Web application does not respond for a long time, will restart the worker process, there is "temporary" the effect of the resurrection; other features. Above said the role of Gunicorn, the following by the way Gunicorn Configuration bar:) Gunicorn configuration BindThe IP and port number of the binding. After deployment, you can access the Web service by accessing the IP and port number. However, it is usually used as a reverse proxy before gunicorn. WorkersThe number of corresponding processing processes. is an important configuration. ps aux via Command | grep ' Gunicorn ' can see that the number of processes matches the number in the configuration file.There are recommended (2*CPU) +1, the actual need to see the specific situation, the request volume is not exactly the same, in order to reduce unnecessary memory consumption. TimeoutTimeout parameter, if the Web application server exceeds this time and still does not respond then the worker will be restarted, apparently the service is not available during the restart. If the Web application server is blocked before the reboot, then the reboot blocks may beDisappears when the service is available. But if the cause of the blockage No elimination, the Web application server will be blocked sooner or later, blocking time too long, causing the worker to restart again. This is called the "temporary" resurrectionDaemonWhether it is a daemon process. PythonpathPython path. Preload_appMatch True to load code before the worker process Fork, and recommend a try.  Other parameters refer to this. Finished Gunicorn configuration, and then talk about the GuicornDeploymentIt! Start Gunicorn

Example

/home/venv/bin/python/home/venv/bin/gunicorn-c start_gunicorn.py Wsgi:app

Where-c specifies the configuration file

To write the Web application in the wsgi.py file, note the path to the Wsgi file.

The place where bloggers don't quite understand lies in the strange colon. The section to the left of the colon represents the package or module that defines the program, and the part to the right of the colon indicates the name of the program instance in the package [2] seemingly, no colon is also possible;) reference Gunicorn with Django Digression Web backend The most simple and rude understanding: Get the request, check the database, throw it back to the client (Bloggers go away please take Guicorn = WSGI Server + HTTP server.) For Django, it's a better WSGI server ( able to serve multiple workeretc.), and it can also handle HTTP requests. Refer to [1] HTTP authoritative guide, fifth chapter; Redis combat, [2] http://www.jianshu.com/p/7bc34e56fa39 If you don't say it, Welcome to shoot Bricks ;)May 5, 2016

What is Guicorn?

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.