Skip to content

Commit 7d45d17

Browse files
committed
DOCSP-51324: Network Compression
1 parent 6dc5793 commit 7d45d17

File tree

2 files changed

+98
-29
lines changed

2 files changed

+98
-29
lines changed

source/connect.txt

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ Connection Guide
2424

2525
Create a MongoClient </connect/mongoclient>
2626
Choose a Connection Target </connect/connection-targets>
27-
Connection Options </connect/connection-options>
27+
Connection Options </connect/connection-options>
28+
Network Compression </connect/network-compression>
2829
AWS Lambda <https://www.mongodb.com/docs/atlas/manage-connections-aws-lambda/>
2930

3031
.. /connect/connection-troubleshooting
@@ -124,34 +125,6 @@ connecting by using TLS:
124125
.. To learn more about disabling hostname verification, see :ref:`kotlin-sync-insecure-tls` in
125126
.. the TLS configuration guide.
126127

127-
Network Compression
128-
-------------------
129-
130-
The following sections describe how to connect to MongoDB
131-
while specifying network compression algorithms.
132-
133-
Compression Algorithms
134-
~~~~~~~~~~~~~~~~~~~~~~
135-
136-
The following tabs demonstrate how to specify all available compressors
137-
while connecting to MongoDB:
138-
139-
.. include:: /includes/connect/compression-tabs.rst
140-
141-
.. To learn more about specifying compression algorithms, see
142-
.. :ref:`kotlin-sync-enable-compression` in the Network Compression guide.
143-
144-
zlib Compression Level
145-
~~~~~~~~~~~~~~~~~~~~~~
146-
147-
The following tabs demonstrate how to specify a compression level for
148-
the ``zlib`` compressor:
149-
150-
.. include:: /includes/connect/zlib-level-tabs.rst
151-
152-
.. To learn more about setting the zlib compression level, see
153-
.. :ref:`kotlin-sync-enable-compression` in the Network Compression guide.
154-
155128
Server Selection
156129
----------------
157130

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
.. _kotlin-sync-compression:
2+
3+
========================
4+
Compress Network Traffic
5+
========================
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 1
11+
:class: singlecol
12+
13+
.. facet::
14+
:name: genre
15+
:values: reference
16+
17+
.. meta::
18+
:keywords: zlib, zstandard, zstd, snappy
19+
20+
Overview
21+
--------
22+
23+
In this guide, you can learn how to use the {+driver-short+} to enable network
24+
compression. The driver provides a connection option to compress messages, which
25+
reduces the amount of data passed over the network between MongoDB and your application.
26+
27+
The driver supports the following compression algorithms:
28+
29+
- `Snappy <https://google.github.io/snappy/>`__
30+
- `Zlib <https://zlib.net/>`__
31+
- `Zstandard <https://github.com/facebook/zstd/>`__
32+
33+
If you specify multiple compression algorithms, the driver selects the first one
34+
in the list supported by your MongoDB instance.
35+
36+
.. note::
37+
38+
Applications that require Snappy or Zstandard compression must
39+
add explicit dependencies for those algorithms. To learn more,
40+
see the :ref:`kotlin-sync-compression-dependencies` section of this guide.
41+
42+
Specify Compression Algorithms
43+
------------------------------
44+
45+
You can enable compression for the connection to your MongoDB instance
46+
by specifying the algorithms in one of the following ways:
47+
48+
- Chain the ``compressorList()`` method to the ``MongoClientSettings.builder()`` method.
49+
- Use the ``compressors`` parameter in your connection URI.
50+
51+
The following tabs demonstrate how to specify all available compressors
52+
while connecting to MongoDB. Select the :guilabel:`MongoClientSettings` or :guilabel:`Connection URI`
53+
tab to see the corresponding syntax:
54+
55+
.. include:: /includes/connect/compression-tabs.rst
56+
57+
Specify the Zlib Compression Level
58+
----------------------------------
59+
60+
If you specify ``zlib`` as one of your compression algorithms, you can also use the
61+
``MongoCompressor.LEVEL`` property to specify a compression level. This option accepts
62+
an integer value between ``-1`` and ``9``:
63+
64+
- **-1:** (Default). zlib uses its default compression level (usually ``6``).
65+
- **0:** No compression.
66+
- **1:** Fastest speed but lowest compression.
67+
- **9:** Best compression but slowest speed.
68+
69+
The following tabs demonstrate how to specify a compression level for
70+
the ``zlib`` compressor. Select the :guilabel:`MongoClientSettings` or :guilabel:`Connection URI`
71+
tab to see the corresponding syntax:
72+
73+
.. include:: /includes/connect/zlib-level-tabs.rst
74+
75+
.. _kotlin-sync-compression-dependencies:
76+
77+
Compression Algorithm Dependencies
78+
----------------------------------
79+
80+
The JDK natively supports `Zlib <https://zlib.net/>`__ compression. However,
81+
Snappy and Zstandard depend on open source Java implementations. To learn more
82+
about these implementations, see the following GitHub repositories:
83+
84+
- `snappy-java <https://github.com/xerial/snappy-java>`__
85+
- `zstd-java <https://github.com/luben/zstd-jni>`__
86+
87+
API Documentation
88+
-----------------
89+
90+
To learn more about any of the methods or types discussed in this
91+
guide, see the following API documentation:
92+
93+
- `MongoClient <{+driver-api+}/-mongo-client/index.html>`__
94+
- `createSnappyCompressor() <{+core-api+}/com/mongodb/MongoCompressor.html#createSnappyCompressor()>`__
95+
- `createZlibCompressor() <{+core-api+}/com/mongodb/MongoCompressor.html#createZlibCompressor()>`__
96+
- `createZstdCompressor() <{+core-api+}/com/mongodb/MongoCompressor.html#createZstdCompressor()>`__

0 commit comments

Comments
 (0)