使 WebSocket 发送非阻塞
Make WebSocket sending non-blocking
Jetty 使用 org.eclipse.jetty.websocket.common.BlockingWriteCallback 通过 websocket 发送消息。如果客户端是 "slow",则此阻塞写入可能会挂起(例如,参见此处 https://github.com/eclipse/jetty.project/issues/272#issuecomment-290910610)
我使用 Jetty+Spring+Spring 的 Websocket 客户端成功模拟了慢速客户端。
我想 "send and forget" websocket 消息,因此如果客户端速度很慢(对于它尝试做的任何确认),这不会影响 BrokerWriteCallback 的解析。使用 Jetty 实现该目标的最佳方法是什么(配置或源代码编辑?)
当前 Jetty 版本 9.3.11.v20160721 与 Spring 4.3.3.
一起使用
Jetty 已经进行了 slow server and slow client 次测试。
没有 "send and forget" 这样的东西,因为它意味着无限缓冲。
有非阻塞发送选项,但强烈鼓励您注意Futures
或Callbacks
以了解本地是否端点已成功发送该消息(或未成功)。
Hint: don't send another message to a RemoteEndpoint if the prior one hasn't succeeded yet (you have network congestion decisions to deal with).
不注意Futures
或Callbacks
会触发内存错误(OOM)。
- void sendBytes(ByteBuffer 数据,WriteCallback 回调)
- 未来sendBytesByFuture(字节缓冲区数据)
- void sendString(字符串文本,WriteCallback 回调)
- 未来 sendStringByFuture(字符串文本)
如果所有这些看起来让人难以承受,请考虑使用构建在 websocket 之上的众多库之一来管理所有这些。
我鼓励您查看开源项目 cometd.org
Jetty 使用 org.eclipse.jetty.websocket.common.BlockingWriteCallback 通过 websocket 发送消息。如果客户端是 "slow",则此阻塞写入可能会挂起(例如,参见此处 https://github.com/eclipse/jetty.project/issues/272#issuecomment-290910610)
我使用 Jetty+Spring+Spring 的 Websocket 客户端成功模拟了慢速客户端。
我想 "send and forget" websocket 消息,因此如果客户端速度很慢(对于它尝试做的任何确认),这不会影响 BrokerWriteCallback 的解析。使用 Jetty 实现该目标的最佳方法是什么(配置或源代码编辑?)
当前 Jetty 版本 9.3.11.v20160721 与 Spring 4.3.3.
一起使用Jetty 已经进行了 slow server and slow client 次测试。
没有 "send and forget" 这样的东西,因为它意味着无限缓冲。
有非阻塞发送选项,但强烈鼓励您注意Futures
或Callbacks
以了解本地是否端点已成功发送该消息(或未成功)。
Hint: don't send another message to a RemoteEndpoint if the prior one hasn't succeeded yet (you have network congestion decisions to deal with).
不注意Futures
或Callbacks
会触发内存错误(OOM)。
- void sendBytes(ByteBuffer 数据,WriteCallback 回调)
- 未来sendBytesByFuture(字节缓冲区数据)
- void sendString(字符串文本,WriteCallback 回调)
- 未来 sendStringByFuture(字符串文本)
如果所有这些看起来让人难以承受,请考虑使用构建在 websocket 之上的众多库之一来管理所有这些。
我鼓励您查看开源项目 cometd.org