Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance scala Play 2.5 vs golang基准,并在Play框架中优化性能_Performance_Scala_Optimization_Go_Playframework - Fatal编程技术网

Performance scala Play 2.5 vs golang基准,并在Play框架中优化性能

Performance scala Play 2.5 vs golang基准,并在Play框架中优化性能,performance,scala,optimization,go,playframework,Performance,Scala,Optimization,Go,Playframework,我正在scala play framework 2.5和golang中对一个简单的hello world示例进行基准测试。Golang的游戏性能似乎大大超过了play,我想知道如何优化play框架以提高性能。 我使用以下方法来进行基准测试 ab -r -k -n 100000 -c 100 http://localhost:9000/ ab -r -k -n 100000 -c 100 http://localhost:9000/ This is ApacheBench, Version 2.

我正在scala play framework 2.5和golang中对一个简单的hello world示例进行基准测试。Golang的游戏性能似乎大大超过了play,我想知道如何优化play框架以提高性能。 我使用以下方法来进行基准测试

ab -r -k -n 100000 -c 100 http://localhost:9000/
ab -r -k -n 100000 -c 100 http://localhost:9000/
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:
Server Hostname:        localhost
Server Port:            9000

Document Path:          /
Document Length:        13 bytes

Concurrency Level:      100
Time taken for tests:   1.537 seconds
Complete requests:      100000
Failed requests:        0
Keep-Alive requests:    100000
Total transferred:      15400000 bytes
HTML transferred:       1300000 bytes
Requests per second:    65061.81 [#/sec] (mean)
Time per request:       1.537 [ms] (mean)
Time per request:       0.015 [ms] (mean, across all concurrent requests)
Transfer rate:          9784.69 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       1
Processing:     0    2   1.9      1      72
Waiting:        0    2   1.9      1      72
Total:          0    2   1.9      1      72

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      2
  75%      2
  80%      2
  90%      3
  95%      3
  98%      5
  99%      8
 100%     72 (longest request)
我在prod模式下运行Play2.5,在我的项目中使用默认配置。有人能帮我调整播放服务器的性能以获得最佳性能吗?我阅读了默认的dispatcher线程池,但我不确定我的电脑要使用什么设置。还有哪些方面我可以检查,以帮助提高性能

这是我的marchine规格

Intel(R) Xeon(R) W3670 @ 3.20GHz 3.19GHz, 12.0 GM RAM, running windows 7 64-bit
请注意,我使用sbt(clean和stage)在prod模式下就地运行服务器,并执行target/universal/stage/bin/中的bat文件。这是游戏的源代码

package controllers

import play.api.mvc._


class Application extends Controller {


  def index = Action {
    Ok("Hello, world!")
  }

}
下面是ab基准测试的结果

ab -r -k -n 100000 -c 100 http://localhost:9000/
ab -r -k -n 100000 -c 100 http://localhost:9000/
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:
Server Hostname:        localhost
Server Port:            9000

Document Path:          /
Document Length:        13 bytes

Concurrency Level:      100
Time taken for tests:   1.537 seconds
Complete requests:      100000
Failed requests:        0
Keep-Alive requests:    100000
Total transferred:      15400000 bytes
HTML transferred:       1300000 bytes
Requests per second:    65061.81 [#/sec] (mean)
Time per request:       1.537 [ms] (mean)
Time per request:       0.015 [ms] (mean, across all concurrent requests)
Transfer rate:          9784.69 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       1
Processing:     0    2   1.9      1      72
Waiting:        0    2   1.9      1      72
Total:          0    2   1.9      1      72

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      2
  75%      2
  80%      2
  90%      3
  95%      3
  98%      5
  99%      8
 100%     72 (longest request)
以下是golang的ab基准测试结果

package main

import (
    "fmt"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello, world!")
}

func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
}
ab -r -k -n 100000 -c 100 http://localhost:8080/
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:
Server Hostname:        localhost
Server Port:            8080

Document Path:          /
Document Length:        13 bytes

Concurrency Level:      100
Time taken for tests:   0.914 seconds
Complete requests:      100000
Failed requests:        0
Keep-Alive requests:    100000
Total transferred:      15400000 bytes
HTML transferred:       1300000 bytes
Requests per second:    109398.30 [#/sec] (mean)
Time per request:       0.914 [ms] (mean)
Time per request:       0.009 [ms] (mean, across all concurrent requests)
Transfer rate:          16452.48 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       1
Processing:     0    1   1.5      1      52
Waiting:        0    1   1.5      1      52
Total:          0    1   1.5      1      52

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      2
  98%      5
  99%      7
 100%     52 (longest request) 
基准结果

ab -r -k -n 100000 -c 100 http://localhost:9000/
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:
Server Hostname:        localhost
Server Port:            9000

Document Path:          /
Document Length:        13 bytes

Concurrency Level:      100
Time taken for tests:   1.230 seconds
Complete requests:      100000
Failed requests:        0
Keep-Alive requests:    100000
Total transferred:      15400000 bytes
HTML transferred:       1300000 bytes
Requests per second:    81292.68 [#/sec] (mean)
Time per request:       1.230 [ms] (mean)
Time per request:       0.012 [ms] (mean, across all concurrent requests)
Transfer rate:          12225.66 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       1
Processing:     0    1   2.2      1     131
Waiting:        0    1   2.2      1     131
Total:          0    1   2.2      1     131

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      2
  90%      2
  95%      3
  98%      5
  99%      7
 100%    131 (longest request)
ab-r-k-n100000-c100http://localhost:9000/
这是ApacheBench,版本2.3
版权1996亚当·特维斯,宙斯科技有限公司,http://www.zeustech.net/
授权给Apache软件基金会,http://www.apache.org/
对本地主机进行基准测试(耐心等待)
已完成10000个请求
已完成20000个请求
完成30000个请求
已完成40000个请求
已完成50000个请求
已完成60000个请求
完成70000个请求
已完成80000个请求
已完成90000个请求
已完成100000个请求
完成100000个请求
服务器软件:
服务器主机名:localhost
服务器端口:9000
文档路径:/
文件长度:13字节
并发级别:100
测试时间:1.230秒
完成申请:100000
失败的请求:0
保持活动请求:100000
传输总量:15400000字节
传输的HTML:1300000字节
每秒请求数:81292.68[#/秒](平均值)
每次请求的时间:1.230[ms](平均值)
每个请求的时间:0.012[ms](所有并发请求的平均值)
传输速率:接收到12225.66[千字节/秒]
连接时间(毫秒)
最小平均值[+/-sd]最大中值
连接:0.0.0 1
处理:0112.21131
候补人数:0112.21131
总数:0112.21131
在特定时间内服务的请求百分比(毫秒)
50%      1
66%      1
75%      1
80%      2
90%      2
95%      3
98%      5
99%      7
100%131(最长请求)

正如@marcospereira所说,Play是一个相对高级的框架,它专注于利用Scala中更高级的类型系统,为您提供许多功能和安全性,从而帮助您编写可重构和可扩展的代码,以满足您的需要。尽管如此,我还是从它的制作中得到了很好的表现


我将重复@marcospereira所说的,不要建议您尝试在Linux上运行基准测试,在不停止Play服务器的情况下运行基准测试几次。您的Play基准测试结果中的标准偏差似乎异常高(平均值为1,SD为2.2),这表明JIT可能尚未完全为您完成代码优化。

这是因为您正在将低级http库(go
net/http
)与高级框架(Play)进行比较。高级框架正在做更多的事情,因为它提供了更多的实用程序,但速度较慢。比较一下netty(Play使用的http“库”)和Go
net/http
。我还建议对play运行测试,直到获得一致的结果为止(因为jvm上的jit编译)。@marcospereira我几乎不会称
net/http
“低级”,这是一个主要的抽象。您可以用一行代码打开一条路由,传入的请求将被解析并转化为一个很好的对象,其中所有数据都很容易访问。我会称之为相当高的级别,因为实际上接收的是二进制数据,而这些数据甚至不是一个整体。到OP;你为什么不干脆不玩呢?真糟糕。那是我的2美分。它的性能很差,因为它过于抽象,我打赌你不会使用它提供给你的80%,而你的性能将在100%的时间里受到影响。与play这样的全堆栈框架相比,它的级别很低。这就是a的意思。