在Play 2.6.x之前,Play默认使用Netty服务后端。 而到了2.6.x,默认服务后端换成了Akka HTTP, 但还是可以通过手动选择Netty服务后端。想升级到2.6.x,就需要注意到这一点了。因为Akka HTTP服务器要比Netty HTTP服务器慢。所以如果对性能特别敏感,升级完就需要手动选择Netty服务后端。
至于为什么会选择性能有所下降的Akka HTTP服务后端,Play项目的Tech Leader Greg Methvin在Google网上论坛给了一些解释。
Hi everyone,
Why is Play switching to Akka HTTP as the default server?
Play is switching for a few reasons. Play already uses Akka and Akka streams internally, and the model Akka HTTP uses for representing requests and responses is much closer to Play's. Some of the improvements we plan to make in 3.0 will bring them closer together. We are optimistic about the Akka HTTP project and where it's headed in terms of features and performance.
While both Netty and Play are active projects, it's much easier for us to work with the Akka team. This is in part due to shared philosophy and goals but also due to the fact that both teams work for Lightbend. This improved communication will help us implement new features and fix bugs and security issues more quickly.
What's the difference in performance?
Currently we have done no optimization, so the Akka server on 2.6.0-M1 is actually slower than the Netty server. This is expected. We are working with the Akka team to bring the performance to the same level, or hopefully better. You should see the improvements on
prune as we continue this work.
Our contributor Christian Schmitt also published a
gist with nice benchmarks showing akka-http performance (without Play) actually exceeds that of play-netty-server in his test case, in terms of both latency and bytes transferred. Based on this and similar benchmarks we have done, we expect to see comparable performance to Netty once we've removed the unnecessary overhead introduced in the conversion between Play and Akka HTTP models.
Does Play still support the Netty server backend?
Yes. We will continue supporting both Netty and Akka HTTP backends for the foreseeable future, but will prioritize new features on Akka HTTP.
If you want to switch back to the Netty server, please see the
Netty server documentation.
What about HTTP/2?
HTTP/2 is coming as part of the improvements being made to the Akka HTTP server and will be included in a future milestone. We are interested in implementing it on Netty as well, but it's not a priority for the 2.6.0 release. We'd gladly accept contributions from the community, though.