Could not understand the different parameters in the stomp over websocket config I am using for developing a chat application that involves images/vidoes:
I notice that the SockJs in webpage, sends message with a frame size of 16K. I also tested that the message size limit is what determines the max size of message that I can transfer.
Could you please let me know what is:
stream bytes limit
send buffer size limit
http message cache size
What is partial messages and how to use them and are they useful here?
Also I plan on setting the max size of image/video to 2GB and expects about 100 simultaneous users when I release.
Could you please let us know what sizes should I keep and why? What are the defaults? And how each of them would affect the performance of my chat application?
@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);
}
}
Answering question with my findings and implementation:
In the below configuration:
@Override
public void configureWebSocketTransport(WebSocketTransportRegistration registration) {
registration.setSendTimeLimit(60 * 1000)
.setSendBufferSizeLimit(200 * 1024 * 1024)
.setMessageSizeLimit(200 * 1024 * 1024);
}
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;
}
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.
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;
}
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)
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With