It's not a secret anymore!*
The moose likes Performance and the fly likes socket performance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "socket performance" Watch "socket performance" New topic
Author

socket performance

Karthik Anant
Greenhorn

Joined: Nov 02, 2009
Posts: 20
Hi,

I am running a simple socket programming to transmitmessages which is about 500Bytes. Am only able to acieve close to 1000-1200 messages per second despite trying multi threaded clients and running both server and client on the same machine. Can any one please advice me on what I can do to achieve faster rates. My target is 10000 messages per second

below is the basic server program of mine (changing buffer size didnt really help)


William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5


Why are you using a Reader? Readers are for character data and will always consume time trying to change bytes to characters.

If you want bytes, read bytes directly to a byte[] with InputStream

The usual approach, once a server socket has gotten a connection, is to pass that connection to a separate Thread while the first Thread goes back to listening at the server socket.

Bill
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8877
    
    8

Karthik Ananthasubramanian wrote:running both server and client on the same machine.


That's one problem. If you are just interested in the number of connections the server can handle, why are you running the client on the same machine?
How fast is your hardware? Do you have multiple CPU's like a server-class machine should? Have you benchmarked your machine to check for RAM or CPU bottlenecks? Are you running other applications that are stealing valuable CPU cycles from your application?
You do an awful lot of work in the main method before you finally spawn some worker threads. Save that work for the workers. A thread pool may be a good idea too. You know you are going to be receiving connections and need threads to process them. Why wait until there's a client on the line before creating it?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Karthik Anant
Greenhorn

Joined: Nov 02, 2009
Posts: 20
William Brogden wrote:

Why are you using a Reader? Readers are for character data and will always consume time trying to change bytes to characters.



am sorry for the misunderstanding. my requirement is also in character only, i.e., am expecting only inputs in character format which would be around 500 character on average.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
As I said before and Joe suggested, the usual practice is to hand the connectionSocket to your worker class and start its own Thread.

Let the worker do the time consuming stream creation operations while the server socket Thread goes back to listening for another connection.

Watch out for time-out conditions, you don't want Threads waiting infinitely for data that never comes.

Bill
Karthik Anant
Greenhorn

Joined: Nov 02, 2009
Posts: 20
William Brogden wrote:As I said before and Joe suggested, the usual practice is to hand the connectionSocket to your worker class and start its own Thread.


Thanks Bill, that certainly helped. and much more, considerable performance boost came from using a printwriter. as am dealing with chars directly, it certainly saved a lot of time.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: socket performance