测试环境:

  • 系统: CentOS 7.1
  • Mem: 8G
  • CPU: 虚拟机16核
  • Python版本: python3.6
  • Flask版本: 0.12.2
  • Golang版本: 1.6.3
1.首先写一个Flask的web程序,只返回一个 Hello word!
from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def hello_world():
return 'Hello word!' if __name__ == '__main__':
app.run()
2.写一个go语言的web程序,也返回一个 Hello word!
package main

import (
f "fmt"
"log"
"net/http"
) func sayhelloName(w http.ResponseWriter, r *http.Request) {
f.Fprintln(w, "hello world!")
}
func main() {
http.HandleFunc("/", sayhelloName)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("ListenAndServe:", err)
}
}
3.直接在控制台启动Flask, 用压力测试工具模拟并发请求。这里模拟100个并发100000个请求。
ab -n 100000 -c 100 "http://172.30.200.88:5000/"
Server Software:        Werkzeug/0.12.2
Server Hostname: 172.30.200.88
Server Port: 5000 Document Path: /
Document Length: 11 bytes Concurrency Level: 100
Time taken for tests: 88.441 seconds
Complete requests: 100000
Failed requests: 0
Write errors: 0
Total transferred: 16500000 bytes
HTML transferred: 1100000 bytes
Requests per second: 1130.70 [#/sec] (mean)
Time per request: 88.441 [ms] (mean)
Time per request: 0.884 [ms] (mean, across all concurrent requests)
Transfer rate: 182.19 [Kbytes/sec] received
4.用Gunicorn以8个进程启动flask,再以同样的并发测试一遍
Server Software:        gunicorn/19.7.1
Server Hostname: 172.30.200.88
Server Port: 8080 Document Path: /
Document Length: 11 bytes Concurrency Level: 100
Time taken for tests: 15.842 seconds
Complete requests: 100000
Failed requests: 0
Write errors: 0
Total transferred: 17100000 bytes
HTML transferred: 1100000 bytes
Requests per second: 6312.50 [#/sec] (mean)
Time per request: 15.842 [ms] (mean)
Time per request: 0.158 [ms] (mean, across all concurrent requests)
Transfer rate: 1054.14 [Kbytes/sec] received
5.以同样的并发测试Go
Server Software:
Server Hostname: 172.30.200.88
Server Port: 8080 Document Path: /
Document Length: 13 bytes Concurrency Level: 100
Time taken for tests: 12.460 seconds
Complete requests: 100000
Failed requests: 0
Write errors: 0
Total transferred: 13000000 bytes
HTML transferred: 1300000 bytes
Requests per second: 8025.80 [#/sec] (mean)
Time per request: 12.460 [ms] (mean)
Time per request: 0.125 [ms] (mean, across all concurrent requests)
Transfer rate: 1018.90 [Kbytes/sec] received

测试结果:
Flask 总耗时 88.441秒,平均每秒处理1130个请求
Gunicorn多进程时耗时 15.842, 平均每秒处理 6312个请求
Go 总耗时 12.46秒,每秒处理 8025个请求

相比之下 go跟gunicorn的处理速度有提升,但是并没有像传说中十倍的性能。在测试中还发现,在用flask的时候并不能支持大并发,当并发在200以上就很容易报错了, 而Golang的并发到1000都能正常运行,这一点上差距比较大。

Python flask 与 GO WEB服务器性能对比的更多相关文章

  1. 个人学期总结及Python+Flask+MysqL的web建设技术过程

    一个学期即将过去,我们也迎来了2018年.这个学期,首次接触了web网站开发建设,不仅是这门课程,还有另外一门用idea的gradle框架来制作网页. 很显然,用python语言的flask框架更加简 ...

  2. Python+Flask+MysqL的web建设技术过程

    一.前言(个人学期总结) 个人总结一下这学期对于Python+Flask+MysqL的web建设技术过程的学习体会,Flask小辣椒框架相对于其他框架而言,更加稳定,不会有莫名其妙的错误,容错性强,运 ...

  3. Python+Flask+MysqL的web技术建站过程

    1.个人学期总结 时间过得飞快,转眼间2017年就要过去.这一年,我学习JSP和Python,哪一门都像一样新的东西,之前从来没有学习过. 这里我就用我学习过的Python和大家分享一下,我是怎么从一 ...

  4. Web服务器性能监控分析与优化

    Web服务器性能监控分析与优化 http://www.docin.com/p-759040698.html

  5. Web服务器性能/压力测试工具http_load、webbench、ab、Siege使用教程 - VPS侦探

    Web服务器性能/压力测试工具http_load.webbench.ab.Siege使用教程 - VPS侦探 http://soft.vpser.net/test/http_load/http_loa ...

  6. python超简单的web服务器

    今天无意google时看见,心里突然想说,python做web服务器,用不用这么简单啊,看来是我大惊小怪了. web1.py   1 2 3 #!/usr/bin/python import Simp ...

  7. python自带的web服务器

    python自带的web服务器 python自带的包可以建立简单的web服务器 BaseHTTPServer 提供基本的web服务和处理类 SimpleHTTPServer 包含执行get请求的Sim ...

  8. Web服务器性能压力测试工具http_load、webbench、ab、Siege使用教程

    Web服务器性能压力测试工具http_load.webbench.ab.Siege使用教程 作者: feng 日期: 2012/07/25 发表评论 (0) 查看评论   一.http_load 程序 ...

  9. Web服务器性能/压力测试工具http_load、webbench、ab、Siege、loadrunner

    回头看看 Web服务器性能/压力测试工具http_load.webbench.ab.Siege.loadrunner

随机推荐

  1. java8新特性学习:stream与lambda

    Streams api 对 Stream 的使用就是实现一个 filter-map-reduce 过程,产生一个最终结果,或者导致一个副作用(side effect). 流的操作类型分为两种: Int ...

  2. PHP类知识----值传递和引用传递

    JS中数组是引用传递 PHP除了资源和对象等数据类型,其数据类型是值传递(即使数组也如此) 栈内存(快速内存)中存放标量数据类型,复合数据类型的变量名和数据地址 在内存中,我们可以认为内存中有很多格子 ...

  3. Python之列表与元组的区别详解

    相同点:都是序列类型 回答它们的区别之前,先来说说两者有什么相同之处.list 与 tuple 都是序列类型的容器对象,可以存放任何类型的数据.支持切片.迭代等操作 foos = [0, 1, 2, ...

  4. SpringBoot对接收及返回Instant类型的处理(转)

    一:处理post请求json中的Instant类型1.springboot中日期格式化配置: spring: jackson: date-format: yyyy-MM-dd HH:mm:ss tim ...

  5. 题解 【NOIP2014】解方程

    题面 解析 这题的数据看起来似乎特别吓人... 但实际上, 这题非常好想. 只需要模一个大质数就行了(我模的是1e9+7)(实测有效) 另外,a要用快读读入,再一边模Mod(因为实在太大了). 然后, ...

  6. CodeForces 788B - Weird journey [ 分类讨论 ] [ 欧拉通路 ]

    题意: 给出无向图. good way : 仅有两条边只经过一次,余下边全经过两次的路 问你共有多少条不同的good way. 两条good way不同仅当它们所经过的边的集合中至少有一条不同 (很关 ...

  7. hdu 6049 Sdjpx Is Happy

    题: OwO http://acm.hdu.edu.cn/showproblem.php?pid=6049 (2017 Multi-University Training Contest - Team ...

  8. Mysql存储时间字段

    兄弟连教育数据库培训教程 Mysql存储时间字段用int.timestamp还是datetime 通常存储时间用datetime类型,现在很多系统也用int存储时间,它们有什么区别?总结如下: int ...

  9. VLC播放器:快捷键

     造冰箱的大熊猫@cnblogs 2019/2/27 VLC播放器(VLC Media Player)快捷键汇总(在Ubuntu 16.04环境下测试) - 音量大/小:CTRL+上/下 - 静音开/ ...

  10. tp5分页,一看就懂,简单明了(附带额外参数)

    php 代码: $result = $jjModel->where($wheres)->paginate(10,false,['query' => ['peytype'=>$p ...