我现在正在调整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.861ms,而第一例的等待时间为0.880ms(等待时间增加了16倍)
这个简单的服务器没有阻塞IO。
我想知道我应该配置什么以保持尽可能低的延迟。
答案 0 :(得分:0)
间接答案
检查akka-http-quickstart-scala.g8
source code显示,所有并发的GET
请求都在查询Actor
以获取Users
:
get {
val users: Future[Users] =
(userRegistryActor ? GetUsers).mapTo[Users]
complete(users)
}
因此,所有发送到Actor的GetUsers
请求都在邮箱中排队,并且Actor对其进行1比1处理。因此,所有并发连接都是串行同步而不是并发处理。
尽管某些配置可以在您的特定计算机上微调ActorSystem
的性能,但是并不能避免该特定项目的设计并非旨在最大程度地减少多次并行读取的延迟。
要获得所需的性能类型,必须使用ReadWriteLock
之类的东西重新设计该项目。
直接回答
要使特定硬件的性能最大化,您必须调整http configurations和actor system configuration。