Skip to content

Commit 6f62210

Browse files
authored
DOCSP-51324: Network Compression (#110)
1 parent 7c94562 commit 6f62210

File tree

5 files changed

+99
-33
lines changed

5 files changed

+99
-33
lines changed

source/connect.txt

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -121,34 +121,6 @@ connecting by using TLS:
121121
.. To learn more about disabling hostname verification, see :ref:`kotlin-sync-insecure-tls` in
122122
.. the TLS configuration guide.
123123

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

source/connect/connection-options.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ Specify Connection Options
1515
:titlesonly:
1616
:maxdepth: 1
1717

18-
Stable API </connect/stable-api>
19-
Limit Server Execution Time </connect/csot>
18+
Network Compression </connect/connection-options/network-compression>
19+
Stable API </connect/connection-options/stable-api>
20+
Limit Server Execution Time </connect/connection-options/csot>
2021
Connection Pools </connect/connection-pools>
2122

22-
.. /connect/network-compression
23-
.. /connect/server-selection
24-
2523
Overview
2624
--------
2725

File renamed without changes.
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 examples 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 compression (usually ``6``)
65+
- **0:** No compression
66+
- **1:** Fastest speed but lowest compression
67+
- **9:** Best compression but slowest speed
68+
69+
The following examples 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-jni <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+}/MongoCompressor.html#createSnappyCompressor()>`__
95+
- `createZlibCompressor() <{+core-api+}/MongoCompressor.html#createZlibCompressor()>`__
96+
- `createZstdCompressor() <{+core-api+}/MongoCompressor.html#createZstdCompressor()>`__

0 commit comments

Comments
 (0)