Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Could you please give me a tip?

I have Java websocket server. I wrote a client that can open many connections and send messages etc.
How can I find a bottleneck in the sense of latency (time between sending a request to server and receiving a response?

Everything what I have is a measuring of latency from client side and I can monitor CPU, heap usage from server side.

What I have tried:

Tried to find something on the internet
Posted
Updated 20-May-20 13:25pm

1 solution

It's hard to answer based on this description.

If you've written a client that tries to behave like many clients, it really isn't a client. And if it's running on the same system as the server, it will obviously interfere with it.

With regard to an isolated server, what affects latency?

1. How long it takes the network layer (part of the platform and therefore outside your control) to react to an incoming packet.
2. How long the I/O thread that services sockets (I'm guessing TCP here) has to wait before it gets to run, given that it contends with other threads.
3. How many sockets have events. The I/O thread has to handle each one, so some will get handled earlier than others. The thread should turn each client's stream into a series of work items and queue them for a worker thread instead of processing them itself.
4. How long a work item sits on a work queue before it gets processed. The worker thread that handles it can send a response directly to the client.

That's about the best you can do. You can timestamp a work item when it gets created and queued, so that you can see how long it waited before a worker thread handled it, and you can gather statistics from this. You can also look at CPU usage to see if the server is getting overloaded (100% CPU usage). Heap usage is unlikely to be a factor except that the busier the server, the busier the garbage collector.

Maybe I've wasted time here, because I'm assuming you can modify the server. If it's some black-box code, then it should provide the kinds of statistics I'm talking about if it's something other than a toy demo.

Edit: Nothing here is really a "bottleneck" until the server is running at 100% CPU usage. At that point, it's a question of streamlining the code. Also, if work from clients can be classified as either "new" or "progress", then the server can implement an overload control policy that rejects (or just silently throws away) new work in order to maintain good service to clients that have already been accepted.
 
Share this answer
 
v4
Comments
Member 13702159 20-May-20 19:49pm    
"If you've written a client that tries to behave like many clients, it really isn't a client. And if it's running on the same system as the server, it will obviously interfere with it." - it is not running on the same system, it is different computer.

Heap cannot be a factor? when I run many thread, the chart of heap usage looks like a very dense sawtooth wave.

"Nothing here is really a "bottleneck" until the server is running at 100% CPU usage" - could you elaborate on this ?
Greg Utas 20-May-20 20:12pm    
Yes, the heap will look like a sawtooth wave because of garbage collection.

If there is CPU time to spare on the server, then how could there be a bottleneck? The exception would be a server that is, say, disk-bound, waiting for disk reads (of images, for example) to complete.
Member 13702159 21-May-20 12:56pm    
"Yes, the heap will look like a sawtooth wave because of garbage collection." - I know but when garbage collector algorithm is executing it absorbs CPU, isnt?
When GC is called often then it can imply latency with processing of right data. Am I right ?
Greg Utas 21-May-20 14:54pm    
Yes, GC uses CPU time, and usually more if the system is busy. So you're right, it affects latency. Which is why serious servers don't use it. But there's little you can do about it.
Member 13702159 21-May-20 17:00pm    
"Which is why serious servers don't use it" hmm, no GC?
so what instead of GC ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900