C++ vs Java for server application

Krab picture Krab · Aug 29, 2012 · Viewed 9.3k times · Source

i need to make low latency server, where raw data throughput is less important than the ability to handle thousands of simultaneous connections. I don't know what language to use. Java is simpler, development will be faster, nice interface for all what i need + good support for networking (JAVA NIO and selector class). But actually i don't have much experience with java beside programming, so even if i read things like java isn't today slower then native C/C++, still have some doubts about the performence, because c/c++ is compiled to binary code, but java .class files are interpreted, so there MUST be overhead in that translating.

  • Can someone post his own experience?
  • Have someone low latency app programmed?
  • What you mean is better to use for that type of application?

EDIT: App will be server for support real-time on web applications (like chat, etc.)

Answer

Peter Lawrey picture Peter Lawrey · Aug 29, 2012

Usually people want a low latency application so I don't know what you mean by low latency.

so even if i read things like java isn't today slower then native C/C++

Its still slightly slower, just not enough to matter most of the time.

For example, network IO is network IO regardless of the language you use. e.g. The language won't make your network faster or slower except in the most extreme low latency cases.

, because c/c++ is compiled to binary code, but java .class files are interpreted,

Java is compiled to native code at runtime so both system run native code in the end.

so there MUST be overhead in that translating.

There is a overhead on startup. But once the application is running, the impact is much less.

Have someone high latency app programmed?

If your network has high latency, your language is less likely to matter.

What you mean is better to use for that type of application?

I suggest you use the language you are most comfortable with.

App will be server for support real-time on web applications

In that case, your network latency is likely to be far higher than that of your application if you have coded it properly.


To give you a broad idea, a typical internet connect has a latency of 5 - 20 ms. A typical user can only react with a latency of 50 ms. A server with a latency of 20 - 50 ms can be written in just about any language. A server with a latency of 200 - 500 micro-seconds can be written in Java or C++. If you want less than 100 micro-seconds, including the latency to the client, you are looking at specialist hardware and some C++ code for your core engine. In that case, the server and the consumer will probably be in the same building, if not the same rack.