记录一下:

nginx做反向代理,单纯测试框架。

机器配置:
Intel® Core™ i5-3470 CPU @ 3.20GHz 4核心 8G内存

test.go:

<!-- lang: cpp -->
package main
import (
"encoding/json"
"fmt"
"github.com/emicklei/go-restful"
"io"
"net/http"
"runtime"
"os"
)
var count int = 0
func main() {runtime.GOMAXPROCS(8)ws := new(restful.WebService)ws.Route(ws.GET("/").To(hello))restful.Add(ws)fmt.Println("Server starting on port ", os.Args[1])http.ListenAndServe(":"+os.Args[1], nil)
}func hello(req *restful.Request, resp *restful.Response) {article := Article{"A Royal Baby", "A slow news week"}count++fmt.Println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", count)b, _ := json.Marshal(article)io.WriteString(resp, string(b))
}type Article struct {Name stringBody string
}

tornado.py

#!/usr/bin/env pythonimport tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.webfrom tornado.options import define, optionsdefine("port", default=8888, help="run on the given port", type=int)class MainHandler(tornado.web.RequestHandler):def get(self):self.write("Hello, world")def main():tornado.options.parse_command_line()application = tornado.web.Application([(r"/", MainHandler),])http_server = tornado.httpserver.HTTPServer(application)http_server.listen(options.port)tornado.ioloop.IOLoop.instance().start()if __name__ == "__main__":main()

nginx 配置:

