diff --git a/handler_websocket.go b/handler_websocket.go index 1b00ed2b..76f15104 100644 --- a/handler_websocket.go +++ b/handler_websocket.go @@ -62,14 +62,13 @@ type WebsocketConfig struct { // WebsocketCompression enabled and compression negotiated with client. CompressionMinSize int - // PreparedMessageCacheMaxSize when greater than zero enables caching of WebSocket prepared - // messages and sets the maximum size of that cache in bytes. When cache is on – Centrifuge - // uses prepared WebSocket messages for connections with compression. This generally - // introduces overhead but at the same time may drastically reduce compression memory - // and CPU spikes during broadcasts. See also BenchmarkWsBroadcastCompressionCache. + // CompressionPreparedMessageCacheSize when greater than zero tells Centrifuge to use + // prepared WebSocket messages for connections with compression. This generally introduces + // overhead but at the same time may drastically reduce compression memory and CPU spikes + // during broadcasts. See also BenchmarkWsBroadcastCompressionCache. // This option is EXPERIMENTAL, do not use in production. Contact maintainers if it // works well for your use case, and you want to enable it in production. - PreparedMessageCacheMaxSize int64 + CompressionPreparedMessageCacheSize int64 PingPongConfig } @@ -104,8 +103,8 @@ func NewWebsocketHandler(node *Node, config WebsocketConfig) *WebsocketHandler { upgrade.CheckOrigin = sameHostOriginCheck(node) } var cache *theine.Cache[string, *websocket.PreparedMessage] - if config.PreparedMessageCacheMaxSize > 0 { - cache, _ = theine.NewBuilder[string, *websocket.PreparedMessage](config.PreparedMessageCacheMaxSize).Build() + if config.CompressionPreparedMessageCacheSize > 0 { + cache, _ = theine.NewBuilder[string, *websocket.PreparedMessage](config.CompressionPreparedMessageCacheSize).Build() } return &WebsocketHandler{ node: node, diff --git a/handler_websocket_test.go b/handler_websocket_test.go index 28401aa5..c3f4252b 100644 --- a/handler_websocket_test.go +++ b/handler_websocket_test.go @@ -825,8 +825,8 @@ func TestWsBroadcastCompressionCache(t *testing.T) { t.Run(testName, func(t *testing.T) { mux := http.NewServeMux() mux.Handle("/connection/websocket", testAuthMiddleware(NewWebsocketHandler(n, WebsocketConfig{ - Compression: true, - PreparedMessageCacheMaxSize: bm.cacheSizeMB * 1024 * 1024, + Compression: true, + CompressionPreparedMessageCacheSize: bm.cacheSizeMB * 1024 * 1024, }))) server := httptest.NewServer(mux) defer server.Close() @@ -881,8 +881,8 @@ func BenchmarkWsBroadcastCompressionCache(b *testing.B) { mux := http.NewServeMux() mux.Handle("/connection/websocket", testAuthMiddleware(NewWebsocketHandler(n, WebsocketConfig{ - Compression: true, - PreparedMessageCacheMaxSize: bm.cacheSizeMB * 1024 * 1024, + Compression: true, + CompressionPreparedMessageCacheSize: bm.cacheSizeMB * 1024 * 1024, }))) server := httptest.NewServer(mux) defer server.Close()