码迷,mamicode.com
首页 > Web开发 > 详细

pypy with twisted vs nodejs

时间:2014-11-04 01:33:05      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:http   io   ar   os   for   sp   on   cti   代码   

看到网上都说nodejs处理并发请求速度很快.对比了一下pypy + twisted 单线程模型下

pypy+twisted完胜 nodejs 最少比nodejs快2倍以上

 

nodejs 结果:

Benchmarking 127.0.0.1 (be patient)
Completed 4000 requests
Completed 8000 requests
Completed 12000 requests
Completed 16000 requests
Completed 20000 requests
Completed 24000 requests
Completed 28000 requests
Completed 32000 requests
Completed 36000 requests
Completed 40000 requests
Finished 40000 requests


Server Software:        
Server Hostname:        127.0.0.1Benchmarking 127.0.0.1 (be patient)
Completed 4000 requests
Completed 8000 requests
Completed 12000 requests
Completed 16000 requests
Completed 20000 requests
Completed 24000 requests
Completed 28000 requests
Completed 32000 requests
Completed 36000 requests
Completed 40000 requests
Finished 40000 requests


Server Software:        
Server Hostname:        127.0.0.1
Server Port:            8080

Document Path:          /
Document Length:        12 bytes

Concurrency Level:      10000
Time taken for tests:   3.465 seconds
Complete requests:      40000
Failed requests:        0
Total transferred:      2280000 bytes
HTML transferred:       480000 bytes
Requests per second:    11543.84 [#/sec] (mean)
Time per request:       866.263 [ms] (mean)
Time per request:       0.087 [ms] (mean, across all concurrent requests)
Transfer rate:          642.58 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  200 350.6      7    1026
Processing:     4  105 170.3     12    1658
Waiting:        2  101 167.4     10    1658
Total:          5  304 427.1     20    2677

Percentage of the requests served within a certain time (ms)
  50%     20
  66%    446
  75%    461
  80%    518
  90%   1029
  95%   1064
  98%   1418
  99%   1811
 100%   2677 (longest request)


Server Port:            8888

Document Path:          /
Document Length:        11 bytes

Concurrency Level:      10000
Time taken for tests:   6.965 seconds
Complete requests:      40000
Failed requests:        0
Total transferred:      4480000 bytes
HTML transferred:       440000 bytes
Requests per second:    5742.94 [#/sec] (mean)
Time per request:       1741.267 [ms] (mean)
Time per request:       0.174 [ms] (mean, across all concurrent requests)
Transfer rate:          628.13 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  713 968.6    200    3010
Processing:    19  121 200.9     47    3277
Waiting:       19  121 200.9     47    3277
Total:         22  834 987.6    676    6283

Percentage of the requests served within a certain time (ms)
  50%    676
  66%   1046
  75%   1054
  80%   1173
  90%   3047
  95%   3059
  98%   3090
  99%   3248
 100%   6283 (longest request)

 

pypy + twisted

 

Benchmarking 127.0.0.1 (be patient)
Completed 4000 requests
Completed 8000 requests
Completed 12000 requests
Completed 16000 requests
Completed 20000 requests
Completed 24000 requests
Completed 28000 requests
Completed 32000 requests
Completed 36000 requests
Completed 40000 requests
Finished 40000 requests


Server Software:        
Server Hostname:        127.0.0.1
Server Port:            8080

Document Path:          /
Document Length:        12 bytes

Concurrency Level:      10000
Time taken for tests:   3.465 seconds
Complete requests:      40000
Failed requests:        0
Total transferred:      2280000 bytes
HTML transferred:       480000 bytes
Requests per second:    11543.84 [#/sec] (mean)
Time per request:       866.263 [ms] (mean)
Time per request:       0.087 [ms] (mean, across all concurrent requests)
Transfer rate:          642.58 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  200 350.6      7    1026
Processing:     4  105 170.3     12    1658
Waiting:        2  101 167.4     10    1658
Total:          5  304 427.1     20    2677

Percentage of the requests served within a certain time (ms)
  50%     20
  66%    446
  75%    461
  80%    518
  90%   1029
  95%   1064
  98%   1418
  99%   1811
 100%   2677 (longest request)

 

nodejs代码:

var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);

 

 

twisted代码:

import sys
from twisted.internet import epollreactor
epollreactor.install();
from twisted.internet import reactor

from twisted.web import http

class MyRequestHandler(http.Request):
    pages={
        ‘/‘:‘Hello world!‘,
        ‘/test‘:‘<h1>Test</h1>Test Page‘,
        }
    def process(self):
        if self.pages.has_key(self.path):

            self.setHeader("Content-Type", "text/plain")
            self.write(self.pages[self.path])

        else:
            self.setResponseCode(http.NOT_FOUND)
            self.write("<h1>Not Found</h1>Sorry, no such page.")
        self.finish()
class MyHttp(http.HTTPChannel):
    requestFactory=MyRequestHandler
class MyHttpFactory(http.HTTPFactory):
    protocol=MyHttp
if __name__=="__main__":
    reactor.listenTCP(8080,MyHttpFactory())
    reactor.run()

pypy with twisted vs nodejs

标签:http   io   ar   os   for   sp   on   cti   代码   

原文地址:http://www.cnblogs.com/raffeale/p/4072543.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!