tyrus
  1. tyrus
  2. TYRUS-133

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

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.3
    • Component/s: None
    • Labels:
      None

      Description

      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);
      }
      

        Issue Links

          Activity

            People

            • Assignee:
              Pavel Bucek
              Reporter:
              oleksiys
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: