pypy with twisted vs nodejs

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

时间: 2024-10-12 08:20:25

pypy with twisted vs nodejs的相关文章

为什么 Node.js 这么火,而同样异步模式 Python 框架 Twisted 却十几年一直不温不火?

twisted是一个强大的异步网络框架,应用的面也非常广,但是没有这几年才出现的Node.js火,社区.文档也是很少可怜我觉得二者其实在本质上差不多,而且python使用起来还是比较容易一些的 匿名用户 因为,它给了一大部分程序猿幻觉比如前后端统一,脚本也能性能很屌,做Demo搜搜快什么的,但实际上,这仅仅是幻觉罢了…… 正是因为这样的幻觉是“看得到”的,又有一个响当当的干爹Google,因此Node的曝光率远高于后端常规语言就不足为奇了. 论速度,你一个带JIT的跟常规脚本语言的虚拟机比,没到

2017年的golang、python、php、c++、c、java、Nodejs性能对比[续]

2017年的golang.python.php.c++.c.java.Nodejs性能对比[续] 最近忙,这个话题放了几天,今天来个续集.   上篇传送门: 2017年的golang.python.php.c++.c.java.Nodejs性能对比(golang python php c++ java Nodejs Performance)   好了,上回的某些事有些人有异议,今天也回应下. 1.有人说python性能没那么Low? 这个我用pypy 2.7确认了下,确实没那么差, 如果用num

web编程速度大比拼(nodejs go python)(非专业对比)

C10K问题的解决,涌现出一大批新框架,或者新语言,那么问题来了:到底谁最快呢?非专业程序猿来个非专业对比. 比较程序:输出Hello World! 测试程序:siege –c 100 –r 100 –b 例子包括: 1.go用http模块实现的helloworld 2.go用martini微框架实现的Helloworld 3.python3 python2 pypy分别用gevent server  tornado实现的Hello world 4.python3 python2 pypy分别用

pypy安装过程,及依附其上的模块安装

pypy用预先编译好的版本安装还是挺简单的,实际上不用安装,仅仅是挎贝,跟nodejs的某些版本安装一样绿色. 下载地址: http://pypy.org/download.html, 有时候访问很慢,同时试了aliyun和腾讯的云主机,也都很慢,可能是网络的问题 安装pip的话可以用现成的  https://pip.pypa.io/en/stable/installing/ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py 接下来的

Node.js 使用angularjs取得Nodejs http服务端返回的JSON数组示例

server.js代码: // 内置http模块,提供了http服务器和客户端功能(path模块也是内置模块,而mime是附加模块) var http=require("http"); // 创建服务器,创建HTTP服务器要调用http.createServer()函数,它只有一个参数,是个回调函数,服务器每次收到http请求后都会调用这个回调函数.服务器每收到一条http请求,都会用新的request和response对象触发请求函数. var server=http.createS

Nodejs + MongoDb

一.搭建开发环境 进入 http://nodejs.org 下载开发环境 http://Expressjs.com 下载安装Express  npm install -g express 继续安装ejs:npm install ejs 如果要想运行Node.js程序,则现在只能够使用“node app.js”,而这样的运行方式,如果在app.js文件修改之后往往需要重新启动才可以加载新的内容,这对于开发是非常不方便的, 为此,可以使用一个supervisor组件包,它可以动态的加载修改之后的开发

nodejs应用在linux服务器中的部署

1.(可选)添加用户: addgroup wmui添加用户组useradd -d /home/wmui -s /bin/bash -m wmui创建wmui用户passwd wmui设置密码,如果忘记密码,也可用此命令重置密码usermod -a -G wmui wmui 添加用户到组visudo 设置sudo权限然后会跳转到下面页面 root ALL=(ALL:ALL) ALL下面添加wmui ALL=(ALL) NOPASSWD: ALLctrl+x保存退出接下来打开一个新的窗口,测试是否登

centos 6.5安装NodeJS

centos 6.5安装NodeJS 下载 可以在本地下载node.js最新版,然后通过ftp工具上传到服务器,或者直接在服务器终端使用wget命令下载(我当时下载的是node-v7.5.0-linux-x86版本,其他版本请查看上面链接然后替换即可): $ wget http://nodejs.org/dist/latest/node-v7.5.0-linux-x86.tar.gz 解压 进入服务器终端,找到上传或者下载的安装包,解压 $ tar -zvxf node-v7.5.0-linux

NodeJS之queryString

前面的话 无论是前端还是后端,经常出现的应用场景是URL中参数的处理.nodeJS的queryString模块提供了一些处理 query strings 的工具.本文将详细介绍nodeJS中的queryString var querystring = require('querystring'); /* { unescapeBuffer: [Function], unescape: [Function: qsUnescape], escape: [Function], encode: [Func