Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

socket performance

 
Karthik Anant
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 9299
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Karthik Anant
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic