哪个 NIO 库(Netty、Grizzly、kryonet 等)用于 Java 中的简单后端服务器实现?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8269093/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-15 00:28:55  来源:igfitidea点击:

Which NIO library (Netty, Grizzly, kryonet, ...) for simple backend server implementation in Java?

javarminettygrizzlykryonet

提问by Japer D.

Our frontend is simple Jetty (might be replaced with Tomcat later on) server. Through servlets, we are providing a public HTTP API (more or less RESTful) to expose our product functionality.

我们的前端是简单的 Jetty(稍后可能会被 Tomcat 替换)服务器。通过 servlet,我们提供了一个公共 HTTP API(或多或少是 RESTful)来公开我们的产品功能。

In the backend, we have a Java process which does several kind of maintenance tasks. While the backend process usually does it own tasks when it's time, now and then, the frontend needs to wake-up the backend to execute a certain task in the background.

在后端,我们有一个 Java 进程,它执行多种维护任务。虽然后端进程通常在需要的时候执行它自己的任务,但前端需要时不时地唤醒后端以在后台执行某个任务。

Which (N)IO library would be ideal for this task? I found Netty, Grizzly, kryonet and plain RMI. For now, I am inclined to say Netty, it seems simple to use and it is probably very reliable.

哪个 (N)IO 库最适合此任务?我找到了 Netty、Grizzly、kryonet 和普通的 RMI。就目前而言,我倾向于说Netty,它使用起来似乎很简单,而且可能非常可靠。

Does any of you have experience in this kind of setups? What would your choice be?

你们中有人有这种设置的经验吗?你的选择是什么?

thanks!

谢谢!

采纳答案by Sebastien Lorber

Try to translate this document which answer to your question. http://blog.xebia.fr/2011/11/09/java-nio-et-framework-web-haute-performance/

尝试翻译这份文件来回答您的问题。 http://blog.xebia.fr/2011/11/09/java-nio-et-framework-web-haute-performance/

This society, as french famous Java EE experts, did a lot of poc of NIO servers in the context of a french challenge sponsored by VmWare (USI2011). It was about building a simple quizz app that can handle a load of 1 million connected users.

这个社团作为法国著名的Java EE专家,在VmWare赞助的法国挑战赛(USI2011)的背景下,做了很多NIO服务器的poc。这是关于构建一个简单的测验应用程序,可以处理 100 万连接用户的负载。

They won that challenge with great results. Their implementation was Netty + Gemfire and they only replaced the CachedThreadPool by a MemoryAwareThreadPool.

他们以优异的成绩赢得了这项挑战。他们的实现是 Netty + Gemfire,他们只用 MemoryAwareThreadPool 替换了 CachedThreadPool。

Netty seems to offer great performances, and is well documented.

Netty 似乎提供了出色的性能,并且有据可查。

They also considered Deft, inspired by Tornado (python/facebook) but it's still a bit immature for them

他们也考虑过 Deft,受 Tornado (python/facebook) 启发,但对他们来说仍然有点不成熟

Edit:here's the translated linkprovided in the comments

编辑:这是评论中提供的翻译链接

回答by Matt

I would decouple them by using JMS, just have some (set of) control queues your backend sits there listening on and you're done. No need to write a custom nio api here.

我会通过使用 JMS 将它们解耦,只需让您的后端坐在那里监听一些(一组)控制队列,您就完成了。无需在此处编写自定义 nio api。

One sample provider is hornetq. This can be run as an in process jms broker as well, it uses Netty under the covers.

一个示例提供程序是 hornetq。这也可以作为进程中的 jms 代理运行,它在幕后使用 Netty。

回答by Mike Heath

My preference is Netty. It's simple yet flexible. Very fast and the community around Netty is awesome.

我的偏好是 Netty。它简单而灵活。非常快,而且 Netty 周围的社区很棒。

回答by LatencyGuy

The company I work for is currently evaluating CoralReactor. It is a commercial software but it has the easiest API I have ever seen for Java NIO. My personal opinion is that Netty makes things too complicated, especially if you want to go garbage-free and single-threaded, which are a requirement for many companies from the finance, advertisement and game industry.

我工作的公司目前正在评估CoralReactor。它是一个商业软件,但它具有我见过的最简单的 Java NIO API。我个人的看法是,Netty 把事情弄得太复杂了,特别是如果你想要无垃圾和单线程,这是金融、广告和游戏行业的许多公司的要求。