Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OOM error on jetty websocket async write #1410

Closed
neeraj20gupta opened this issue Mar 19, 2017 · 1 comment
Closed

OOM error on jetty websocket async write #1410

neeraj20gupta opened this issue Mar 19, 2017 · 1 comment

Comments

@neeraj20gupta
Copy link

I have written a websocket application using jetty in which the server send Json frames on the connected websocket clients.

For better performance I am using async Send string method.

session.getRemote().sendString(message, writecallback)
For my connected 200 clients I see OOM error after sending data(approximately 500 records per second) for 20-25 mins.

Following is the trace

    java.lang.OutOfMemoryError: GC overhead limit exceeded
            at java.lang.StringCoding.encode(StringCoding.java:350)
            at java.lang.String.getBytes(String.java:929)
            at org.eclipse.jetty.util.StringUtil.getUtf8Bytes(StringUtil.java:561)
            at org.eclipse.jetty.websocket.common.frames.TextFrame.setPayload(TextFrame.java:44)
            at org.eclipse.jetty.websocket.common.WebSocketRemoteEndpoint.sendString(WebSocketRemoteEndpoint.java:426)

Jetty Version :- 9.4.0.v20161208. Heap Size :- 16 GB(both min and max). Default GC setting of JDK 1.8
The OOM is not happening when I use blocking SendString()
Is this a bug with jetty or incorrect usage of async write?
Thanks in advance :)

@joakime
Copy link
Contributor

joakime commented Mar 19, 2017

Incorrect usage of async write.

Async write will write when it can, you can't keep shoving content at the endpoint, having Jetty queue messages infinitely.

You have to pay attention to return on the Future, or use the Callback to identify when a message has been send (and more importantly, if it hasn't been sent after a certain amount of time).

Don't send messages to slow endpoints, drop messages if you can, enqueue messages on your application for when the prior write has completed.

This is can get rather complicated, and you'll probably want to use one of the many libraries built on top of WebSockets to handle this kind of messaging. (cometd is our go-to)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants