Web programming speed battle (Nodejs go Python) (non-professional contrast)

Source: Internet
Author: User

c10k problem solving, emerging a large number of new frameworks, or new language, then the question is: Who is the fastest? Non-professional program apes come from a non-professional comparison.

Comparison program: Output Hello world!

Test procedure: Siege–c 100–r 100–b

Examples include:

1.go implementation of HelloWorld with HTTP module

2.go HelloWorld with Martini micro-frame

3.python3 python2 PyPy, respectively, with the Gevent server tornado implementation of Hello World

4.python3 Python2 PyPy with a micro-framework bottle+gevent implementation of Hello World

HelloWorld of 5.NodeJS Pure JS implementation

6.NodeJS Express Framework for HelloWorld

Test Platform:

The company's old Pentium platform Pentium (R) dual-core CPU E6700 @ 3.20GHz

Memory 2GB (Weak enough)

First, the fastest go test in the universe:

1Package Main2 3Import (4"FMT"5"net/http"6)7 8Func sayhelloname (w http. Responsewriter, R *http. Request) {9Fmt. fprintf (W, "Hello world!")Ten} One  AFunc Main () { -http. Handlefunc ("/", Sayhelloname) -http. Listenandserve (": 9090", nil) the}

Continuous testing 5 times, the results are as follows:

1transactions:10000 Hits2availability:100.00%3Elapsed Time: 4.11 secs4Data transferred:0.11 MB5Response Time: 0.03 secs6Transaction rate:2433.09 trans/sec7throughput:0.03 mb/sec8concurrency:79.769Successful transactions:10000TenFailed transactions:0 OneLongest transaction:0.20 AShortest transaction:0.00

4.11 seconds, good results.

Look again at the example of Nodejs:

  1var http = require ("http");   2 http.createserver (function(request, Response) {  3     Response.writehead ( {"content-type": "text/plain"});   4     Response.Write ("Hello world!");   5     response.end ();   6 }). Listen (8000);   7 console.log ("nodejs start listen 8888 port!");   8

The test results are as follows:

  1 transactions:                  10000 hits  2 availability:                 100.00%  3 Elapsed time:                   5.00 secs  4 Data transferred:               0.11 MB  5 Response time:                  0.04 secs   6 Transaction Rate:            2000.00 trans/sec  7 throughput:                     0.02 mb/sec  8 Concurrency:                   86.84  9 Successful transactions:       10000  Failed transactions:               0  longest transaction:            0.17 Shortest  transaction:           0.00

5 seconds, a little bit slower than go

Next is python, because Python comes with the wsgiref server, just a reference implementation, performance is poor, so here choose two good performance WSGI server gevent, Tornado

The Gevent code is as follows:

1#!/usr/bin/python2From GeventImportPywsgi3 4 defHello_world (env, start_response):5     ifenv[' path_info ' = = '/':6Start_response (' K OK ', [(' Content-type ', ' text/html ')])7         return["Hello World"]8 9 Print' Serving on https://127.0.0.1:8000 'TenServer = Pywsgi. Wsgiserver ((' 0.0.0.0 ', 8000), Hello_world) OneServer.serve_forever () A 

The code for Tornado is as follows:

1From tornadoImportHttpserver2From tornadoImportIoloop3 defHandle_request (Request):4     ifrequest.uri== '/':5Message = B "Hello world!"6Request.Write(b "http/1.1 ok\r\ncontent-length:%d\r\n\r\n%s" % (7Len (message), message))8Request.finish ()9 TenHttp_server = Httpserver. Httpserver (Handle_request) OneHttp_server.bind (8888) AHttp_server.Start() -Ioloop. Ioloop.instance().Start() - 

As the python example to run in Python2 Python3 pypy, the result is too much, I only give the result:

Gevent:

python2:5.8 sec, python3:7.5 sec, pypy:4.8 sec

The interesting thing is: PyPy first run for 6.8 seconds, the second time after all is 4.8 seconds (feeling the reason is the first time because of the JIT wasted a little time) posted the results of a pypy:

1transactions:10000 Hits2availability:100.00%3Elapsed Time: 4.77 secs4Data transferred:0.10 MB5Response Time: 0.04 secs6Transaction rate:2096.44 trans/sec7throughput:0.02 mb/sec8concurrency:90.389Successful transactions:10000TenFailed transactions:0 OneLongest transaction:0.13 AShortest transaction:0.00 - 

Next is tornado:

python2:9.05 sec, python3:8.6 sec, pypy:5.95 sec

Similarly: PyPy The first execution time is 9.45 seconds, the subsequent execution time of each time is more than 5.9 seconds

As can be seen, pypy and go nodejs performance, which go the fastest 4.11 seconds, pypy+gevent and Nodejs performance is similar, pypy slightly better, Pypy+tornado is slightly slower than Nodejs.

2. Frame article:

From the above example can be seen, pure code is still more cumbersome to write, generally we are using the framework to write the web, I chose a few lightweight framework to output HelloWorld:

Go+martini

  1 Package main  2  3 import "github.com/codegangsta/martini"   4   5 func main () {  6   m: = Martini. Classic ()  7   m.get ("/", func () string {  8     return " Hello world!"   9   }) Ten   M.run ()  one} 

Run time is:

1transactions:10000 Hits2availability:100.00%3Elapsed Time: 4.69 secs4Data transferred:0.11 MB5Response Time: 0.04 secs6Transaction rate:2132.20 trans/sec7throughput:0.02 mb/sec8concurrency:90.239Successful transactions:10000TenFailed transactions:0 OneLongest transaction:0.17 AShortest transaction:0.00 - 

Nodejs+express:

  1var express = require (' Express ')  2var app = Express ()  3    4function (req, res) {  5   res.send (' Hello world ')   6 })  7    8 app.listen (3000)

Unavailable:

1transactions:10000 Hits2availability:100.00%3Elapsed Time: 5.90 secs4Data transferred:0.10 MB5Response Time: 0.06 secs6Transaction rate:1694.92 trans/sec7throughput:0.02 mb/sec8concurrency:96.449Successful transactions:10000TenFailed transactions:0 OneLongest transaction:0.13 AShortest transaction:0.01 - 

Python gevent+bottle:

  1import monkey  2 monkey.patch_all ()  3import run,get   4   5 @get ("/")  6defindex():  7     return "Hello world!"   8  9 Run (server= ' gevent ') 

Spents: Python2 10.05 sec, python3:12.95 sec, pypy:5.85 sec

Python tornado:

1 ImportTornado.httpserver2 ImportTornado.ioloop3 ImportTornado.web4 5 classIndexhandler (Tornado.web.RequestHandler):6     defGet (self):7Self.Write(' Hello world! ')8 9 if__name__ = = "__main__":TenApp = Tornado.web.Application (handlers=[(R)/", Indexhandler)]) OneHttp_server = Tornado.httpserver.HTTPServer (APP) AHttp_server.listen (8000) -Tornado.ioloop.IOLoop.instance().Start() - 

Spents: Python2 11.85 sec, python3:11.79 sec, pypy:6.65 sec

Web programming speed battle (Nodejs go Python) (non-professional contrast)

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.