Search code examples
pythonmongodbcompressionpymongosnappy

How to ensure pymongo is using snappy compression for wire protocol


I'm using a mongodb 3.6 server and pymongo 3.4.

How can I ensure that mongodb is using snappy compression for data transfer?

In the mongodb log I see that snappy is enabled:

app_metadata=(formatVersion=1),assert=(commit_timestamp=none,read_timestamp=none),block_allocation=best,block_compressor=snappy,

But how can I be sure that when I make a request via pymongo that snappy compression is actually applied? I have experimented with adding mongodb://localhost/?compressors=zlib to the connection string, but adding compressors=whatever doesn't seem to make any difference.

How can I ensure compression is applied for the wire protocol? Does the version of pymongo matter at all?


Solution

  • https://docs.mongodb.com/manual/reference/program/mongo/#cmdoption-mongo-networkmessagecompressors reads:

    Messages are compressed when both parties enable network compression. Otherwise, messages between the parties are uncompressed.

    On the client side I read https://api.mongodb.com/python/current/changelog.html#changes-in-version-3-7-0:

    Support for wire protocol compression

    as it was not supported before v3.7.

    The block_compressor you see in the log is likely storage compression, not the wire compression. It is defined in storage options of mongodb config serverside and can't be changed from the client.