This is a creation in Article, where the information may have evolved or changed.
Performance comparison of Go and Python Web servers
2011-08-05 13:41 renwofei423 Open Source China community I want to comment (0)Size: T| T
I usually use Python to build web apps. A year ago, driven by interest, I began to learn go. I found that the go with HTTP, Mustache.go Gomysql package is a good combination of tools that I can use to work. So I decided to use go to write my app
AD:2013 Cloud Computing Architect Summit Course exposure
I usually use Python to build web apps. A year ago, driven by interest, I began to learn go. During this time, I rewrote some CGI applications that were originally developed by C, including applications running in the chroot environment with the THTTPD server. I started looking for tools that could develop a standalone web application that is easy to chroot and built into a Web server. At that time, I started playing web.go framework, mustache.go template, go native HTTP package, and Gomysql database API. I found that the go with HTTP, Mustache.go Gomysql package is a good combination of tools that I can use to work. So I decided to use go to write my app. (The Go programming language can also be used to write Web applications?) )
In the process of working, I need to be more flexible than mustache.go, more mature than gomysql, and less Bug-free stuff. Eventually, I used the kasia.go template and Mymysql (a package developed for my app, but I contributed it to the go community). Rewritten applications work well even in a more operational environment than in previous workloads. I began to think about the question: how much faster (or slower) it is to implement a standalone WEB application with go than Python. I decided to do some testing for various frameworks and different uses of the server. For comparison, I chose the following Go package:
The original Go HTTP package;
Web.go Framework (it uses HTTP packets running in standalone mode [standalone mode]);
Twister Framework (It also uses HTTP packets).
and the following Python Web server/framework:
Use the web.py framework of the CherryPy WSGI server;
Use Flup FastCGI to do the background processing of Nginx server web.py framework;
Tornado asynchronous server/framework;
Nginx to do load balancing tornado.
For each use case, I have written a small application, a slightly more complex, traditional Hello world example. Any application will include:
Use regular expressions to pass parameters through URL paths;
Use statements to create multiple lines of output;
Format the output with a formatted function/expression in printf form.
I think these are common operations in WEB applications, so it should be included in any simple performance comparison test. The code for all test apps is in the following link:
Go http
Web.go
Twister
web.py
Tornado
Test environment
The test environment includes two PCs with Gigabit Ethernet links (Request initiator and application server).
Request Initiator: 2 x Xeon 2.6 GHz with hyperthreading, Debian SID, kernel:2.6.33.7.2-rt30-1-686 #1 SMP PREEMPT RT;
Server: MSI Netbook with the core Intel U4100 1.30GHz, AC power connected, 64-bit Ubuntu 10.10, Kernel:2.6.35-25-generic # 44-ubuntu SMP, Python 2.6.6-2ubuntu2, web.py 0.34-2, Flup 1.0.2-1, Tornado 0.2-1, Nginx 0.7.67-3ubuntu1;
In order to generate HTTP requests and evaluate the performance of the test application, I use the Siege Performance test tool. Siege can simulate multiple users with multithreading. I used the following command to generate the request:
Siege-c 200-t 20s http://server_addr:8080/hello/100
or more similar commands to reduce the amount of the parameter-C (in this test, I ran multiple Python scripts at the same time). It simulates the request of 200 users and lasts for 20 seconds. This URL causes the Web app to output 100 rows for each request. Go app uses go release version 2011-02-01.1.
Results
Gomaxprocs=1, a Python process:
| Framework |
Request rate [1/SEC] |
| Go http |
1350 |
| Twister |
1324 |
| Web.go |
1141 |
| Tornado |
882 |
| Tornado+nginx |
862 |
| Web.py+cherypy |
169 |
| Web.py+nginx |
114 |
gomaxprocs=2, two Python concurrent processes:
Gomaxprocs=4, four Python concurrent processes:
Flup FastCGI options for Web.py+nginx work: Multiplexed=false, Multithreaded=false. If multiplexed=true it will run slower. If Multithreaded=true and only one process serves the Nginx server, the following error is reported:
Conclusion
You can see that Go has won almost all of the test cases. The less desirable result of the WEB.GO framework may be that it first tries to find a static page with the specified URL before it executes the processing method. What surprises me is that the Tornado Python framework is so high in performance, especially compared to the web.py framework. I'm also surprised that CherryPy servers are faster than Nginx+flup (I use Web.py+flup+nginx to run almost all of the Python Web apps).