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

时间:2016-06-18 10:05:13

标签: java spring stomp spring-websocket sockjs

无法理解我在用于开发涉及图像/视频的聊天应用程序的websocket配置中的不同参数:

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

你可以告诉我这是什么:

  1. stream bytes limit

  2. 发送缓冲区大小限制

  3. http消息缓存大小

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

  5. 此外,我计划将图片/视频的最大尺寸设置为2GB,并在发布时预计会有大约100个并发用户。

  6. 请您告诉我们应该保留哪些尺寸以及为什么?什么是默认值?以及它们每个如何影响我的聊天应用程序的性能?

    @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 个答案:

答案 0 :(得分:8)

回答我的调查结果和实施问题:

在以下配置中:

@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. 此外,我计划将图像/视频的最大尺寸设置为2GB,并在发布时预计大约100个并发用户。 =&GT;由messageSizeLimit设置 并使用HTTP进行文件上传/流媒体下载。还使用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;
    

    }