Netty性能

发布于 2024-10-19 17:55:05 字数 55 浏览 4 评论 0原文

在具有数万个连接的应用程序中使用 Netty 和不使用 Netty 时,性能有什么真正的区别吗?

Is there any real difference to the performance when you use Netty and if you don't use it in an application with tens of thousand of connections?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

[浮城] 2024-10-26 17:55:05

事实并非如此,使用 Netty 的一个很好的理由是提高连接的可靠性,让您对连接的功能进行编码,而不用担心可能出错的所有细节。 (通常只有通过艰难的方式才能找到)

Netty 可以帮助您扩展超过 1K 的连接。但是,如果您不需要这么多连接,您可能会发现简单的代码性能最佳。

Not really, a good reason to use Netty is to improve the reliability of the connections and leave you to code what the connection does rather than worry about the details of everything which can go wrong. (Often only comes by finding out the hard way)

Netty may help you scale over 1K connections. However if you don't need so many connections you might find that simple code performs best.

耶耶耶 2024-10-26 17:55:05

正如彼得指出的那样,事实并非如此。

然而,我发现 Netty 还提供了一个非常好的 API 来构建服务器。尽管 API 有一点学习曲线,但它制作精良,并且创建新服务器可能很简单。它在代码方面也非常高效,因此,如果您有一个简单的协议和实现,那么您将需要很少的代码。

仅当您正在为 HTTP 之外的其他内容构建服务器时,才会出现这种情况。如果您正在谈论 HTTP Web 应用程序,请选择“尝试过”为 true。 Apache 用于直接 HTML 页面,Tomcat 如果您需要 Servlet。

Not really, as Peter noted.

However, I've found that Netty also offers a very nice API for building a server. Although there is a bit of a learning curve to the API, it's well made and creating a new server can be trivial. It's also quite efficient code-wise, so you would have very little code, if you have a simple protocol and implementation.

This is ONLY if you are building a server for something other than HTTP. If you are talking about an HTTP web application, go with the tried an true. Apache for straight HTML pages, Tomcat if you need Servlets.

他是夢罘是命 2024-10-26 17:55:05

HTTP Web 应用程序不一定要转到 apache httpd 和 tomcat:

  1. 检查 这个这个看看如何优越的 nginx 与 apache httpd 相比
  2. 点击此处请参阅 Play!framework(基于 Netty)如何优于基于 Tomcat/Servlet 的框架

HTTP web app is not necessarily go to apache httpd and tomcat:

  1. Check this and this to see how superior nginx is compare to apache httpd
  2. Click here to see How Play!framework (based on Netty) outperforms those based on Tomcat/Servlet
君勿笑 2024-10-26 17:55:05

Netty 非常快,尤其是在连接很多的情况下。

根据我的经验:

  • 它比标准 Java IO 更具可扩展性。特别是,旧的同步 Java IO 包要求您为每个连接绑定一个线程。对于数万个连接来说,这可能会成为问题!
  • 它的速度与使用 Java NIO 编写自定义网络代码的速度大致相同,但是直接使用 Netty 比走这条路要简单得多。

Netty is very fast, especially with many connections.

In my experience:

  • It's more scalable than the standard Java IO. In particular, the old synchronous Java IO packages require you to tie up one thread per connection. This can become problematic with tens of thousands of connections!
  • It's approximately the same speed as what you would get if you wrote custom networking code using Java NIO, but it's a lot simpler to just use Netty directly rather than go down this route.
黑凤梨 2024-10-26 17:55:05

Twitter 在其搜索系统中使用了 Netty:

参考:Twitter 搜索速度现在快了 3 倍< /a>

Twitter used Netty in its Search System:

Ref: Twitter Search is Now 3x Faster

怼怹恏 2024-10-26 17:55:05

实际使用Tomcat NIO,最多可以获得16000个并发连接;请注意,这是一台机器上的并发连接。这是与 Jetty 进行比较的测试,当他们不断给予它们越来越多的内存时,Jetty 的最高值达到 4000。 (http://www.javalobby.org/java/forums/t92965.html

并且使用“约定优于配置”框架(例如具有内置 REST 功能的 Grails)(或简单的插件(例如 RestRPC)),您可以在几秒钟内轻松构建 API、Webhooks 等。

我还可以使用 Spring Security 插件更好地控制谁可以通过什么 IP 或什么角色访问什么 api 调用(如果我愿意)。

Netty 的局限性在于,过多的 Grails 插件可以远远超出使用 Tomcat NIO 的范围。

Actually using Tomcat NIO, you can get up to 16,000 concurrent connections; mind you thats CONCURRENT connections on one machine. This was tested against as a comparison vs Jetty which topped out at 4000 when they kept giving them more and more memory. (http://www.javalobby.org/java/forums/t92965.html)

And using a 'convention over config' framework like Grails with REST functionmality built in (or simple plugins like RestRPC), you can easily build API's, webhooks, etc in seconds.

I also have more control using Spring Security plugin as to who can access what api call via what IP or what role if I want.

Netty has limitations that the plethora of Grails plugins can expand far beyond using Tomcat NIO.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文