-
Notifications
You must be signed in to change notification settings - Fork 43
DOCSP-47032: Network compression #622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,95 +1,101 @@ | ||||||||||
.. _compression: | ||||||||||
.. _network-compression: | ||||||||||
.. _java-compression: | ||||||||||
|
||||||||||
=================== | ||||||||||
Network Compression | ||||||||||
=================== | ||||||||||
======================== | ||||||||||
Compress Network Traffic | ||||||||||
======================== | ||||||||||
|
||||||||||
You can enable a driver option to compress messages which reduces the amount | ||||||||||
of data passed over the network between MongoDB and your application. | ||||||||||
.. contents:: On this page | ||||||||||
:local: | ||||||||||
:backlinks: none | ||||||||||
:depth: 1 | ||||||||||
:class: singlecol | ||||||||||
|
||||||||||
The driver supports the following algorithms: | ||||||||||
.. facet:: | ||||||||||
:name: genre | ||||||||||
:values: reference | ||||||||||
|
||||||||||
.. meta:: | ||||||||||
:keywords: zlib, zstandard, zstd, snappy | ||||||||||
|
||||||||||
1. `Snappy <https://google.github.io/snappy/>`__: available in MongoDB 3.4 and later. | ||||||||||
Overview | ||||||||||
-------- | ||||||||||
|
||||||||||
2. `Zlib <https://zlib.net/>`__: available in MongoDB 3.6 and later. | ||||||||||
In this guide, you can learn how to use the {+driver-short+} to enable network | ||||||||||
compression. The driver provides a connection option to compress messages, which | ||||||||||
reduces the amount of data passed over the network between MongoDB and your application. | ||||||||||
|
||||||||||
3. `Zstandard <https://github.com/facebook/zstd/>`__: available in MongoDB 4.2 and later. | ||||||||||
The driver supports the following compression algorithms: | ||||||||||
|
||||||||||
- `Snappy <https://google.github.io/snappy/>`__: Available in {+mdb-server+} v3.4 and later. | ||||||||||
- `Zlib <https://zlib.net/>`__: Available in {+mdb-server+} v3.6 and later. | ||||||||||
- `Zstandard <https://github.com/facebook/zstd/>`__: Available in {+mdb-server+} v4.2 and later. | ||||||||||
|
||||||||||
The driver tests against the following versions of these libraries: | ||||||||||
|
||||||||||
- ``{+snappyVersion+}`` | ||||||||||
- ``{+zstdVersion+}`` | ||||||||||
|
||||||||||
If you specify multiple compression algorithms, the driver selects the | ||||||||||
first one in the list supported by the MongoDB instance to which it is | ||||||||||
connected. | ||||||||||
If you specify multiple compression algorithms, the driver selects the first one | ||||||||||
in the list supported by your MongoDB instance. | ||||||||||
|
||||||||||
.. note:: | ||||||||||
|
||||||||||
Applications that require Snappy or Zstandard compression must | ||||||||||
:ref:`add explicit dependencies <compression-dependencies>` for those | ||||||||||
algorithms. | ||||||||||
add explicit dependencies for those algorithms. To learn more, | ||||||||||
see the :ref:`java-compression-dependencies` section of this guide. | ||||||||||
|
||||||||||
.. _enable-compression: | ||||||||||
.. _java-compression-specify: | ||||||||||
|
||||||||||
Specify Compression Algorithms | ||||||||||
------------------------------ | ||||||||||
|
||||||||||
You can enable compression for the connection to your MongoDB instance | ||||||||||
by specifying the algorithms in one of two ways: adding the parameter to your | ||||||||||
connection string using ``ConnectionString`` or by calling the method in the | ||||||||||
``MongoClientSettings.Builder`` class. | ||||||||||
|
||||||||||
.. tabs:: | ||||||||||
by specifying the algorithms in one of the following ways: | ||||||||||
|
||||||||||
.. tab:: ConnectionString | ||||||||||
:tabid: connectionstring | ||||||||||
|
||||||||||
To enable compression using the `ConnectionString <{+api+}/apidocs/mongodb-driver-core/com/mongodb/ConnectionString.html>`__, | ||||||||||
add the parameter ``compressors`` in the connection string passed to | ||||||||||
``MongoClients.create()``. You can specify one or more compression | ||||||||||
algorithms, separating them with commas: | ||||||||||
- Use the ``compressors`` parameter in your connection string | ||||||||||
- Chain the ``compressorList()`` method to the ``MongoClientSettings.builder()`` method | ||||||||||
|
- Use the ``compressors`` parameter in your connection string | |
- Chain the ``compressorList()`` method to the ``MongoClientSettings.builder()`` method | |
- Use the ``compressors`` parameter in your connection string. | |
- Chain the ``compressorList()`` method to the ``MongoClientSettings.builder()`` method. |
S: Would use a period since there is an implied you.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the start-specify-uri
and end-specify-uri
look confusing to me, for there is no uri involved here.
maybe better naming like start-use-client-settings-builder
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes good catch, I'll update these comments!
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
about these implementations, see the following Github repositories: | |
about these implementations, see the following GitHub repositories: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// start-specify-connection-string | ||
ConnectionString connectionString = new ConnectionString( | ||
"mongodb+srv://<db_username>:<db_password>@<cluster-url>/?compressors=snappy,zlib,zstd"); | ||
|
||
MongoClient client = MongoClients.create(connectionString); | ||
// end-specify-connection-string | ||
|
||
// start-specify-uri | ||
MongoClientSettings settings = MongoClientSettings.builder() | ||
.compressorList(Arrays.asList(MongoCompressor.createSnappyCompressor(), | ||
MongoCompressor.createZlibCompressor(), | ||
MongoCompressor.createZstdCompressor())) | ||
.build(); | ||
|
||
MongoClient client = MongoClients.create(settings); | ||
// end-specify-uri |
Uh oh!
There was an error while loading. Please reload this page.