Spring 超越 Websocket:Message/Buffer/Cache/Stream 限制

Spring Stomp over Websocket: Message/Buffer/Cache/Stream limits

无法理解我用于开发涉及 images/vidoes:

的聊天应用程序的 stomp over websocket 配置中的不同参数

我注意到网页中的SockJs,发送帧大小为16K的消息。我还测试了消息大小限制决定了我可以传输的最大消息大小。

你能告诉我什么是:

  1. 流字节限制

  2. 发送缓冲区大小限制

  3. http 消息缓存大小

  4. 什么是部分消息,如何使用它们,它们在这里有用吗?

  5. 我还计划将 image/video 的最大大小设置为 2GB,并预计在我发布时大约有 100 个并发用户。

能否请您告诉我们我应该保留什么尺寸以及为什么?默认值是多少?他们每个人将如何影响我的聊天应用程序的性能?

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
    registry.addEndpoint("/stomp").withSockJS()
            .setStreamBytesLimit(15 * 1024)
            .setHttpMessageCacheSize(15 * 1024);
}

@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
    registry.enableSimpleBroker("/queue/", "/topic/", "/exchange/");
    registry.setApplicationDestinationPrefixes("/app");
}

@Override
public void configureWebSocketTransport(WebSocketTransportRegistration registration) {
    registration.setSendTimeLimit(15 * 1000)
            .setSendBufferSizeLimit(1 * 1024)
            // max message size 2GB (2048 bytes) : default is 64KB
            .setMessageSizeLimit(2 * 1024 * 1024);
}

}

用我的发现和实施回答问题:

在以下配置中:

@Override
public void configureWebSocketTransport(WebSocketTransportRegistration registration) {
    registration.setSendTimeLimit(60 * 1000)
            .setSendBufferSizeLimit(200 * 1024 * 1024)
            .setMessageSizeLimit(200 * 1024 * 1024);
}
  1. 流字节限制:来自源的信息

    /**
     * Streaming transports save responses on the client side and don't free
     * memory used by delivered messages. Such transports need to recycle the
     * connection once in a while. This property sets a minimum number of bytes
     * that can be send over a single HTTP streaming request before it will be
     * closed. After that client will open a new request. Setting this value to
     * one effectively disables streaming and will make streaming transports to
     * behave like polling transports.
     * <p>The default value is 128K (i.e. 128 * 1024).
     */
    public SockJsServiceRegistration setStreamBytesLimit(int streamBytesLimit) {
        this.streamBytesLimit = streamBytesLimit;
        return this;
    }
    
  2. 发送缓冲区大小限制 默认为 512KB。如果消息发送缓慢,后续消息将被缓冲,直到达到 sendTimeLimit 或 sendBufferSizeLimit。

  3. http 消息缓存大小:来自源的信息

    /**
     * The number of server-to-client messages that a session can cache while waiting for
     * the next HTTP polling request from the client. All HTTP transports use this
     * property since even streaming transports recycle HTTP requests periodically.
     * <p>The amount of time between HTTP requests should be relatively brief and will not
     * exceed the allows disconnect delay (see
     * {@link #setDisconnectDelay(long)}), 5 seconds by default.
     * <p>The default size is 100.
     */
    public SockJsServiceRegistration setHttpMessageCacheSize(int httpMessageCacheSize) {
        this.httpMessageCacheSize = httpMessageCacheSize;
        return this;
    }
    
  4. 什么是部分消息,如何使用它们,它们在这里有用吗? 仍然不确定如何通过 websocket 传输大文件并使用部分消息传递(决定改用 HTTP)

  5. 我还计划将 image/video 的最大大小设置为 2GB,预计在我发布时大约有 100 个并发用户。 => 由 messageSizeLimit 设置 并使用 HTTP 进行文件上传/流式下载。还使用 apache 文件上传配置设置服务器限制:

    //set up the server limits using apache file-upload config
    @Bean
    public CommonsMultipartResolver multipartResolver() {
        CommonsMultipartResolver resolver = new CommonsMultipartResolver();
        resolver.setMaxUploadSize(2 * 1024 * 1024 * 1024); // 2 GB limit set for file upload
        resolver.setDefaultEncoding("utf-8");
        return resolver;
        }