博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
pypy with twisted vs nodejs
阅读量:5463 次
发布时间:2019-06-15

本文共 4370 字,大约阅读时间需要 14 分钟。

看到网上都说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()

转载于:https://www.cnblogs.com/raffeale/p/4072543.html

你可能感兴趣的文章
cesium编程入门(三)开始使用cesium开发
查看>>
4.18n阶勒让德多项式求解
查看>>
RTMP协议分析及推流过程
查看>>
PAT天梯赛L1-054 福到了
查看>>
Pains and Sickness 学习笔记
查看>>
PHP变量测试函数
查看>>
第六天 基本文件管理与XFS文件系统备份恢复
查看>>
win10中强制vs2015使用管理员启动
查看>>
UISerachBar / UISearchDisplayController
查看>>
Linux常用的操作命令
查看>>
Redis Desktop Manager
查看>>
css书写规范
查看>>
Asp.net +Jquery-uploadify多文件上传
查看>>
【恐怖的数组模拟】Secret Poems - HihoCoder - 1632
查看>>
大规模机器学习
查看>>
EasyPlayerPro(Windows)流媒体播放器开发之接口设计
查看>>
寻找数组中子数组和的最大值
查看>>
如何系统的进入大数据领域,学习路线是什么?
查看>>
COLLATE Chinese_PRC_CI_AS
查看>>
PHP中面对过程的冗余是什么?
查看>>