-
Notifications
You must be signed in to change notification settings - Fork 17
DOCSP-39689 Network Compression standardization #70
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
Merged
jordan-smith721
merged 7 commits into
mongodb:main
from
jordan-smith721:DOCSP-39689-network-compression
Aug 30, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f786998
network compression standardization
jordan-smith721 8910877
facet & meta
jordan-smith721 5e9ca07
clean up and typos
jordan-smith721 6351fd8
Nora feedback
jordan-smith721 3090ba3
fix
jordan-smith721 430b62f
remove import
jordan-smith721 601b73a
Merge branch 'main' into DOCSP-39689-network-compression
jordan-smith721 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
.. _java-rs-compression: | ||
.. _java-rs-network-compression: | ||
|
||
======================== | ||
Compress Network Traffic | ||
======================== | ||
|
||
.. contents:: On this page | ||
:local: | ||
:backlinks: none | ||
:depth: 1 | ||
:class: singlecol | ||
|
||
.. facet:: | ||
:name: genre | ||
:values: reference | ||
|
||
.. meta:: | ||
:keywords: zlib, zstandard, zstd, snappy | ||
|
||
The {+driver-short+} provides a connection option to compress messages, which reduces the amount | ||
of data passed over the network between MongoDB and your application. | ||
|
||
The driver supports the following algorithms: | ||
|
||
- `Snappy <https://google.github.io/snappy/>`__: available in MongoDB 3.4 and later. | ||
- `Zlib <https://zlib.net/>`__: available in MongoDB 3.6 and later. | ||
- `Zstandard <https://github.com/facebook/zstd/>`__: available in MongoDB 4.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 your MongoDB instance. | ||
|
||
.. note:: | ||
|
||
Applications that require Snappy or Zstandard compression must | ||
:ref:`add explicit dependencies <java-rs-compression-dependencies>` for those | ||
algorithms. | ||
|
||
.. _enable-compression: | ||
|
||
Specify Compression Algorithms | ||
------------------------------ | ||
|
||
You can enable compression for the connection to your MongoDB instance | ||
by specifying the algorithms in one of two ways. Select the | ||
:guilabel:`Connection String` or :guilabel:`MongoClientSettings` tab to | ||
see the corresponding syntax: | ||
|
||
- In the ``compressors`` parameter of your connection string | ||
- In the ``compressorList`` method chained to the ``MongoClientSettings.builder()`` method | ||
|
||
The following example shows how to specify all compression algorithms: | ||
|
||
.. tabs:: | ||
|
||
.. tab:: Connection String | ||
:tabid: connectionstring | ||
|
||
.. literalinclude:: /includes/connect/network-compression.java | ||
:start-after: start-specify-connection-string | ||
:end-before: end-specify-connection-string | ||
:language: java | ||
|
||
.. tab:: MongoClientSettings | ||
:tabid: mongoclientsettings | ||
|
||
.. literalinclude:: /includes/connect/network-compression.java | ||
:start-after: start-specify-uri | ||
:end-before: end-specify-uri | ||
:language: java | ||
|
||
.. _java-rs-compression-dependencies: | ||
|
||
Compression Algorithm Dependencies | ||
---------------------------------- | ||
|
||
The JDK natively supports `Zlib <https://zlib.net/>`__ compression. However, | ||
Snappy and Zstandard depend on open source Java implementations. To learn more | ||
about these implementations, see the following Github pages: | ||
|
||
- `snappy-java <https://github.com/xerial/snappy-java>`__ | ||
- `zstd-java <https://github.com/luben/zstd-jni>`__ | ||
|
||
API Documentation | ||
----------------- | ||
|
||
To learn more about any of the methods or types discussed in this | ||
guide, see the following API documentation: | ||
|
||
- `MongoClient <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoClient.html>`__ | ||
- `createSnappyCompressor() <{+api+}/mongodb-driver-core/com/mongodb/MongoCompressor.html#createSnappyCompressor()>`__ | ||
- `createZlibCompressor() <{+api+}//mongodb-driver-core/com/mongodb/MongoCompressor.html#createZlibCompressor()>`__ | ||
- `createZstdCompressor() <{+api+}/mongodb-driver-core/com/mongodb/MongoCompressor.html#createZstdCompressor()>`__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.