-
Type: New Feature
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Component/s: None
-
None
MongoDB 3.4:
- Enable compression with
mongod --networkMessageCompressors snappy
- Only supports snappy and noop
- Compresses all responses if a supported compressor was provided in the initial isMaster (including the initial response to the isMaster!), irregardless if the request was compressed or not
- It will compress using the first compressor configured in --networkMessageCompressors snappy,noop that was also present in the isMaster response
MongoDB 3.5-current-RC:
- Adds support for zlib
- snappy enabled by default (no need for --networkMessageCompressors)
- To enable zlib or noop, use --networkMessageCompressors (remember to include snappy in the list if desired)
- Compresses the response if the request was compressed. uses the first compressor configured in the --networkMessageCompressors (defaults to snappy if none provided) that was also present in the isMaster response
MongoDB 3.6:
- Probably, maybe, will only compress responses using the same compressor as the request
- Probably, maybe, adds zlib to its default --networkMessageCompressors, making the default value snappy,zlib
OP_COMPRESSED
struct OP_COMPRESSED { struct MsgHeader { int32 messageLength; int32 requestID; int32 responseTo; int32 opCode = 2012; }; int32_t originalOpcode; int32_t uncompressedSize; uint8_t compressorId; char *compressedMessage; };
originalOpcode | Contains the value of the wrapped opcode. |
uncompressedSize | The size of the deflated compressedMessage, which excludes the MsgHeader |
compressorId | The ID of the compressor that compressed the message |
compressedMessage | The opcode itself, excluding the MsgHeader |
Currently supported/defined compressorIds are:
compressorId | isMaster value | Description |
---|---|---|
0 | noop | The content of the message is uncompressed. Testing Only |
1 | snappy | The content of the message is compressed using snappy |
2 | zlib | The content of the message is compressed using zlib |
3-255 | reserved | Reserved for future used |
Negotiation / handshake
Compression is negotiated during the MongoDB Handshake:
{ isMaster: 1, client: {}, /* See MongoDB Handshake */ compression: ["snappy", "zlib"] }
New Connection String Options
compressors | Comma separated values. Must warn when given unsupported compressor |
zlibCompressionLevel | Integer values for -1 to 9 |
zlibCompressionLevel meaning (informative, this is how zlib defines them)
-1 | Default Compression (usually 6) |
0 | No compression |
1 | Best Speed |
9 | Best Compression |
Blacklisted commands
The following commands MUST NOT be compressed:
- isMaster
- saslStart
- saslContinue
- getnonce
- authenticate
- createUser
- updateUser
- copydbSaslStart
- copydbgetnonce
- copydb
- depends on
-
CDRIVER-2116 Add support for OP_COMPRESSED
- Development Complete
-
CSHARP-1991 Add support for OP_COMPRESSED
- Closed
-
CXX-1356 Add support for reading and writing OP_COMPRESSED
- Closed
-
GODRIVER-20 Implement Compression Specification
- Closed
-
GODRIVER-49 Add support for reading and writing OP_COMPRESSED
- Closed
-
JAVA-2527 OP_COMPRESSED support
- Closed
-
MOTOR-162 Add support for reading and writing OP_COMPRESSED
- Closed
-
NODE-1018 Add support for reading and writing OP_COMPRESSED
- Closed
-
PHPC-967 Add support for reading and writing OP_COMPRESSED
- Closed
-
PYTHON-1278 Support OP_COMPRESSED
- Closed
-
RUBY-1216 Add support for reading and writing OP_COMPRESSED
- Closed
-
RUST-54 Add support for reading and writing OP_COMPRESSED
- Closed
- is duplicated by
-
SERVER-25620 Compression of wire protocol for Clients
- Closed
- is related to
-
DRIVERS-2986 Package drivers with zstd and snappy support by default
- Backlog
- links to