Skip to content

Commit

Permalink
rename option to CompressionPreparedMessageCacheSize
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia committed May 23, 2024
1 parent 8357fe0 commit e5952c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
15 changes: 7 additions & 8 deletions handler_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions handler_websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit e5952c3

Please sign in to comment.