Server-side WebSocket frame ordering

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Server-side WebSocket frame ordering

coudy
I'm trying to process WS frames in incoming order per socket and am a bit
stuck.

My `@OnWebSocketMessage` handler gets dispatched on various threads out of
the Jetty server thread pool, which seems to be used for all manner of
things, so I can't simply configure that to have one thread.

As such it doesn't look like per-socket (per-session) threading is
configurable. Since messaging ordering in WS is obviously derived from TCP's
the lack of configurability is extremely surprising. I hope I'm just missing
something.

Many thanks for any pointers.



--
Sent from: http://jetty.4.x6.nabble.com/Jetty-User-f3247280.html
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Server-side WebSocket frame ordering

Joakim Erdfelt-8
@OnWebSocketMessage is a Jetty API for whole message delivery of websocket messages.

The internals of Jetty will aggregate the individual frames and then call your method with the entire message.

For WebSocket frames access, don't use annotations, and instead use the org.eclipse.jetty.websocket.api.WebSocketFrameListener.

The only scenario where @OnWebSocketMessage method will be called from different threads is if you are using a streaming based approach to handling.
For each websocket message, the first frame will result in a dispatched @OnWebSocketMessage to you.
Each dispatch will be on a new thread, this is to allow your websocket application the opportunity to read the websocket message via the java.io Stream APIs.
When the message is finished (fin=true frame received), then the final payload is delivered to your prior dispatched thread and a new message is allowed to be started.

To avoid this dispatch, use String (for websocket TEXT messages) or ByteBuffer (for websocket BINARY messages) object types in your @OnWebSocketMessage method, not streams.
Those are delivered to your application's @OnWebSocketMessage in the same thread as the one managing the reads operations from the internal websocket connection.


Joakim Erdfelt / [hidden email]

On Wed, Jan 10, 2018 at 5:48 PM, coudy <[hidden email]> wrote:
I'm trying to process WS frames in incoming order per socket and am a bit
stuck.

My `@OnWebSocketMessage` handler gets dispatched on various threads out of
the Jetty server thread pool, which seems to be used for all manner of
things, so I can't simply configure that to have one thread.

As such it doesn't look like per-socket (per-session) threading is
configurable. Since messaging ordering in WS is obviously derived from TCP's
the lack of configurability is extremely surprising. I hope I'm just missing
something.

Many thanks for any pointers.



--
Sent from: http://jetty.4.x6.nabble.com/Jetty-User-f3247280.html
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Server-side WebSocket frame ordering

Simone Bordet-3
In reply to this post by coudy
Hi,

On Thu, Jan 11, 2018 at 12:48 AM, coudy <[hidden email]> wrote:
> As such it doesn't look like per-socket (per-session) threading is
> configurable.

I'm interested in knowing why would that be desirable for you ?

--
Simone Bordet
----
http://cometd.org
http://webtide.com
Developer advice, training, services and support
from the Jetty & CometD experts.
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Server-side WebSocket frame ordering

coudy
In reply to this post by Joakim Erdfelt-8
Joakim, that's a really good explanation, everything makes sense now. Yes, I'm using streaming for both text and binary messages. FYI, I mentioned frames but really meant messages, I don't do any fragmentation in my protocol anyway.

On Wed, 10 Jan 2018 at 23:58 Joakim Erdfelt <[hidden email]> wrote:
@OnWebSocketMessage is a Jetty API for whole message delivery of websocket messages.

The internals of Jetty will aggregate the individual frames and then call your method with the entire message.

For WebSocket frames access, don't use annotations, and instead use the org.eclipse.jetty.websocket.api.WebSocketFrameListener.

The only scenario where @OnWebSocketMessage method will be called from different threads is if you are using a streaming based approach to handling.
For each websocket message, the first frame will result in a dispatched @OnWebSocketMessage to you.
Each dispatch will be on a new thread, this is to allow your websocket application the opportunity to read the websocket message via the java.io Stream APIs.
When the message is finished (fin=true frame received), then the final payload is delivered to your prior dispatched thread and a new message is allowed to be started.

To avoid this dispatch, use String (for websocket TEXT messages) or ByteBuffer (for websocket BINARY messages) object types in your @OnWebSocketMessage method, not streams.
Those are delivered to your application's @OnWebSocketMessage in the same thread as the one managing the reads operations from the internal websocket connection.


Joakim Erdfelt / [hidden email]

On Wed, Jan 10, 2018 at 5:48 PM, coudy <[hidden email]> wrote:
I'm trying to process WS frames in incoming order per socket and am a bit
stuck.

My `@OnWebSocketMessage` handler gets dispatched on various threads out of
the Jetty server thread pool, which seems to be used for all manner of
things, so I can't simply configure that to have one thread.

As such it doesn't look like per-socket (per-session) threading is
configurable. Since messaging ordering in WS is obviously derived from TCP's
the lack of configurability is extremely surprising. I hope I'm just missing
something.

Many thanks for any pointers.



--
Sent from: http://jetty.4.x6.nabble.com/Jetty-User-f3247280.html
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Server-side WebSocket frame ordering

coudy
In reply to this post by Simone Bordet-3
I'm specifically interested in processing messages in incoming order. There are several reasons I can think of to do with managing state associated with the socket, e.g. in my protocol you send an authentication message, which doesn't require a response, followed by request that relies on said authentication.

On Thu, 11 Jan 2018 at 00:03 Simone Bordet <[hidden email]> wrote:
Hi,

On Thu, Jan 11, 2018 at 12:48 AM, coudy <[hidden email]> wrote:
> As such it doesn't look like per-socket (per-session) threading is
> configurable.

I'm interested in knowing why would that be desirable for you ?

--
Simone Bordet
----
http://cometd.org
http://webtide.com
Developer advice, training, services and support
from the Jetty & CometD experts.
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users