为什么Go的Martini不如Play Framework 2.2.x高效

时间:2014-03-14 23:39:41

标签: web-services playframework go playframework-2.0

我在Golang + Martini和Play Framework 2.2.x中写了两个相同的项目来比较它的性能。两者都有1个动作可呈现10K HTML视图。使用ab -n 10000 -c 1000对其进行测试,并通过ab输出和htop监控结果。两者都使用生产confs和编译视图。我想知道结果:

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 + Martini:

./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

Martini与runtime.GOMAXPROCS(runtime.NumCPU())

一起运行

我想在制作中使用golang,但在此基准之后我不知道如何做出这样的决定...

有加速的方法吗?

3 个答案:

答案 0 :(得分:2)

我制作了一个简单的马提尼应用程序,渲染了1个html文件并且速度非常快:

  ✗ wrk -t10 -c1000 -d10s  http://localhost:3000/
  Running 10s test @ http://localhost:3000/
    10 threads and 1000 connections
    Thread Stats   Avg      Stdev     Max   +/- Stdev
      Latency    31.94ms   38.80ms 109.56ms   83.25%
      Req/Sec     3.97k     3.63k   11.03k    49.28%
    235155 requests in 10.01s, 31.17MB read
    Socket errors: connect 774, read 0, write 0, timeout 3496
  Requests/sec:  23497.82
  Transfer/sec:      3.11MB

Macbook pro i7。 这是应用https://gist.github.com/zishe/9947025 如果你展示你的代码会有所帮助,也许你没有禁用日志或遗漏某些东西。

但是timeout 3496似乎很糟糕。

答案 1 :(得分:2)

@ Kr0e,对!我发现在马提尼的DI中大量使用反射使得它表现得很慢。 我搬到了大猩猩mux并写了一些马提尼风格的助手,并得到了一个想要的表现。

@Cory LaNou:我不能接受你的评论)现在我同意你的意见,没有任何框架是好主意。感谢

@ user3353963:看我的问题:两者都使用生产confs和编译视图

答案 2 :(得分:1)

添加以下代码:

func init(){
  martini.Env = martini.Prod
}
抱歉,您的代码已经完成。

相关问题