scala Play 2.5 vs golang基准测试,并在play框架中优化性能
我在
scala play framework 2.5和golang中对一个简单的hello world示例进行基准测试. Golang似乎在很大程度上表现出色,我想知道如何优化游戏框架以提高性能.
我正在使用以下内容进行基准测试 ab -r -k -n 100000 -c 100 http://localhost:9000/ 我正在使用我项目中的默认配置在prod模式下运行2.5.有人可以帮助我调整播放服务器的性能,以获得最佳性能吗?我读了默认调度程序线程池,但我不确定我的电脑使用什么设置.还有其他我可以检查的区域有助于提高性能吗? 这是我的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/ 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的源代码 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) } 这是来自golang的ab基准测试的结果 ab -r -k -n 100000 -c 100 http://localhost:8080/ This is ApacheBench,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) 提前感谢你 UPDATE! 以下结果可以提高性能,但我仍然对可以提高性能的其他想法感兴趣 package controllers import play.api.mvc._ import scala.concurrent.Future import play.api.libs.concurrent.Execution.Implicits.defaultContext class Application extends Controller { def index = Action.async { Future.successful(Ok("Hello,world!")) } } 基准结果 ab -r -k -n 100000 -c 100 http://localhost:9000/ This is ApacheBench,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) 解决方法
正如@marcospereira所说,Play是一个相对高级的框架,专注于利用Scala中更高级的类型系统来为您提供许多功能和安全性,这反过来又可以帮助您编写可重构和可扩展的代码.您的需求.从来没有,我在生产中获得了很好的表现.
除了建议您尝试使用native socket transport在Linux上运行基准测试之外,我将重复@marcospereira所说的,在不停止Play服务器的情况下运行基准测试几次. Play基准测试结果的标准偏差似乎异常高(平均值为1,标准差为2.2),这表明JIT尚未完全为您完成优化代码. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |