开发者

Will I benefit in terms of memory and speed with JNI?

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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