Issue Details (XML | Word | Printable)

Key: TYRUS-133
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Pavel Bucek
Reporter: oleksiys
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
tyrus

Some Broadcast(er) API is needed in order to opmtimize chat-like usecases

Created: 12/Mar/13 07:08 PM   Updated: 03/Sep/13 01:17 PM   Resolved: 03/Sep/13 01:15 PM
Component/s: None
Affects Version/s: None
Fix Version/s: 1.3

Time Tracking:
Not Specified

Issue Links:
Related
 

Tags:
Participants: oleksiys and Pavel Bucek


 Description  « Hide

Currently there is no broadcast API so when we want to send the same message (usually a String) to a different clients we do something like:

String message = "somemessage";
for (Session nextSession : connections.values()) {
     RemoteEndpoint.Basic remote = nextSession.getBasicRemote();
     remote.sendText(message);
}

so for each sendText call we transform message to UTF-8 byte[] representation, wrap it to a websocket frame and send it on wire. All these operations are not that cheap (especially UTF-8 transformation, which includes CharsetEncoder creation and actual transformation), so when we have 1000+ client we do the transformation 1000+ times.

With the Broadcast(er) API we'd be able to optimize this process. So user will call something like:

broadcaster.broadcast(message, connections);

and our Broadcaster will be able to make required String -> raw byte[] transformation just once and use the result byte[] to send it to each client.

byte[] rawData = SomeWebSocketTransformer.transform(message);
for (Session nextSession : connections.values()) {
      sendRawData(nextSession, rawData);
}


No work has yet been logged on this issue.