Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a4ce124

Browse files
authoredAug 30, 2024
DOCSP-39689 Network Compression standardization (#70)
1 parent efbe96b commit a4ce124

File tree

5 files changed

+122
-152
lines changed

5 files changed

+122
-152
lines changed
 

‎snooty.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
name = "java-rs"
22
title = "Java Reactive Streams Driver"
33

4-
intersphinx = [ "https://www.mongodb.com/docs/manual/objects.inv",
5-
"https://www.mongodb.com/docs/atlas/objects.inv"
6-
]
4+
intersphinx = [
5+
"https://www.mongodb.com/docs/manual/objects.inv",
6+
"https://www.mongodb.com/docs/atlas/objects.inv",
7+
]
78

89
sharedinclude_root = "https://raw.githubusercontent.com/10gen/docs-shared/main/"
910

@@ -29,4 +30,6 @@ string-data-type = "``String``"
2930
bool = "``boolean``"
3031
pr = "Project Reactor"
3132
mdb-server = "MongoDB Server"
32-
stable-api = "Stable API"
33+
snappyVersion = "org.xerial.snappy:snappy-java:1.1.10.3"
34+
zstdVersion = "com.github.luben:zstd-jni:1.5.5-3"
35+
stable-api = "Stable API"

‎source/connect-to-mongo/compression.txt

Lines changed: 0 additions & 147 deletions
This file was deleted.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
.. _java-rs-compression:
2+
.. _java-rs-network-compression:
3+
4+
========================
5+
Compress Network Traffic
6+
========================
7+
8+
.. contents:: On this page
9+
:local:
10+
:backlinks: none
11+
:depth: 1
12+
:class: singlecol
13+
14+
.. facet::
15+
:name: genre
16+
:values: reference
17+
18+
.. meta::
19+
:keywords: zlib, zstandard, zstd, snappy
20+
21+
The {+driver-short+} provides a connection option to compress messages, which reduces the amount
22+
of data passed over the network between MongoDB and your application.
23+
24+
The driver supports the following algorithms:
25+
26+
- `Snappy <https://google.github.io/snappy/>`__: available in MongoDB 3.4 and later.
27+
- `Zlib <https://zlib.net/>`__: available in MongoDB 3.6 and later.
28+
- `Zstandard <https://github.com/facebook/zstd/>`__: available in MongoDB 4.2 and later.
29+
30+
The driver tests against the following versions of these libraries:
31+
32+
- ``{+snappyVersion+}``
33+
- ``{+zstdVersion+}``
34+
35+
If you specify multiple compression algorithms, the driver selects the first one
36+
in the list supported by your MongoDB instance.
37+
38+
.. note::
39+
40+
Applications that require Snappy or Zstandard compression must
41+
:ref:`add explicit dependencies <java-rs-compression-dependencies>` for those
42+
algorithms.
43+
44+
.. _enable-compression:
45+
46+
Specify Compression Algorithms
47+
------------------------------
48+
49+
You can enable compression for the connection to your MongoDB instance
50+
by specifying the algorithms in one of two ways. Select the
51+
:guilabel:`Connection String` or :guilabel:`MongoClientSettings` tab to
52+
see the corresponding syntax:
53+
54+
- In the ``compressors`` parameter of your connection string
55+
- In the ``compressorList`` method chained to the ``MongoClientSettings.builder()`` method
56+
57+
The following example shows how to specify all compression algorithms:
58+
59+
.. tabs::
60+
61+
.. tab:: Connection String
62+
:tabid: connectionstring
63+
64+
.. literalinclude:: /includes/connect/network-compression.java
65+
:start-after: start-specify-connection-string
66+
:end-before: end-specify-connection-string
67+
:language: java
68+
69+
.. tab:: MongoClientSettings
70+
:tabid: mongoclientsettings
71+
72+
.. literalinclude:: /includes/connect/network-compression.java
73+
:start-after: start-specify-uri
74+
:end-before: end-specify-uri
75+
:language: java
76+
77+
.. _java-rs-compression-dependencies:
78+
79+
Compression Algorithm Dependencies
80+
----------------------------------
81+
82+
The JDK natively supports `Zlib <https://zlib.net/>`__ compression. However,
83+
Snappy and Zstandard depend on open source Java implementations. To learn more
84+
about these implementations, see the following Github pages:
85+
86+
- `snappy-java <https://github.com/xerial/snappy-java>`__
87+
- `zstd-java <https://github.com/luben/zstd-jni>`__
88+
89+
API Documentation
90+
-----------------
91+
92+
To learn more about any of the methods or types discussed in this
93+
guide, see the following API documentation:
94+
95+
- `MongoClient <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoClient.html>`__
96+
- `createSnappyCompressor() <{+api+}/mongodb-driver-core/com/mongodb/MongoCompressor.html#createSnappyCompressor()>`__
97+
- `createZlibCompressor() <{+api+}//mongodb-driver-core/com/mongodb/MongoCompressor.html#createZlibCompressor()>`__
98+
- `createZstdCompressor() <{+api+}/mongodb-driver-core/com/mongodb/MongoCompressor.html#createZstdCompressor()>`__

‎source/connect.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Connect to MongoDB
2626
/connect-to-mongo/choose-connection-target/
2727
/connect-to-mongo/connection-options/
2828
/connect-to-mongo/tls/
29-
/connect-to-mongo/compression/
29+
/connect-to-mongo/network-compression
3030
/connect-to-mongo/stable-api/
3131

3232
Overview
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// start-specify-connection-string
2+
ConnectionString connectionString = new ConnectionString(
3+
"mongodb+srv://<db_username>:<db_password>@<cluster-url>/?compressors=snappy,zlib,zstd");
4+
5+
MongoClient client = MongoClients.create(connectionString);
6+
// end-specify-connection-string
7+
8+
// start-specify-uri
9+
MongoClientSettings settings = MongoClientSettings.builder()
10+
.compressorList(Arrays.asList(MongoCompressor.createSnappyCompressor(),
11+
MongoCompressor.createZlibCompressor(),
12+
MongoCompressor.createZstdCompressor()))
13+
.build();
14+
15+
MongoClient client = MongoClients.create(settings);
16+
// end-specify-uri

0 commit comments

Comments
 (0)
Please sign in to comment.