Common deployment methods for Python Web services

Source: Internet
Author: User
Tags app service

Citation-9 ways to fully interpret Python web programs

Python has a lot of web development frameworks, The code is finished, deployment on-line is a big deal, generally speaking, the Web application is generally a three-tier fabric Web server---->application-----> DB Server

    • Mainstream Web server can count on a slap, apache,lighttpd,nginx,iis.
    • application, the Chinese name for the app service, is the app code you write based on a web framework
    • DB server refers to the storage services, Web development with more mysql, in recent years because of the scale of the site, Memcache,redis this key-value and other storage also popular

Top-of-the-web Server has 3 features

    1. Efficient processing of static files, Web server is developed with c, call is native function, the io, file transfer are targeted optimization
    2. As a simple network firewall, you can Denny some ip, simply control the number of concurrent connections, and so on, better than nothing
    3. Handles high concurrent short connection requests, forwarding thousands of users ' request through dozens of long connections on the intranet, one reason is that Web server handles high concurrency and is professional, and another reason is that most application frameworks do not have the ability to handle high concurrency

In fact, there are some web frameworks in the market because of the built-in support epoll/kqueue and other efficient network library, but with the ability to handle high concurrency, such as the Python Tornado,java system tomcat,jetty and so on, Someone will get rid of the front-end Web server, directly naked, but in the deployment of public network applications, it is best not to do so, because the aforementioned 1, 22 reasons, user brower to Web server network condition is strange, you can not imagine, Web server It is strongly recommended to use Nginx for three reasons

    1. Excellent performance, very stable
    2. Simple installation, Less dependent packages
    3. conf files are very easy to configure and easier than APACHE/LIGHTTPD
There are 9 ways to deploy a python-developed Web program
  • MoDpython, which is an Apache built-in module, is heavily dependenton the Python version used by the MoD Python compiler, and is not recommended for use with Apache.
  • cgi, This is too old, not recommended, and Nginx does not support CGI mode, only with LIGHTTPD or Apache
  • fastcgi, This is currently the most popular practice, through the Flup module to support, in nginx corresponding configuration instructions are Fastcgi_pass
  • spawn-fcgi, This is fastcgi multi-process management program, LIGHTTPD installation package comes with, and Flup effect, The difference is Flup is the Python code-level introduction, spawn-fcgi is an external program. SPAWN-FCGI uses a wide range of code to support any language development, php,python,perl, as long as your code implements the FastCGI interface, it can help you manage your process
  • scgi, the full name is simple Common Gateway Interface, but also the alternative version of cgi, scgi protocol is very easy, I think and fastcgi almost, just not how to promote, nginx corresponding configuration command is scgi_pass, If you want to use it, Flup also supports it.
  • Http,nginx uses Proxy_pass forwarding, which requires that the backend appplication must have a built-in HTTP server capable of handling high concurrency, and in Python's Web framework, only tornado can be selected. Python programmers like to invent wheels, tornado in addition to being a Web framework, it can also provide high-performance HTTP server alone, So if you use other Python framework to write code, such as bottle, you can also through the import Tornado to start a high-performance http server, the same can be used with the HTTP protocol and Nginx Deployment. extension, python packages can handle high-concurrency HTTP server There are many, such as gevent, can also be referenced by other frameworks to support the deployment of HTTP. In reality, Java is used to do web programs, usually with HTTP and nginx mates, application Server select Tomcat or jetty
  • uwsgi, consisting of 4 parts,
    • UWSGI protocol
    • Web server built-in Support Protocol module
    • Application Server protocol Support module
    • Process Control program Nginx starting from 0.8.4 built-in support Uwsgi protocol, UWSGI protocol is very simple, a 4 byte header+ a body,body can be a lot of protocol package, such as http,cgi, etc. (through the header field label), I used to do a small-scale performance comparison test, and the results showed that performance was less obvious than Uwsgi and fastcgi, and could be the reason for the smaller data set.

Uwsgi is characterized by its own process Control Program. it is written in c, using the Natvie function, which is actually similar to SPAWN-FCGI/PHP-FPM. So UWSGI can support a variety of application frameworks, including (python,lua,ruby,erlang,go) and so on * gunicorn, and Uwsgi similar tools, migrated from the Rails deployment tool (Unicorn). But the protocol it uses is WSGI, the full name is Python Web Server Gateway Interface, which is the official standard defined at python2.5 (PEP 333), root red Miaozheng, and deployment is relatively simple, http://gunicorn.org /on the Detailed tutorial * Mod_wsgi,apache a module, also supports the WSGI protocol, https://code.google.com/p/modwsgi/

Comparison of FASTCGI protocol and HTTP protocol in code deployment
    • Although fastcgi is a binary protocol, it does not conserve resources relative to the HTTP Protocol. Binary protocol, can only save the expression of numbers, such as 1234567, with a string to represent the need for 7 byte, with a number is 4 byte, and the string to where all the same
    • FastCGI in the transfer of data, in order to be compatible with the CGI protocol, but also with a bunch of CGI environment variables, so compared with the HTTP protocol, with the fastcgi transmission of data does not save, but more
    • FastCGI the only advantage is that it is a long connection, the user concurrent 1000 request,fastcgi may be used 10 links to the back end of the appplication, if the HTTP protocol, how much to give, will be back to the end Appplication Initiate 1000 requests
    • HTTP proxy forwarding, in the face of ultra-high concurrency in the case of problems, because, TCP stack, port is int16 integer you create a local connect, you need to consume a port, up to 65536. External concurrent hundreds of thousands of requests, port pool dry, Your server can only refuse to respond

Common deployment methods for Python Web services

Related Article

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.