开发者

Is it worth implementing C++ code through JNI in this application?

开发者 https://www.devze.com 2023-03-17 01:39 出处:网络
I\'m developing a server application, and would like to harness the flexibility and (possible) speed increases C++ has to offer, by implementing the network code in C++. However, the base application

I'm developing a server application, and would like to harness the flexibility and (possible) speed increases C++ has to offer, by implementing the network code in C++. However, the base application has to be written in Java.

I'm aware of the possible reliability and debugging impact implementing JNI-code might have on the JVM. So I would like to know, would it be worth implementing such behavior in C++, or would the overhead caused simply not make it worth it?

Restriction: writing the application entirely in C++ is not an option.

Edit: I am a skilled (not very, but I can solve mos开发者_StackOverflow中文版t tasks) C++ programmer, and I plan to use a library, do you have any suggestions?

Main criteria:

  1. Speed
  2. Raises the abstraction level
  3. Event dispatched
  4. Asynchronous (I will synchronize the code in Java before calling the C++ functions)

  5. Has support for/is multithreaded)


No, it will not be worth it for the reasons you mentioned (related to overhead) and without getting into any c++/java wars about performance, there wouldn't be enough of it (performance) to impact the throughput of client/server type of calls.

In most client/server type of applications, the movement of data across the network itself and the application level processing will constitute the vast majority of your time. Basically the amount of time spent in the servers network layer will be such a small percentage of the total time that performance benefits won't make enough of a difference.

Whether this balance holds true in your particular case, I cannot say since I don't know the nature of your application, but I would say it is the typical case.


If the application is IO/bound, then optimising the CPU load is unlikely to make a significant difference. JNI itself also has overheads.


I'm fairly certain that writing something as complicated as networking code in C++ instead of Java is going to be very time-consuming unless you have access to people who are already skilled C++ programmers. If this is the kind of thing where you don't know C++ but heard it's faster, you're better off keeping everything in Java and focusing on your implementation.

Performance-wise C++ should be "faster" assuming that you implement any C++ modules in a sane fashion. You'll note that "faster" was in quotes - I don't believe it's likely to make very much difference.

0

精彩评论

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