簡體   English   中英

Spring Stomp over Websocket:消息/緩沖區/緩存/流限制

[英]Spring Stomp over Websocket: Message/Buffer/Cache/Stream limits

無法理解我在用於開發涉及圖像/視頻的聊天應用程序的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);
}

}

用我的發現和實施回答問題:

在以下配置中:

@Override
public void configureWebSocketTransport(WebSocketTransportRegistration registration) {
    registration.setSendTimeLimit(60 * 1000)
            .setSendBufferSizeLimit(200 * 1024 * 1024)
            .setMessageSizeLimit(200 * 1024 * 1024);
}
  1. stream bytes limit:來自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 (ie 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個並發用戶。 =>由messageSizeLimit設置並使用HTTP進行文件上傳/流式下載。 還使用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; } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM