Web. py performance test

Source: Internet
Author: User

He has been engaged in background system development and has no knowledge of web or even front-end technologies. In response to the Multi-Party call of leader, he decided to explore the front-end technologies. I personally have a special liking for python and decided to start with Python web development. Among the many Python web frameworks, I have taken a look at simple and lightweight web. py. I don't like it very much because it is simple and cost-effective, haha. However, you are more willing to accept lightweight things, such as nginx. This article will not introduce the development of Web. py, nor deploy the environment. The official website has a very detailed introduction of these things, or a bunch of documents on the Internet. In general, the order of researching new technologies is basically: whether the documents are detailed or not, how the performance is, whether the stability can be produced, and whether the functions meet the requirements. Therefore, this article only records a benchmark made on the Web. py framework and nginx.

Test example

#!/bin/env /usr/local/bin/pythonimport web web.config.debug = Falseurls = ('/(.*)', 'hello')app = web.application(urls, globals())class hello:        def GET(self, name):        if not name:             name = 'World'            return 'Hello, ' + name + '! fuck the hello'if __name__ == "__main__":    app.run()

PS: It seems that the demo is directly copied from the official website, and I modified it in a very simple way.

Test Tool
Although I think Apache has its own well-known AB, it is at least not as well-known as Apache. The test parameters are as follows:

AB-N 10000-C 100 http: // 127.0.0.1: 1988/

Web. py Performance

Directly use the web. py built-in web server to start the hello word service. When started, the standard output and standard errors are redirected to/dev/null to reduce Io consumption. Benchmark:

Web. although the py program is started by default by multiple threads (this can be seen in/proc/PID), but due to the python multi-thread implementation lock problem, there has been no significant effect on concurrency, so the benchmark here is a little miserable, at least it will not satisfy the research on high-concurrency servers. It's a pity that the 16-core CPU is still there.

Nginx + spawn-fcgi + flup + web. py Performance

Nginx does not perform any optimization, which is basically the default configuration, except for the FastCGI commands. Web. py uses spawn-fcgi to start 32 processes. In fact, it is not much different from 16 processes. The test host is 8-core and hyper-threading to 16-core. The memory will not affect the construction of this test. Benchmark:

PS: using this architecture, the performance has been significantly improved, and QPS is eight times that of single web. py. The performance improvement is mainly because the multi-core CPU is reused in the python multi-process. All 16 cores ran to 70%-80%, basically full; load reached 50-60. 24 GB memory test host, memory is not a bottleneck. The optimization space for this result should not be too large. After all, the CPU is almost full of load, and the CPU becomes a bottleneck.

To sum up

High-performance servers can be designed with multiple threads or processes to maximize CPU reuse. The CPU is put there, and you don't need to use it for white.

Error note

Use spawn-fcgi to start the web. in the test program of Py, the following error is always thrown, and the absolute path is not used for the file specified by the-F option. The spawn-fcgi user experience is too low.

Spawn-fcgi: Child exited with: 127

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.