结论: 其实如果纯粹输出 Hellow world的话, 大家都差不多. 关键还是要看实际的应用情况( 读取数据库)
.
今天看到 express 框架的最好相应速度是 : 2200 req/s .一时兴起, 打算对比下 其他几种框架的速度.
使用的命令是ab:
$ ab -n 1000 -c 1000 http://localhost:3000/
没有读取数据库,都是纯文字hello world.
咱们看一下.
1. sinatra:
require 'sinatra' get '/' do "Hello World!" end $ ruby test_sinatra.rb
跟 express 一样, 每秒 2000个左右请求, 1800 ~ 2500浮动. 大部分都在1800 ~ 2000
2. express , 跟sinatra一样一样的.
3. java : 算了. 太复杂. ... 从头到尾需要 WEB-INF, xml, jar 等搭建各种东西.... 算了吧... 看了下 stackoverflow上一个人给出的测试, 700 req/s
4. python tornado: 没有经过任何优化, ( 跟sinatra, expressjs 一样)
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
application = tornado.web.Application([
(r"/", MainHandler),
])
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
每秒处理1000个请求 . 但是我估计是没有使用 uwsgi + nginx 造成的? 不清楚了.
Concurrency Level: 1000
Time taken for tests: 1.002 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 205000 bytes
HTML transferred: 12000 bytes
Requests per second: 998.03 [#/sec] (mean)
Time per request: 1001.972 [ms] (mean)
Time per request: 1.002 [ms] (mean, across all concurrent requests)
Transfer rate: 199.80 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 4 7.3 0 21
Processing: 3 128 42.3 120 525
Waiting: 3 128 42.3 120 525
Total: 23 131 41.9 120 525
Percentage of the requests served within a certain time (ms)
50% 120
66% 136
75% 139
80% 170
90% 184
95% 202
98% 216
99% 222
100% 525 (longest request)