v3-docs/docs/performance/websocket-compression.md
::: warning Modifying websocket compression settings without understanding your application's DDP messaging patterns can negatively impact performance. Before changing these settings, you should:
Meteor's stream server uses the permessage-deflate extension for websocket compression by default. While compression can help reduce bandwidth usage, it may impact performance in reactivity-intensive applications due to the computational overhead of compressing numerous DDP messages.
You can disable websocket compression by setting the SERVER_WEBSOCKET_COMPRESSION environment variable to false:
SERVER_WEBSOCKET_COMPRESSION=false
To customize compression settings, set SERVER_WEBSOCKET_COMPRESSION to a JSON string with your desired configuration:
# Example with custom settings
SERVER_WEBSOCKET_COMPRESSION='{"threshold": 2048, "level": 1}'
Available configuration options:
threshold: Minimum message size (in bytes) before compression is applied (default: 1024)level: Compression level (0-9, where 0=none, 1=fastest, 9=best compression)memLevel: Memory level (1-9, lower uses less memory)noContextTakeover: When true, compressor resets for each message (default: true)maxWindowBits: Window size for compression (9-15, lower uses less memory)Here are recommended configurations for different types of applications:
For applications with frequent small updates (e.g., real-time dashboards, trading platforms):
# Disable compression for optimal performance with small, frequent updates
SERVER_WEBSOCKET_COMPRESSION=false
For applications transferring large datasets (e.g., file sharing, data visualization):
# Optimize for large data transfers
SERVER_WEBSOCKET_COMPRESSION='{"threshold": 1024, "level": 6, "memLevel": 8}'
For deployments with limited memory resources:
# Minimize memory usage while maintaining compression
SERVER_WEBSOCKET_COMPRESSION='{"threshold": 2048, "level": 1, "memLevel": 1, "maxWindowBits": 9}'
For typical applications with mixed message sizes:
# Balance between compression and performance
SERVER_WEBSOCKET_COMPRESSION='{"threshold": 1536, "level": 3, "memLevel": 4}'
You can check if compression is enabled through the Meteor shell:
Meteor.server.stream_server.server.options.faye_server_options.extensions
Results interpretation:
[] (empty array): Compression is disabled[{}] (array with object): Compression is enabledWhen enabled, the default configuration uses: