Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] WebSocket message batching in 9.2.3

Just a follow up on this (would still love some authoritative input).

Setting BatchMode.OFF was not sufficient. Messages still appeared to be occasionally getting batched.
I am now also calling RemoteEndPoint.flush() after each send and so far I haven't noticed any batching, nor any performance degrade.

What's the difference between setting BatchMode.OFF and calling flush() after each send?
Shouldn't they be equivalent?


On Sat, Mar 21, 2015 at 4:58 PM, William Ferguson <william.ferguson@xxxxxxxxxxxxx> wrote:
More a query than anything else.

I am using Jetty-9.2.3 to co-ordinate a bit over a dozen mobile devices on a local wi-fi network using WebSockets.
I have wrapped the WebSockets in a ReliableSender so that if the client doesn't acknowledge a message within 500ms the server sends it again until it times out after 5 retries.

Most of the time it works OK, but I am seeing instances where the server sends a message to a client, doesn't get an ACK, so resends, and keeps resending every 500ms (times as recorded by the logging in the code shown below) until it times out after 2.5 seconds. But looking at the client log the client receives the first message more than 2.5 seconds after the server claims to have sent it. And then the client receives all the resends within the next 50ms. So it appears that the messages may have been batched.

The sends on the server never take more that one milli. This is the code I am using.
final long currentTime = System.currentTimeMillis();
getRemote().sendString(outboundTextMessage, new WriteCallback() {
public void writeFailed(Throwable e) {
log.debug("#sendMessage could not send remote=" + getRemoteClientDescription() + " message=" + message, e);

public void writeSuccess() {
final long elapsedTime = System.currentTimeMillis() - currentTime;
log.debug((isResend ? "#resendMessage" : "#sendMessage") + " remote=" + getRemoteClientDescription() + " message=" + message + " msToSend=" + elapsedTime);

Could this be because the messages are getting batched by Jetty's WebSocket implementation?
This would mean that the batching is done AFTER writeSuccess(), correct?

How do I ensure that batching doesn't occur? And what would be the cost of adopting that approach?

Should I flush after each send?

Or should I configure the RemoteEndPoint#setBatchMode(BatchMode.OFF)?


Back to the top