python高性能web框架——Japronto,pythonjapronto, 近期做了一个简单
python高性能web框架——Japronto,pythonjapronto, 近期做了一个简单
近期做了一个简单的demo需求,搭建一个http server,支持简单的qa查询。库中有10000个qa对,需要支持每秒10000次以上的查询请求。
需求比较简单,主要难点就是10000+的RPS。首先使用python + uwsgi写了个简单的demo,压测后发现,RPS只有几千,达不到性能要求。后来部署了多个服务,使用nginx做负载均衡才勉强达到需求。
Japronto
后来经过google 搜索,发现了Japronto,github地址https://github.com/squeaky-pl/japronto,性能非常强悍,可以看下作者提供的性能图:
为什么可以有这么高的性能,因为Japronto做了大量优化,其中最主要的是HTTP pipelining,Japronto 用它来做执行并发请求的优化。大多数服务器把来自客户端的pipelining和non-pipelining请求都一视同仁,用同样的方法处理,并没有做针对性的优化。
其他细节可以参考 https://medium.freecodecamp.org/million-requests-per-second-with-python-95c137af319 和https://github.com/squeaky-pl/japronto
测试
采用docker的方式进行部署的,按照官网的例子
1、拉取镜像
docker pull japronto/japronto
2、编写测试代码
# examples/1_hello/hello.pyfrom japronto import Application# Views handle logic, take request as a parameter and# returns Response object back to the clientdef hello(request): return request.Response(text=‘Hello world!‘)# The Application instance is a fundamental concept.# It is a parent to all the resources and all the settings# can be tweaked here.app = Application()# The Router instance lets you register your handlers and execute# them depending on the url path and methodsapp.router.add_route(‘/‘, hello)# Finally start our server and handle requests until termination is# requested. Enabling debug lets you see request logs and stack traces.app.run(debug=True)
3、启动docker 容器
docker run -p 8080:8080 -v $(pwd)/hello.py:/hello.py japronto/japronto --script /hello.py
使用wrk进行压测,使用 单线程,100个连接,压测30s。结果如下
wrk -c 100 -t 1 -d 30s http://192.168.86.10:8077/Running 30s test @ http://192.168.86.10:8077/ 1 threads and 100 connections Thread Stats Avg Stdev Max +/- Stdev Latency 1.88ms 548.76us 17.70ms 88.46% Req/Sec 53.43k 2.40k 54.86k 96.33% 1593994 requests in 30.02s, 139.85MB readRequests/sec: 53104.58Transfer/sec: 4.66MB
压测结果受服务器,运行方式等影响,虽然和给出的数据相差较大,但是性能也是非常强悍的。
不过比较遗憾的是,目前这个项目已经暂停更新了
python高性能web框架——Japronto
相关内容
- 深度学习 GPU环境 Ubuntu 16.04 + Nvidia GTX 1080 + Python 3.6 +
- Python在Windows下操作CH341DLL,pythonch341dll, 1 #! /usr
- win10环境下python3安装sqlserver方法,win10python3,win10环境下
- python爬虫--模拟登录知乎,python爬虫--,1、处理登录表单
- python正则表达式re 中m.group和m.groups的解释,m.groupm.gro
- python cookies 爬虫处理,pythoncookies,CookieCook
- 并发体验:Python抓图的8种方式,并发python抓图8种,本文
- Python pyQt4学习笔记1,pythonpyqt4,PyQt4是用来编写
- Python中PIL及Opencv转化,pythonpilopencv,转载:http://
- Python3基础 小技巧 为模块更换名字 import 模块名 as 别名
评论关闭