使用 JNI 会在内存和速度方面受益吗?

发布于 2024-11-03 00:57:57 字数 148 浏览 2 评论 0原文

我正在用 Java 构建一个游戏服务器。网络将由 JBoss Netty 处理,我认为如果我使用 JNI 调用 C++ 函数,我可以获得一点额外的性能和内存效率,这些函数只是汇编代码的包装器(用 NASM 组装),因此 I/O 操作将完成汇编以及处理大量数据。这种方法有什么好处吗?

I am building a game server in Java. The networking will be handled by JBoss Netty, and I thought I could gain a little extra performance and memory effeciency if I use JNI to call C++ functions which are just wrappers for Assembly code (assembled with NASM) so I/O operations would be done in Assembly, as well as handling large amounts of data. Is there any kind of gain to this approach?

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

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

发布评论

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

评论(2

甩你一脸翔 2024-11-10 00:57:57

I/O 功能受到操作系统的瓶颈,而汇编将不会加速 I/O。一般来说,切换到 C++ 或切换到任何较低级语言也不会。

如果您想提高性能,请尝试避免 I/O。

I/O functions are bottleneck'ed by the OS, and assembly will not speed up I/O. Neither does switching to C++ or switching to any lower-level language in general.

If you want to improve performance, try avoiding I/O.

溺深海 2024-11-10 00:57:57

这是根据具体情况而定的。如果在 I/O 之间涉及大量计算/进程/内存访问,而 Java 的实现效率低于 C++,那么是的,您肯定会获得性能提升。在很多情况下,这是事实。

但请仔细考虑性能增益是否超过了调试特定进程的能力。如果问题发生在 JNI 调用中,则很难查明问题出在哪里。

通常,对于服务器来说,更重要的是能够判断问题所在并解决它,而不是在提高性能方面走极端,因为与客户端不同,服务器性能也可以通过额外的硬件(更快的组件、集群等)轻松获得-side 程序,您经常被默认硬件困住。

This is case to case basis. If in between I/O it involves huge amount of computations / processes / memory access that Java has less efficient implementation than C++ then YES you will definitely have performance gains. In many cases, this is true.

But think carefully if performance gain outweighs your ability to debug that certain process. It will be very hard to pinpoint where the problem is if it occurs inside your JNI call.

Usually with servers it is more important to be able to tell what's the problem and fix it rather than go to the extremes in pushing the performance, since server performance can also be gained easily by additional hardware (faster components, clustering, etc) unlike client-side programs where you are often stuck with a default hardware.

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