Skip to content

DOCSP-51416 Network Compression #162

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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions snooty.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name = "ruby-driver"
title = "Ruby Driver"
toc_landing_pages = [
"/connect/connection-options",
"/crud/query",
"/indexes",
"/security/authentication"
Expand Down
3 changes: 0 additions & 3 deletions source/connect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ Connect to MongoDB
:maxdepth: 1

Create a Client </connect/mongoclient>
Stable API </connect/stable-api>
Choose a Connection Target </connect/connection-targets>
Connection Options </connect/connection-options>
Configure TLS </connect/tls>
Limit Server Execution Time </connect/csot>
AWS Lambda <https://www.mongodb.com/docs/atlas/manage-connections-aws-lambda/>
8 changes: 8 additions & 0 deletions source/connect/connection-options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ Specify Connection Options
.. meta::
:keywords: connection string, URI, server, Atlas, settings, configure

.. toctree::
:titlesonly:
:maxdepth: 1

Compress Network Traffic </connect/network-compression>
Stable API </connect/stable-api>
Limit Server Execution Time </connect/csot>

Overview
--------

Expand Down
59 changes: 59 additions & 0 deletions source/connect/network-compression.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
========================
Compress Network Traffic
========================

.. meta::
:keywords: network compression, zlib, snappy, zstd, Ruby driver, connection string, URI, settings, configure

.. contents:: On this page
:local:
:depth: 2

Overview
--------

The {+driver-short+} supports network compression to reduce the amount
of data transmitted between the client and the server.

The driver supports the following compression algorithms:

- `Snappy <https://google.github.io/snappy/>`__
- `Zlib <https://zlib.net/>`__
- `Zstandard <https://github.com/facebook/zstd/>`__


If you specify multiple compression algorithms, the driver selects the first
one in the list supported by your MongoDB instance.

Specify Compression Algorithms
------------------------------

To enable compression for the connection to your MongoDB instance,
specify the algorithms you want to use in one of the following ways:

- Add the algorithms to your connection string as a parameter
- Specify the algorithms in the ``compressors`` option of your ``Mongo::Client`` object

.. tabs::

.. tab:: Connection String
:tabid: connection-string

To enable network compression by using the connection string, add the ``compressors`` option.
You can specify one or more algorithms as a comma-separated list.

.. literalinclude:: /includes/connect/network-compression.rb
:start-after: start-connection-string
:end-before: end-connection-string
:language: ruby

.. tab:: Client Settings
:tabid: client-settings

To enable compression in your Client object, pass the ``compressors`` option
to the ``Mongo::Client`` constructor.

.. literalinclude:: /includes/connect/network-compression.rb
:start-after: start-client-settings
:end-before: end-client-settings
:language: ruby
9 changes: 9 additions & 0 deletions source/includes/connect/network-compression.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# start-connection-string
uri = "mongodb://<hostname>:<port>/?compressors=zlib,snappy"
client = Mongo::Client.new(uri)
# end-connection-string

# start-client-settings
client = Mongo::Client.new(["<hostname>:<port>"],
compressors: ["zlib", "snappy"])
# end-client-settings
Loading