Re: Best Programming language for Network programming (serious server application



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
.



Relevant Pages

  • Re: Execute more sql statments in one step.
    ... Before today the update works only for the client binary and not for the database structure. ... It's, for me, more easy to create an unique .sql file which contains all the sql statments needs to modify the database, instead of a lot of files with single sql statments. ... There's no way to connect directly the mysql of the client so i've to do it from java. ...
    (comp.lang.java.databases)
  • Re: Best Programming language for Network programming (serious server application
    ... dump into database and send response back to the ... So the server needs to be a heavily multi-threaded application ... to write my client and server application? ... I m wondering of using java for my client application development as ...
    (comp.programming)
  • Socket & PrintWriter issue-- writing a float to a C client
    ... I have a Java class that opens a socket and connects with a client. ... In a nutshell the java server looks like this: ...
    (comp.lang.java.programmer)
  • Re: connecting to a database
    ... so I'm attempting to code it up in java. ... I have no idea how to set up a connection. ... connection to an Access Database that they would be willing to post. ... sql. ...
    (comp.lang.java.programmer)
  • Stuff the purple heart programmers cook up
    ... C To act like a framework for the JDBC driver developers. ... D To hide the specifics of accessing particular kinds of database ... Topic: Java 2: Survey Author: Chris Mc Devitt ... The JDBC ResultSet is actually an interface java.sql.ResultSet. ...
    (comp.lang.java.programmer)