最近一段時間,Cloud Insight接連發布了三種語言(Python, Node, Ruby)的SDK,Cloud Insight Agent也迎來了重大突破,釋出了Windows監控第一個版本,總算可以鬆口氣寫點東西了~
題外話二:
偶然的機會看到一篇blog,文中詳細的介紹了Flask(Python), Sinatra(Ruby)以及 Matini(Golang)這三類微型框架的用法,並提供了各個框架在Docker下的部署方式。然而,美中不足的是沒有提供各個框架的效能對比情況,經過一番蒐羅,發現了一篇對現今主流框架做效能對比的文章,找到兩者的結合點,於是才有了今天這篇文章~
迴歸正題,之所以選擇Flask(Python), Sinatra(Ruby), Matini(Golang)和Express(Node),主要是經驗所限以及個人比較喜歡這類微型框架,下面我們就對各個框架在同等條件下的效能表現一探究竟。
本文原始碼地址:https://github.com/startover/fibonacci-webapp-benchmark
環境準備:
Docker
安裝文件:https://docs.docker.com/engine/installation/
ab
CentOS/Redhat:
1 |
yum install httpd-tools |
Ubuntu/Debian:
1 |
apt-get update && apt-get install apache2-utils |
啟動容器
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$ git clone git@github.com:startover/fibonacci-webapp-benchmark.git $ cd fibonacci-webapp-benchmark $ ./docker-compose up -d Recreating fibonacciwebappbenchmark_python_1... Recreating fibonacciwebappbenchmark_go_1... Recreating fibonacciwebappbenchmark_ruby_1... Recreating fibonacciwebappbenchmark_node_1... $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 14e0d2388dca fibonacciwebappbenchmark_node "npm start" 6 seconds ago Up 5 seconds 0.0.0.0:8080->8080/tcp fibonacciwebappbenchmark_node_1 8b1bdd070f83 fibonacciwebappbenchmark_ruby "bundle exec ruby sin" 23 seconds ago Up 22 seconds 0.0.0.0:4567->4567/tcp fibonacciwebappbenchmark_ruby_1 333360123b56 fibonacciwebappbenchmark_go "go run martini.go" 34 seconds ago Up 32 seconds 0.0.0.0:3000->3000/tcp fibonacciwebappbenchmark_go_1 df50829f511b fibonacciwebappbenchmark_python "python app.py" 42 seconds ago Up 41 seconds 0.0.0.0:5000->5000/tcp fibonacciwebappbenchmark_python_1 |
效能測試
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
$ ab -n 100000 -c 100 http://localhost:5000/10 ... Concurrency Level: 100 Time taken for tests: 168.322 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Total transferred: 18400000 bytes HTML transferred: 2900000 bytes Requests per second: 594.10 [#/sec] (mean) Time per request: 168.322 [ms] (mean) Time per request: 1.683 [ms] (mean, across all concurrent requests) Transfer rate: 106.75 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.3 0 12 Processing: 21 168 15.3 166 295 Waiting: 13 167 15.1 165 286 Total: 26 168 15.3 166 295 ... |
Ruby + Sinatra
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
$ ab -n 100000 -c 100 http://localhost:4567/10 ... Concurrency Level: 100 Time taken for tests: 496.401 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Total transferred: 30700000 bytes HTML transferred: 3000000 bytes Requests per second: 201.45 [#/sec] (mean) Time per request: 496.401 [ms] (mean) Time per request: 4.964 [ms] (mean, across all concurrent requests) Transfer rate: 60.40 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.3 0 14 Processing: 180 493 522.3 412 10507 Waiting: 177 485 521.7 404 10505 Total: 180 493 522.3 412 10507 ... |
Go + Martini
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
$ ab -n 100000 -c 100 http://localhost:3000/10 ... Concurrency Level: 100 Time taken for tests: 48.284 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Total transferred: 15700000 bytes HTML transferred: 4100000 bytes Requests per second: 2071.08 [#/sec] (mean) Time per request: 48.284 [ms] (mean) Time per request: 0.483 [ms] (mean, across all concurrent requests) Transfer rate: 317.54 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 0.7 1 14 Processing: 13 47 12.0 47 105 Waiting: 3 35 10.4 34 99 Total: 14 48 12.0 48 112 ... |
Node + Express
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
$ ab -n 100000 -c 100 http://localhost:8080/10 ... Concurrency Level: 100 Time taken for tests: 59.962 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Total transferred: 20700000 bytes HTML transferred: 3000000 bytes Requests per second: 1667.72 [#/sec] (mean) Time per request: 59.962 [ms] (mean) Time per request: 0.600 [ms] (mean, across all concurrent requests) Transfer rate: 337.13 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.5 0 20 Processing: 26 59 11.2 59 168 Waiting: 16 56 10.8 55 168 Total: 26 60 11.1 59 171 ... |
總結:
Web framework | avg | min | max |
---|---|---|---|
Flask(Python) | 168ms | 26ms | 295ms |
Sinatra(Ruby) | 496ms | 180ms | 10507ms |
Martini(Go) | 48ms | 14ms | 112ms |
Express(Node) | 60ms | 26ms | 171ms |
可見,Matini(Golang)和Express(Node)效能優勢比較明顯,也在意料之中,Flask(Python)表現中規中矩,相較之下,Sinatra(Ruby)的效能簡直是沒法忍(PS: 我不是Ruby黑)!感興趣的親們可以在自己的環境測試下。完。
參考連結:
https://realpython.com/blog/python/python-ruby-and-golang-a-web-Service-application-comparison/
https://medium.com/@tschundeee/express-vs-flask-vs-go-acc0879c2122#.6katm1qn2