-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add compression to replicator #6013
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
Open
lacklacklack
wants to merge
10
commits into
apache:main
Choose a base branch
from
lacklacklack:replicator-compression-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
95baa10
Add compression to replicator
lacklacklack 7581daa
Add test and metrics
lacklacklack f1fe550
Resolve comments: gzip only, simplify _bulk_docs body handling
lacklacklack a37a5fb
Resolve new minor comments, refactor
lacklacklack 204f0bb
Add per job compression
lacklacklack 16fade4
Adding bulk_get compression, fixes
lacklacklack a59c3b8
Clean code, test refactor, new test case
lacklacklack 5349ae3
Remove unnecessary iolist_to_binary call
lacklacklack d094cf7
Run erlfmt
lacklacklack 42e2d6a
Add docs
lacklacklack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
src/couch_replicator/test/eunit/couch_replicator_compression_tests.erl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| % Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| % use this file except in compliance with the License. You may obtain a copy of | ||
| % the License at | ||
| % | ||
| % http://www.apache.org/licenses/LICENSE-2.0 | ||
| % | ||
| % Unless required by applicable law or agreed to in writing, software | ||
| % distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| % WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| % License for the specific language governing permissions and limitations under | ||
| % the License. | ||
|
|
||
| -module(couch_replicator_compression_tests). | ||
|
|
||
| -include_lib("couch/include/couch_eunit.hrl"). | ||
| -include_lib("couch/include/couch_db.hrl"). | ||
|
|
||
| -define(DOCS_COUNT, 10). | ||
| -define(LARGE_DOCS_COUNT, 500). | ||
| -define(TIMEOUT_EUNIT, 60). | ||
|
|
||
| compression_test_() -> | ||
| { | ||
| "Replication compression tests", | ||
| { | ||
| foreach, | ||
| fun setup/0, | ||
| fun teardown/1, | ||
| [ | ||
| ?TDEF_FE(should_not_compress_by_default, ?TIMEOUT_EUNIT), | ||
| ?TDEF_FE(should_compress_when_enabled, ?TIMEOUT_EUNIT), | ||
| ?TDEF_FE(should_compress_large_batch, ?TIMEOUT_EUNIT), | ||
| ?TDEF_FE(should_compress_per_job, ?TIMEOUT_EUNIT), | ||
| ?TDEF_FE(job_compression_overrides_global_disabled, ?TIMEOUT_EUNIT) | ||
| ] | ||
| } | ||
| }. | ||
|
|
||
| setup() -> | ||
| Ctx = couch_replicator_test_helper:test_setup(), | ||
| config:set("replicator", "request_compression", "none", false), | ||
| config:set("replicator", "compress_min_size", "1024", false), | ||
| Ctx. | ||
|
|
||
| teardown(Ctx) -> | ||
| config:delete("replicator", "request_compression", false), | ||
| config:delete("replicator", "compress_min_size", false), | ||
| couch_replicator_test_helper:test_teardown(Ctx). | ||
|
|
||
| should_not_compress_by_default({_Ctx, {Source, Target}}) -> | ||
| Before = couch_stats:sample([couch_replicator, requests_compressed, gzip]), | ||
| populate_db(Source, ?DOCS_COUNT), | ||
| replicate(Source, Target), | ||
| couch_replicator_test_helper:cluster_compare_dbs(Source, Target), | ||
| After = couch_stats:sample([couch_replicator, requests_compressed, gzip]), | ||
| ?assertEqual(Before, After). | ||
|
|
||
| should_compress_when_enabled({_Ctx, {Source, Target}}) -> | ||
| config:set("replicator", "request_compression", "gzip", false), | ||
| config:set("replicator", "compress_min_size", "10", false), | ||
| Before = couch_stats:sample([couch_replicator, requests_compressed, gzip]), | ||
| populate_db(Source, ?DOCS_COUNT), | ||
| replicate(Source, Target), | ||
| couch_replicator_test_helper:cluster_compare_dbs(Source, Target), | ||
| After = couch_stats:sample([couch_replicator, requests_compressed, gzip]), | ||
| ?assert(After > Before). | ||
|
|
||
| should_compress_large_batch({_Ctx, {Source, Target}}) -> | ||
| config:set("replicator", "request_compression", "gzip", false), | ||
| Before = couch_stats:sample([couch_replicator, requests_compressed, gzip]), | ||
| populate_db(Source, ?LARGE_DOCS_COUNT), | ||
| replicate(Source, Target), | ||
| couch_replicator_test_helper:cluster_compare_dbs(Source, Target), | ||
| After = couch_stats:sample([couch_replicator, requests_compressed, gzip]), | ||
| ?assert(After > Before). | ||
|
|
||
| should_compress_per_job({_Ctx, {Source, Target}}) -> | ||
| % global config is none (default), but job sets gzip | ||
| config:set("replicator", "compress_min_size", "10", false), | ||
| Before = couch_stats:sample([couch_replicator, requests_compressed, gzip]), | ||
| populate_db(Source, ?DOCS_COUNT), | ||
| replicate_with_options(Source, Target, [{<<"request_compression">>, <<"gzip">>}]), | ||
| couch_replicator_test_helper:cluster_compare_dbs(Source, Target), | ||
| After = couch_stats:sample([couch_replicator, requests_compressed, gzip]), | ||
| ?assert(After > Before). | ||
|
|
||
| job_compression_overrides_global_disabled({_Ctx, {Source, Target}}) -> | ||
| % global config is gzip, but job disables it | ||
| config:set("replicator", "request_compression", "gzip", false), | ||
| config:set("replicator", "compress_min_size", "10", false), | ||
| Before = couch_stats:sample([couch_replicator, requests_compressed, gzip]), | ||
| populate_db(Source, ?DOCS_COUNT), | ||
| replicate_with_options(Source, Target, [{<<"request_compression">>, <<"none">>}]), | ||
| couch_replicator_test_helper:cluster_compare_dbs(Source, Target), | ||
| After = couch_stats:sample([couch_replicator, requests_compressed, gzip]), | ||
| ?assertEqual(Before, After). | ||
|
|
||
| populate_db(DbName, Count) -> | ||
| Docs = lists:map( | ||
| fun(I) -> | ||
| Id = iolist_to_binary(io_lib:format("doc~p", [I])), | ||
| Data = list_to_binary(lists:duplicate(100, $x)), | ||
| {[ | ||
| {<<"_id">>, Id}, | ||
| {<<"value">>, I}, | ||
| {<<"data">>, Data} | ||
| ]} | ||
| end, | ||
| lists:seq(1, Count) | ||
| ), | ||
| {ok, _} = fabric:update_docs(DbName, Docs, [?ADMIN_CTX]), | ||
| ok. | ||
|
|
||
| replicate(Source, Target) -> | ||
| replicate_with_options(Source, Target, []). | ||
|
|
||
| replicate_with_options(Source, Target, ExtraOptions) -> | ||
| SourceUrl = couch_replicator_test_helper:cluster_db_url(Source), | ||
| TargetUrl = couch_replicator_test_helper:cluster_db_url(Target), | ||
| RepObject = | ||
| {[ | ||
| {<<"source">>, SourceUrl}, | ||
| {<<"target">>, TargetUrl}, | ||
| {<<"continuous">>, false} | ||
| | ExtraOptions | ||
| ]}, | ||
| {ok, _} = couch_replicator_test_helper:replicate(RepObject). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,6 +122,33 @@ Replicator Database Configuration | |
| [replicator] | ||
| connection_timeout = 30000 | ||
|
|
||
| .. config:option:: request_compression :: Compress outbound request bodies | ||
|
|
||
| .. versionadded:: 3.4 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're past 3.5.2 already so I'd add 3.6 |
||
|
|
||
| Compress outbound replication request bodies (``_bulk_docs``, | ||
| ``_revs_diff``, ``_bulk_get``) using gzip before sending. Accepted | ||
| values are ``none`` (disabled, the default) and ``gzip``. Enable only | ||
| when the replication target supports ``Content-Encoding: gzip`` on | ||
| inbound requests, which all CouchDB servers do:: | ||
|
|
||
| [replicator] | ||
| request_compression = none | ||
|
|
||
| This option can also be set per replication job by including | ||
| ``"request_compression": "gzip"`` in the replication document or | ||
| ``_replicate`` request body, which overrides the global setting. | ||
|
|
||
| .. config:option:: compress_min_size :: Minimum body size for compression | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also add a versionadded |
||
|
|
||
| Minimum request body size in bytes before compression is applied. | ||
| Bodies smaller than this threshold are sent uncompressed even if | ||
| :config:option:`request_compression <replicator/request_compression>` | ||
| is enabled:: | ||
|
|
||
| [replicator] | ||
| compress_min_size = 1024 | ||
|
|
||
| .. config:option:: retries_per_request :: Number of retries per request | ||
|
|
||
| .. versionchanged:: 2.1.1 | ||
|
|
@@ -284,7 +311,7 @@ Replicator Database Configuration | |
| Comma delimited ``host:port:target_host:target_port`` mappings to use for | ||
| replicator requests. This is useful for cases where outbound HTTP requests | ||
| must be made through a transparent proxy or when port rewriting is needed. | ||
|
|
||
| This feature is similar to curl's ``--connect-to`` option. | ||
|
|
||
| ``host`` may be either an exact hostname such as ``foo.bar.com`` or a | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.