Re: Best Programming language for Network programming (serious server application
- From: Logan Shaw <lshaw-usenet@xxxxxxxxxxxxx>
- Date: Thu, 24 May 2007 21:23:06 -0500
anup.kalbalia@xxxxxxxxx wrote:
Now for my server, I am confused between java and C/C++. I have heard
that writing networking applications is easier in Java and even as a
whole, writing and maintaining code in Java is much easier. Also
database interaction is a factor here. But performance-wise i m
extremely worried. Some googling told me that Java is no longer slower
than C++ but i m sceptical. They say that JIT compilation (some
dynamic compilation funda) makes java actually faster than C++. Is it
true or just a theory?
Java may in some cases use a bit more CPU to do equivalent things, but
even if that is the case, it is not important. The reason is this:
your bottleneck will not be the CPU usage; instead, it will be the
design of your application. Design decisions like your threading
model (how many context switches, etc.) will make more of a difference
than whether Java uses a little more CPU to get the same work done.
I have tried creating a sample server Java app, which will spawn one
thread for each client socket connection. I tried connecting 5000
client sockets to this blocking server socket and got "Out of Heap
memory" error in Server!
You need to look at the documentation for your JVM. It should have
an option to increase the maximum heap size. This is the limit you
are running into. With the Sun JVM, the option is "-Xmx". For example,
to give your JVM 512 megabytes (maximum) of heap, you would do
"java -Xmx512m" instead of just "java". If you are using a different
JVM, there may be a different method of setting this.
Second, having a thread for each connection is not very efficient.
One of the good things about Java in this area is the capabilities
that java.nio has. It makes it pretty easy and pretty clean to use
a non-blocking I/O model. Then you can have a few threads, perhaps
a number close to the number of CPUs (or CPU cores) you have, and
each of them dealing with many clients. This should result in
better performance.
This was concerning as my server application
is expected to handle a much higher number of client connections.
If you need to handle more than 5000 simultaneous connections,
you are may have to tune the OS as well. I recently tried this
on Linux, and I found that I needed to increase the per-user limit
on open files in order to even have that many sockets open. This
will be an issue no matter what language you use.
Also, you mentioned the client will be using UDP. If that is the
case, then I'm not even sure you need to have a separate socket
for each client. You should be able to have one UDP socket that
sends and receives packets for all the clients. This might
simplify matters.
On the other hand, if you have to talk to a SQL database over a
TCP connection, that is going to make things tricky, because you
will have to wait on the database. That means you probably need
threads to talk to the database since probably you can't control
whether the database calls will block.
- Logan
.
- References:
- Best Programming language for Network programming (serious server application
- From: anup . kalbalia
- Best Programming language for Network programming (serious server application
- Prev by Date: Re: Best Programming language for Network programming (serious server application
- Next by Date: Re: Best Programming language for Network programming (serious server application
- Previous by thread: Re: Best Programming language for Network programming (serious server application
- Next by thread: Re: Best Programming language for Network programming (serious server application
- Index(es):
Relevant Pages
|