hello大家好,
今天给大家介绍一个python的高性能web framework,目前是beta版本,
我们将其与tornado进行性能对比:
OS:Linux 4.2
Python:2.7.11
项目github地址:点击
先给大家看两段代码:
1、tornado的代码:
[code lang=”python”]
# -*-coding:utf-8-*-
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, World!")
Handlers=[
(r"/hello", MainHandler),
]
application = tornado.web.Application(Handlers)
if __name__ == "__main__":
application.listen(9999)
tornado.ioloop.IOLoop.instance().start()
[/code]
2、karlooper代码
[code lang=”python”]
# -*-coding:utf-8-*-
from karlooper.web.application import Application
from karlooper.web.request import Request
class MainHandler(Request):
def get(self):
return self.http_response("Hello,World!")
handlers = {
"/hello": MainHandler
}
if __name__ == ‘__main__’:
application = Application(handlers, port=9999)
application.run()
[/code]
我们使用Apache Bench进行性能测试:
测试结果如下:
tornado
[code]
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 127.0.0.1 (be patient)…..done
Server Software: TornadoServer/4.0.2
Server Hostname: 127.0.0.1
Server Port: 9999
Document Path: /hello
Document Length: 12 bytes
Concurrency Level: 10
Time taken for tests: 0.011 seconds
Complete requests: 10
Failed requests: 0
Write errors: 0
Total transferred: 2070 bytes
HTML transferred: 120 bytes
Requests per second: 946.70 [#/sec] (mean)
Time per request: 10.563 [ms] (mean)
Time per request: 1.056 [ms] (mean, across all concurrent requests)
Transfer rate: 191.37 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 1
Processing: 1 4 1.9 4 6
Waiting: 1 3 1.9 3 6
Total: 1 4 1.8 4 7
Percentage of the requests served within a certain time (ms)
50% 4
66% 5
75% 5
80% 6
90% 7
95% 7
98% 7
99% 7
100% 7 (longest request)
[/code]
karlooper
[code]
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 127.0.0.1 (be patient)…..done
Server Software:
Server Hostname: 127.0.0.1
Server Port: 9999
Document Path: /hello
Document Length: 10 bytes
Concurrency Level: 10
Time taken for tests: 0.005 seconds
Complete requests: 10
Failed requests: 0
Write errors: 0
Total transferred: 1738 bytes
HTML transferred: 110 bytes
Requests per second: 2157.96 [#/sec] (mean)
Time per request: 4.634 [ms] (mean)
Time per request: 0.463 [ms] (mean, across all concurrent requests)
Transfer rate: 366.26 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 0.6 2 2
Processing: 1 2 0.6 2 2
Waiting: 0 1 0.7 1 2
Total: 2 3 0.5 3 4
Percentage of the requests served within a certain time (ms)
50% 3
66% 3
75% 4
80% 4
90% 4
95% 4
98% 4
99% 4
100% 4 (longest request)
[/code]
通过以上数据对比,我们发现,同等条件下:
karlooper的性能要明显高于tornado。