我有一个sbt项目:版本:
Versions of akka-actor, akka-stream = 2.4.17
Versions of akka-http-core and akka-http = 10.0.4
这是我如何启动服务器:
system = ActorSystem("my-server", conf)
mat = ActorMaterializer.create(system)
ec = system.dispatcher
httpService = Http().bindAndHandle(routeWithTypeAndLogging(routeType), bindHost, bindPort)
我编写了一个只能在30到60毫秒之间休眠的API,我从jmeter
命中了解:我可以在API上获得多少并发,而不会让客户端面临更高的吞吐量。 API部署在20核34G机器上。 API如下所示:
get {
parameters('dummy') { dummy =>
complete{
Future {
Thread.sleep(30 + randomGenerator.nextInt(30))
GenericResponse(200, Map(), Response("Success"))
}(ioDispatcher)
}
}
}
当我点击此API时,使用来自jmeter的200个线程:我得到以下响应:
summary + 88512 in 00:00:25 = 3522.2/s Avg: 55 Min: 30 Max: 1547 Err: 0 (0.00%) Active: 200 Started: 200 Finished: 0
summary = 88513 in 00:00:25 = 3485.3/s Avg: 55 Min: 30 Max: 1547 Err: 0 (0.00%)
summary + 106546 in 00:00:30 = 3551.5/s Avg: 55 Min: 30 Max: 904 Err: 0 (0.00%) Active: 200 Started: 200 Finished: 0
summary = 195059 in 00:00:55 = 3521.2/s Avg: 55 Min: 30 Max: 1547 Err: 0 (0.00%)
summary + 106825 in 00:00:30 = 3560.8/s Avg: 55 Min: 30 Max: 1127 Err: 0 (0.00%) Active: 200 Started: 200 Finished: 0
summary = 301884 in 00:01:25 = 3535.1/s Avg: 55 Min: 30 Max: 1547 Err: 0 (0.00%)
但是,当我从3台不同的机器中击中时,每台机器200个线程(共600个线程):我得到以下响应:
summary = 98338 in 00:01:22 = 1203.3/s Avg: 163 Min: 30 Max: 10022 Err: 70 (0.07%)
summary + 35672 in 00:00:30 = 1189.1/s Avg: 162 Min: 30 Max: 7944 Err: 0 (0.00%) Active: 200 Started: 200 Finished: 0
summary = 134010 in 00:01:52 = 1199.5/s Avg: 163 Min: 30 Max: 10022 Err: 70 (0.05%)
summary + 35837 in 00:00:30 = 1194.6/s Avg: 173 Min: 30 Max: 9140 Err: 0 (0.00%) Active: 200 Started: 200 Finished: 0
summary = 169847 in 00:02:22 = 1198.5/s Avg: 165 Min: 30 Max: 10022 Err: 70 (0.04%)
summary + 35024 in 00:00:30 = 1167.5/s Avg: 164 Min: 30 Max: 10040 Err: 69 (0.20%) Active: 200 Started: 200 Finished: 0
summary = 204871 in 00:02:52 = 1193.1/s Avg: 165 Min: 30 Max: 10040 Err: 139 (0.07%)
正如你所看到的,在这两种情况下,我都无法获得超过3600qps的速度,但令人担忧的是600线程命中服务器,它也会降级为客户端。
我已将akka.http.server.max-connections
提交给8192,而更改akka.http.server.pipelining-limit
对上述结果没有影响。
将akka-http更新为10.0.11
也没有帮助。
答案 0 :(得分:2)
你的Thread.sleep表现最糟糕。前一段时间,我写了一个Akka-http服务器,你可以配置响应的延迟。使用Futures,向一个actor发送消息并在模式之后使用akka以避免停止线程https://github.com/EmiCareOfCell44/http-retarder/blob/master/src/main/scala/io/ecocell44。看看这个,你告诉我它是否会改善你的实验。
答案 1 :(得分:2)
永远不要将Thread.sleep
与期货一起使用(至少没有正确的ExecutorService)
等待Scheduler.scheduleOnce
与Promise
一起使用(完全未经测试):
get {
parameters('dummy') { dummy =>
complete{
val p = Promise[GenericResponse]()
system.scheduler.scheduleOnce(50 milliseconds) {
p success GenericResponse(200, Map(), Response("Success"))
}
p.future
}
}
}