Spring Stomp通过Websocket:消息/缓冲区/缓存/流限制

6

我正在开发一个涉及图像/视频的聊天应用程序,但无法理解我使用的stomp over websocket配置中的不同参数:

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

请告诉我以下内容:

  1. 流字节限制

  2. 发送缓冲区大小限制

  3. http消息缓存大小

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

  5. 此外,我计划将图像/视频的最大大小设置为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);
}

}

1个回答

9

根据我的发现和实施,回答以下问题:

在以下配置中:

@Override
public void configureWebSocketTransport(WebSocketTransportRegistration registration) {
    registration.setSendTimeLimit(60 * 1000)
            .setSendBufferSizeLimit(200 * 1024 * 1024)
            .setMessageSizeLimit(200 * 1024 * 1024);
}
  1. stream bytes limit : info from source

    /**
     * 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. send buffer size limit default is 512KB. If message sending is slow, subsequent messages are buffered until either the sendTimeLimit or the sendBufferSizeLimit are reached.

  3. http message cache size: info from source

    /**
     * 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. What is partial messages and how to use them and are they useful here? Still not sure how to stream large files over websocket and use partial messaging (decided to use HTTP for that instead)

  5. Also I plan on setting the max size of image/video to 2GB and expects about 100 simultaneous users when I release. => set by messageSizeLimit and used HTTP to do file uploads/ streaming downloads. Also set up the server limits using apache file-upload config:

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

如何配置SockJsServiceRegistration?(您能提供获取和配置它的代码吗?只是新的SockJsServiceRegistration?) - gstackoverflow

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接