<!-- lang: shell -->worker_processes  8;events {worker_connections  1024;
}upstream tornado_online {server    127.0.0.1:15101;server    127.0.0.1:15102;server    127.0.0.1:15103;server    127.0.0.1:15104;}upstream go_online {server    127.0.0.1:15201;server    127.0.0.1:15202;server    127.0.0.1:15203;server    127.0.0.1:15204;}server {listen       9000;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {proxy_pass    http://tornado_online/;proxy_set_header    Host $host;proxy_set_header    X-Real-IP $remote_addr;proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;client_max_body_size    10m;client_body_buffer_size  128k;proxy_connect_timeout    90;proxy_send_timeout            90;proxy_read_timeout            90;}
}server {listen       9001;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {proxy_pass    http://go_online/;proxy_set_header    Host $host;proxy_set_header    X-Real-IP $remote_addr;proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;client_max_body_size    10m;client_body_buffer_size  128k;proxy_connect_timeout    90;proxy_send_timeout            90;proxy_read_timeout            90;}
}

启动go:

nohup ./test 15201 &
nohup ./test 15202 &
nohup ./test 15203 &
nohup ./test 15204 &

启动tornado:

nohup python tornado.py –port=15101 &
nohup python tornado.py –port=15102 &
nohup python tornado.py –port=15103 &
nohup python tornado.py –port=15104 &

测试: go

<!-- lang: shell -->$ab -c 500 -n 1000000 http://192.168.0.108:9001/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking 192.168.0.108 (be patient)
Completed 100000 requests
Completed 200000 requests
Completed 300000 requests
Completed 400000 requests
Completed 500000 requests
Completed 600000 requests
Completed 700000 requests
Completed 800000 requests
Completed 900000 requests
Completed 1000000 requests
Finished 1000000 requestsServer Software:        nginx/1.5.7
Server Hostname:        192.168.0.108
Server Port:            9001Document Path:          /
Document Length:        49 bytesConcurrency Level:      500
Time taken for tests:   89.459 seconds
Complete requests:      1000000
Failed requests:        0
Write errors:           0
Total transferred:      206002060 bytes
HTML transferred:       49000490 bytes
Requests per second:    11178.28 [#/sec] (mean)
Time per request:       44.730 [ms] (mean)
Time per request:       0.089 [ms] (mean, across all concurrent requests)
Transfer rate:          2248.78 [Kbytes/sec] receivedConnection Times (ms)min  mean[+/-sd] median   max
Connect:        0   24 123.4      7    2028
Processing:     1   20  19.1     18     630
Waiting:        1   16  18.2     14     623
Total:          2   45 125.9     26    2040Percentage of the requests served within a certain time (ms)50%     2666%     3175%     3480%     3690%     4395%     5198%    11299%    983100%   2040 (longest request)➜  test  ps aux | grep test
root     25733 11.6  0.3 1739840 28812 pts/7   SNl  15:04   0:25 ./test 15201
root     25737 11.6  0.4 2140036 36104 pts/7   SNl  15:04   0:25 ./test 15202
root     25741 11.6  0.3 1697800 28472 pts/7   SNl  15:04   0:25 ./test 15203
root     25754 11.6  0.3 1738620 28892 pts/7   SNl  15:04   0:25 ./test 15204
cpu: 50%左右

测试:tornado

<!-- lang: shell -->$ab -c 500 -n 1000000 http://192.168.0.108:9000/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking 192.168.0.108 (be patient)
Completed 100000 requests
Completed 200000 requests
Completed 300000 requests
Completed 400000 requests
Completed 500000 requests
Completed 600000 requests
Completed 700000 requests
Completed 800000 requests
Completed 900000 requests
Completed 1000000 requests
Finished 1000000 requestsServer Software:        nginx/1.5.7
Server Hostname:        192.168.0.108
Server Port:            9000Document Path:          /
Document Length:        12 bytesConcurrency Level:      500
Time taken for tests:   163.648 seconds
Complete requests:      1000000
Failed requests:        1(Connect: 0, Receive: 0, Length: 1, Exceptions: 0)
Write errors:           0
Non-2xx responses:      1
Total transferred:      218000099 bytes
HTML transferred:       12000156 bytes
Requests per second:    6110.67 [#/sec] (mean)
Time per request:       81.824 [ms] (mean)
Time per request:       0.164 [ms] (mean, across all concurrent requests)
Transfer rate:          1300.90 [Kbytes/sec] receivedConnection Times (ms)min  mean[+/-sd] median   max
Connect:        0    6  33.9      1    1011
Processing:     1   75 188.5     40    7108
Waiting:        1   72 188.2     37    7107
Total:          1   81 191.2     45    7110Percentage of the requests served within a certain time (ms)50%     4566%     6675%     8280%     9290%    12195%    15098%   102799%   1067100%   7110 (longest request)
➜  helloworld git:(master) ✗ ps aux | grep tornado
root      1747  0.0  0.1 106348 12920 pts/7    SN   15:34   0:00 python tornado.py –port=15101
root      4534  0.0  0.0  15956  1092 pts/7    S+   15:39   0:00 grep tornado
root     16785  5.0  0.2 112056 18472 pts/7    SN   14:24   3:46 python tornado.py --port=15101
root     16847  5.0  0.2 111260 18036 pts/7    SN   14:24   3:46 python tornado.py --port=15102
root     16879  5.0  0.2 111832 18396 pts/7    SN   14:24   3:47 python tornado.py --port=15103
root     16911  5.0  0.2 111272 18044 pts/7    SN   14:24   3:47 python tornado.py --port=15104
cpu: 100%

总结:
go+nginx的qps是tornado+nginx的1.4倍左右。tornado的响应时间(tpr)是go的1倍左右。tornado会使cpu跑满100%而go只需要50%左右

来源:http://www.codeweblog.com/nginx-tornado%E4%B8%8Enginx-go%E7%9A%84%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%95/

nginx+tornado与nginx+go的性能测试相关推荐

  1. ubuntu下python+tornado+supervisor+nginx部署

    由于项目需要,老师让我写一个小web系统,之前都是用java写web,想到自己最近学机器学习要用python,所以用python来写一下,此外,因为想用点新东西,也介于程序比较小,所以考虑用mongo ...

  2. Nginx + tornado + supervisor部署

    参考链接:supervisor + Tornado + Nginx 使用详解, 用tornado ,Supervisord ,nginx架网站, tornado官方文档 项目文档树: . ├── ch ...

  3. nginx tornado php,tornado+nginx+python 微信公众号接入配置

    配置环境:腾讯主机 Ubuntu Server 16.04.1 LTS 64位 需要用到的软件或者包:nginx,tornado框架 xshell6(非必需) 微信公众号测试平台:http://mp. ...

  4. Nginx学习之Nginx高性能的实现原理

    Nginx 采用的是多进程(单线程) & 多路IO复用模型,使用了 I/O 多路复用技术的 Nginx,就成了"并发事件驱动"的服务器,同时使用sendfile等技术,最终 ...

  5. Nginx防盗链,Nginx访问控制, Nginx解析php相关配置, Nginx代理

    2019独角兽企业重金招聘Python工程师标准>>> Nginx防盗链 Nginx防盗链配置需要与不记录日志和过期时间结合在一起,因为都用到了location. 打开配置文件,注释 ...

  6. Nginx配置——搭建 Nginx 高可用集群(双机热备)

    Nginx配置--搭建 Nginx 高可用集群(双机热备) https://blog.csdn.net/zxd1435513775/article/details/102508573?utm_medi ...

  7. gitlab自带的Nginx与原Nginx冲突的解决方案

    gitlab自带的Nginx与原Nginx冲突的解决方案 参考文章: (1)gitlab自带的Nginx与原Nginx冲突的解决方案 (2)https://www.cnblogs.com/lz0925 ...

  8. Nginx主配置文件nginx.conf详细说明

    第3章 Nginx核心配置文件nginx.conf史上最细中文详解 3.1定义Nginx运行的用户和用户组 user nginx nginx;#改为特殊的用户和组 3.2 nginxworker进程数 ...

  9. nginx 支持php-fpm,nginx php-fpm安装配置以支持PHP

    nginx本身不能处理PHP,它只是个web服务器,当接收到请求后,如果是php请求,则发给php解释器处理,并把结果返回给客户端. nginx一般是把请求发fastcgi管理进程处理,fascgi管 ...

最新文章

  1. SNMP introduction
  2. mysql5.7 生成列 generated column
  3. 超大数据下大批量随机键值的查询优化方案 1
  4. 两篇关于MCU的嵌入式应用的文章【ZZ】
  5. 针对谷歌浏览器Chrome的CSS hack
  6. 1775. [国家集训队2010]小Z的袜子
  7. gnu grub version 2.0.2设置启动顺序_如何修复grub异常
  8. 为什么在微信的阴影下QQ依然是中国第二大App?
  9. Bypass功能depletion mode
  10. 中国1km分辨率的DEM数据以及合并后的中国行政区划数据
  11. X波段雷达对海探测试验与数据获取
  12. 微信⼩程序——wxParse使⽤⽅法
  13. js:toastr弹出提示信息
  14. 可以免费领取卡巴斯基激活码的活动
  15. 二十七、商城 - 搜索解决方案-Solr(15)【1】
  16. 案例▍Python实战 爬取万条票房数据分析2019春节档电影状况
  17. 共享充电宝APP小程序开发
  18. 嵌入式字符设备驱动——ULN2003步进电机驱动程序实现
  19. MaixII-Dock(v831)学习笔记——PWM
  20. C-kermit安装方法

热门文章

  1. Redash 9安装与配置(基于Docker方式)
  2. python通过DictReader实现两个csv文件的映射查找lookup之代码详解
  3. 时间序列错位还原之SQL实现案例详解
  4. 美国本科计算机科学,美国本科计算机科学就业情况分析
  5. java 博客系统_讲解开源项目:5分钟搭建私人Java博客系统
  6. linux nexus端口配置,Linux下安装Nexus-3.15私服
  7. 添加别名_ssh别名免密登陆服务器
  8. 《你不知道的JavaScript》-- 精读(五)
  9. 数据仓库分层ODS DW DM 主题 标签
  10. php empty();和isset();