Skip to content

Commit b749b56

Browse files
committed
chore: extended the documentation about compression
1 parent cf32c87 commit b749b56

File tree

1 file changed

+47
-4
lines changed

1 file changed

+47
-4
lines changed

README.md

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- support for complex and nested documents using the `Mongo.Collection` macros
3030
- support for streaming protocol ([See](https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-monitoring.rst#streaming-protocol))
3131
- support for migration scripts
32+
- support for compression for zlib and zstd ([See](https://github.com/mongodb/specifications/blob/07b7649cc5c805ef4f85fccddf39226add7114e6/source/compression/OP_COMPRESSED.md))
3233

3334
## mongodb_ecto
3435

@@ -541,6 +542,52 @@ In a Phoenix application with installed Phoenix Dashboard the metrics can be use
541542

542543
Then you see for each collection the execution time for each different command in the Dashboard metric page.
543544

545+
## Network compression
546+
547+
The driver supports two compressors
548+
549+
* zlib, which is supported by Erlang
550+
* zstd, which is optional and supported by https://github.com/silviucpp/ezstd bindings.
551+
552+
To activate zstd compression, simply add `{:ezstd, "~> 1.1"}` to the dependencies of your `mix.exs` file.
553+
The driver will provide the related code. After activating the zstd compressor can be used by appending
554+
the `compressors=zstd` to the URL connection string.
555+
556+
The driver uses compression for the following functions:
557+
558+
* `Mongo.aggregate/4`
559+
* `Mongo.find/4`
560+
* `Mongo.insert_one/4`
561+
* `Mongo.insert_many/4`
562+
* `Mongo.update/4`
563+
* `Mongo.update_documents/6`
564+
* `Mongo.find_one_and_update/5`
565+
* `Mongo.find_one_and_replace/5`
566+
* `Mongo.find_one_and_delete/4`
567+
* `Mongo.count/4`
568+
* `Mongo.distinct/5`
569+
* `Mongo.delete_documents/5`
570+
* `Mongo.create/4`
571+
572+
You can disable the compression for a single function by using the option `compression: false`, for example:
573+
574+
```
575+
Mongo.find(conn, "tasks", %{}, compression: false)
576+
```
577+
The compression significantly reduces the amount of data, while increasing the load on the CPU.
578+
This is certainly interesting for environments in which network transmission has to be paid for.
579+
580+
zlib compression requires a greater penalty in terms of speed than zstd compression.
581+
The zstd compression offers a good compromise between compression rate and speed and
582+
is undoubtedly supported by all current MongoDB.
583+
584+
The speed also depends on the `batch_size` attribute. A higher speed is achieved for certain batch sizes.
585+
Simple experiments can be carried out here to determine which size shortens the duration of the queries:
586+
587+
```elixir
588+
:timer.tc(fn -> Mongo.find(conn, "tasks", %{}, limit: 30_000, batch_size: 1000) |> Stream.reject(fn _x -> true end) |> Stream.run() end)
589+
```
590+
544591
## Connection Pooling
545592

546593
The driver supports pooling by DBConnection (2.x). By default `mongodb_driver` will start a single
@@ -1177,10 +1224,6 @@ $ mongod --sslMode allowSSL --sslPEMKeyFile /path/to/mongodb.pem
11771224
- For `--sslMode` you can use one of `allowSSL` or `preferSSL`
11781225
- You can enable any other options you want when starting `mongod`
11791226

1180-
## Special Thanks
1181-
1182-
Special thanks to [JetBrains](https://www.jetbrains.com/?from=elixir-mongodb-driver) for providing a free JetBrains Open Source license for their complete toolbox.
1183-
11841227
## Copyright and License
11851228

11861229
Copyright 2015 Eric Meadows-Jönsson and Justin Wood \

0 commit comments

Comments
 (0)