【发布时间】:2014-03-14 23:39:41
【问题描述】:
我在 Golang+Martini 和 Play Framework 2.2.x 中编写了两个相同的项目来比较它的性能。两者都有 1 个渲染 10K HTML 视图的操作。使用ab -n 10000 -c 1000 对其进行测试,并通过ab 输出和htop 监控结果。两者都使用生产配置和编译视图。我想知道结果:
Play: ~17000 req/sec + constant 100% usage of all cores of my i7 = ~0.059 msec/req
Martini: ~4000 req/sec + constant 70% usage of all cores of my i7 = ~0.25 msec/req
...据我所知,马提尼酒并不臃肿,那为什么慢 4.5 倍?有什么方法可以加快速度?
更新:添加了基准测试结果
Golang + 马提尼酒:
./wrk -c1000 -t10 -d10 http://localhost:9875/
Running 10s test @ http://localhost:9875/
10 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 241.70ms 164.61ms 1.16s 71.06%
Req/Sec 393.42 75.79 716.00 83.26%
38554 requests in 10.00s, 91.33MB read
Socket errors: connect 0, read 0, write 0, timeout 108
Requests/sec: 3854.79
Transfer/sec: 9.13MB
播放!框架 2:
./wrk -c1000 -t10 -d10 http://localhost:9000/
Running 10s test @ http://localhost:9000/
10 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 32.99ms 37.75ms 965.76ms 85.95%
Req/Sec 2.91k 657.65 7.61k 76.64%
276501 requests in 10.00s, 1.39GB read
Socket errors: connect 0, read 0, write 0, timeout 230
Requests/sec: 27645.91
Transfer/sec: 142.14MB
马提尼与runtime.GOMAXPROCS(runtime.NumCPU())一起运行
我想在生产中使用 golang,但是在这个基准测试之后我不知道我该如何做出这样的决定......
有什么方法可以加快速度?
【问题讨论】:
-
我建议您将两个项目的代码发布到 github,并附上如何重现您的比较的说明。那么你得到答案的可能性就更大了。
-
我的第一个想法 - 你在一个内核上运行 go 应用程序,请参阅 golang.org/pkg/runtime/#GOMAXPROCS
-
Apache Bench 极其不可靠。尝试使用 wrk:github.com/wg/wrk
-
避免使用框架。一年多来,我一直在做一个生产网络堆栈,除了标准库和大猩猩的网络工具包(会话/路由)之外,我从来不需要任何东西。向生产 Web 堆栈添加任何开销对我来说毫无意义,因为标准库已经非常强大。我觉得一般来说,来自 rails 的人会在 go 中寻找一个框架,因为这是他们习惯的。我们需要更好的例子来说明如何不使用框架。
-
Martini 大量使用反射。可能这会导致性能下降?
标签: web-services playframework go playframework-2.0