测试环境:
windows10虚拟机vmware安装的ubuntu14.04
内存1g,处理器数量2个,每个处理器核心数量1个
测试工具apchebench(ab)
python版本:2.7
tornado版本4.3
go版本1.4
beego版本1.6
tornado helloworld:
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("hello,world")
if __name__ == "__main__":
app = tornado.web.Application(handlers=[(r"/",MainHandler)])
app.listen(8888)
tornado.ioloop.IOLoop.current().start()
ab测试:ab -n 1000 -c 20 http://127.0.0.1:8888/
Benchmarking 127.0.0.1 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: TornadoServer/4.3
Server Hostname: 127.0.0.1
Server Port: 8888
Document Path: /
Document Length: 11 bytes
Concurrency Level: 20
Time taken for tests: 0.549 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 204000 bytes
HTML transferred: 11000 bytes
Requests per second: 1821.49 [#/sec] (mean)
Time per request: 10.980 [ms] (mean)
Time per request: 0.549 [ms] (mean, across all concurrent requests)
Transfer rate: 362.87 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 1
Processing: 1 11 10.2 8 157
Waiting: 1 11 10.2 8 157
Total: 2 11 10.2 8 158
Percentage of the requests served within a certain time (ms)
50% 8
66% 9
75% 10
80% 11
90% 21
95% 24
98% 29
99% 30
100% 158 (longest request)
package main
import (
"github.com/astaxie/beego"
)
type MainController struct {
beego.Controller
}
func (this *MainController) Get() {
this.Ctx.WriteString("hello world")
}
func main() {
beego.Router("/", &MainController{})
beego.Run()
}
Benchmarking 127.0.0.1 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: beegoServer:1.6.1
Server Hostname: 127.0.0.1
Server Port: 8080
Document Path: /
Document Length: 11 bytes
Concurrency Level: 20
Time taken for tests: 0.099 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 155000 bytes
HTML transferred: 11000 bytes
Requests per second: 10093.06 [#/sec] (mean)
Time per request: 1.982 [ms] (mean)
Time per request: 0.099 [ms] (mean, across all concurrent requests)
Transfer rate: 1527.76 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.8 0 17
Processing: 0 2 2.2 2 18
Waiting: 0 1 0.7 2 18
Total: 0 2 2.3 2 18
WARNING: The median and mean for the waiting time are not within a normal deviation
These results are probably not that reliable.
Percentage of the requests served within a certain time (ms)
50% 2
66% 2
75% 2
80% 2
90% 2
95% 2
98% 17
99% 18
100% 18 (longest request)
可以看出,beego借着go语言的优势,性能比tornado高很多,而且代码看着也很简洁
本人出于个人兴趣,创建了一个个人公众号,每天筛选国外网友发现的有趣的事情推送到公众号,欢迎关注!