我现在正在调整我的Akka Http server
,并且在加载并发请求时会产生非常糟糕的结果。因为我不确定我是否在某个地方有隐藏的阻塞 IO 请求,所以我认为值得从 Akka Http 站点测试示例项目:
或者,您可以使用已经使用 Giter8 模板配置的 Akka HTTP 引导一个新的 sbt 项目:
sbt -Dsbt.version=0.13.15 new https://github.com/akka/akka-http-scala-seed.g8
我已经按照说明进行了引导并在本地主机上运行服务器:
/path/to/bootstrap/sbt run
[info] Running com.example.QuickstartServer
Server online at http://127.0.0.1:8080/
http://127.0.0.1:8080/
ab
我用“ ”工具运行了一些非常简单的测试:
执行顺序请求的简单测试:
ab -n 1000 http://127.0.0.1:8080/users
Server Software: akka-http/10.1.5
Server Hostname: 127.0.0.1
Server Port: 8080
Document Path: /users
Document Length: 12 bytes
Concurrency Level: 1
Time taken for tests: 0.880 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 165000 bytes
HTML transferred: 12000 bytes
Requests per second: 1136.74 [#/sec] (mean)
Time per request: 0.880 [ms] (mean)
Time per request: 0.880 [ms] (mean, across all concurrent requests)
Transfer rate: 183.17 [Kbytes/sec] received
我们看到"time per request" is 0.880 ms [mean]
在这种情况下
现在我将并发性提高到 5:
ab -n 1000 -c 5 http://127.0.0.1:8080/users
Concurrency Level: 5
Time taken for tests: 0.408 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 165000 bytes
HTML transferred: 12000 bytes
Requests per second: 2450.39 [#/sec] (mean)
Time per request: 2.040 [ms] (mean)
Time per request: 0.408 [ms] (mean, across all concurrent requests)
Transfer rate: 394.84 [Kbytes/sec] received
现在Time per request
急剧增加了 2.040 [ms](平均值)(尽管吞吐量要高得多)
并再次增加多达 50 个并发请求:
ab -n 1000 -c 50 http://127.0.0.1:8080/users
Concurrency Level: 50
Time taken for tests: 0.277 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 165000 bytes
HTML transferred: 12000 bytes
Requests per second: 3607.35 [#/sec] (mean)
Time per request: 13.861 [ms] (mean)
Time per request: 0.277 [ms] (mean, across all concurrent requests)
Transfer rate: 581.26 [Kbytes/sec] received
这里的延迟非常高,为 13.861 毫秒,而第一种情况为 0.880 毫秒(延迟增加了大约 16 倍)
这个简单的服务器没有阻塞 IO。
我想知道我应该配置什么以保持尽可能低的延迟。