Skip to content
This repository was archived by the owner on Oct 17, 2022. It is now read-only.

Commit 3af64ec

Browse files
authored
Smoosh documentation (#438)
Add documentation for the new compaction daemon, including migration
1 parent 0fcf72a commit 3af64ec

File tree

4 files changed

+235
-133
lines changed

4 files changed

+235
-133
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ ext/__pycache__/
33
build/
44
venv
55
.venv
6+
Pipfile
7+
Pipfile.lock
68
.DS_Store
79
*~
810
*.swp

src/config/compaction.rst

+85-116
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
.. default-domain:: config
1414
.. highlight:: ini
1515

16-
========================
17-
Compaction Configuration
18-
========================
16+
==========
17+
Compaction
18+
==========
1919

2020
.. _config/database_compaction:
2121

@@ -39,160 +39,129 @@ Database Compaction Options
3939
[database_compaction]
4040
checkpoint_after = 5242880
4141

42-
.. _config/compactions:
42+
.. _config/view_compaction:
4343

44-
Compaction Daemon Rules
44+
View Compaction Options
4545
=======================
4646

47-
.. config:section:: compactions :: Compaction Daemon Rules
48-
49-
A list of rules to determine when to run automatic compaction. The
50-
:option:`daemons/compaction_daemon` compacts databases and their respective
51-
view groups when all the condition parameters are satisfied. Configuration
52-
can be per-database or global, and it has the following format::
53-
54-
[compactions]
55-
database_name = [ {ParamName, ParamValue}, {ParamName, ParamValue}, ... ]
56-
_default = [ {ParamName, ParamValue}, {ParamName, ParamValue}, ... ]
57-
58-
For example::
59-
60-
[compactions]
61-
_default = [{db_fragmentation, "70%"}, {view_fragmentation, "60%"}, {from, "23:00"}, {to, "04:00"}]
62-
63-
- ``db_fragmentation``: If the ratio of legacy data, including metadata, to
64-
current data in the database file size is equal to or greater than this
65-
value, this condition is satisfied. The percentage is expressed as an
66-
integer percentage. This value is computed as:
67-
68-
.. code-block:: none
69-
70-
(sizes.file - sizes.active) / sizes.file * 100
71-
72-
The sizes.active and sizes.file values can be obtained when
73-
querying :http:get:`/{db}`.
47+
.. config:section:: view_compaction :: View Compaction Options
7448
75-
- ``view_fragmentation``: If the ratio of legacy data, including metadata,
76-
to current data in a view index file size is equal to or greater then
77-
this value, this database compaction condition is satisfied. The
78-
percentage is expressed as an integer percentage. This value is computed
79-
as:
49+
.. config:option:: keyvalue_buffer_size :: Key-Values buffer size
8050
81-
.. code-block:: none
51+
Specifies maximum copy buffer size in bytes used during compaction::
8252

83-
(sizes.file - sizes.active) / sizes.file * 100
53+
[view_compaction]
54+
keyvalue_buffer_size = 2097152
8455

85-
The sizes.active and sizes.file values can be obtained when querying a
86-
:ref:`view group's information URI <api/ddoc/info>`.
56+
.. _config/compactions:
8757

88-
- ``from`` and ``to``: The period for which a database (and its view group)
89-
compaction is allowed. The value for these parameters must obey the
90-
format:
58+
Compaction Daemon
59+
=================
9160

92-
.. code-block:: none
61+
CouchDB ships with an automated, event-driven daemon internally known as "smoosh" that
62+
continuously re-prioritizes the database and secondary index files on each node and
63+
automatically compacts the files that will recover the most free space according to the
64+
following parameters.
9365

94-
HH:MM - HH:MM (HH in [0..23], MM in [0..59])
66+
.. config:section:: smoosh :: Compaction Daemon Rules
9567
96-
- ``strict_window``: If a compaction is still running after the end of the
97-
allowed period, it will be canceled if this parameter is set to `true`.
98-
It defaults to `false` and is meaningful only if the *period* parameter
99-
is also specified.
68+
.. config:option:: db_channels :: Active database channels
10069
101-
- ``parallel_view_compaction``: If set to `true`, the database and its
102-
views are compacted in parallel. This is only useful on certain setups,
103-
like for example when the database and view index directories point to
104-
different disks. It defaults to `false`.
70+
A comma-delimited list of channels that are sent the names of database
71+
files when those files are updated. Each channel can choose whether to
72+
enqueue the database for compaction; once a channel has enqueued the
73+
database, no additional channel in the list will be given the
74+
opportunity to do so.
10575

106-
Before a compaction is triggered, an estimation of how much free disk space
107-
is needed is computed. This estimation corresponds to two times the data
108-
size of the database or view index. When there's not enough free disk space
109-
to compact a particular database or view index, a warning message is
110-
logged.
76+
.. config:option:: view_channels :: Active secondary index channels
11177
112-
Examples:
78+
A comma-delimited list of channels that are sent the names of secondary
79+
index files when those files are updated. Each channel can choose
80+
whether to enqueue the index for compaction; once a channel has enqueued
81+
the index, no additional channel in the list will be given the
82+
opportunity to do so.
11383

114-
#.
115-
::
84+
.. config:option:: staleness :: Minimum time between priority calculations
11685
117-
[{db_fragmentation, "70%"}, {view_fragmentation, "60%"}]
86+
The number of minutes that the (expensive) priority calculation on an
87+
individual can be stale for before it is recalculated. Defaults to 5.
11888

119-
The `foo` database is compacted if its fragmentation is 70% or more. Any
120-
view index of this database is compacted only if its fragmentation is
121-
60% or more.
89+
.. config:option:: cleanup_index_files :: Automatically delete orphaned index files
12290
123-
#.
124-
::
91+
If set to true, the compaction daemon will delete the files for indexes
92+
that are no longer associated with any design document. Defaults to
93+
`false` and probably shouldn't be changed unless the node is running low
94+
on disk space, and only after considering the ramifications.
12595

126-
[{db_fragmentation, "70%"}, {view_fragmentation, "60%"}, {from, "00:00"}, {to, "04:00"}]
96+
.. config:option:: wait_secs :: Warmup period before triggering first compaction
12797
128-
Similar to the preceding example but a compaction (database or view
129-
index) is only triggered if the current time is between midnight and 4
130-
AM.
98+
The time a channel waits before starting compactions to allow time to
99+
observe the system and make a smarter decision about what to compact
100+
first. Hardly ever changed from the default of 30 (seconds).
131101

132-
#.
133-
::
102+
.. config:section:: smoosh.<channel> :: Per-channel configuration
134103
135-
[{db_fragmentation, "70%"}, {view_fragmentation, "60%"}, {from, "00:00"}, {to, "04:00"}, {strict_window, true}]
104+
The following settings control the resource allocation for a given compaction
105+
channel.
136106

137-
Similar to the preceding example - a compaction (database or view index)
138-
is only triggered if the current time is between midnight and 4 AM. If
139-
at 4 AM the database or one of its views is still compacting, the
140-
compaction process will be canceled.
107+
.. config:option:: capacity
141108
142-
#.
143-
::
109+
The maximum number of items the channel can hold (lowest priority item
110+
is removed to make room for new items). Defaults to 9999.
144111

145-
[{db_fragmentation, "70%"}, {view_fragmentation, "60%"}, {from, "00:00"}, {to, "04:00"}, {strict_window, true}, {parallel_view_compaction, true}]
112+
.. config:option:: concurrency
146113
147-
Similar to the preceding example, but a database and its views can be
148-
compacted in parallel.
114+
The maximum number of jobs that can run concurrently in this channel.
115+
Defaults to 1.
149116

150-
.. _config/compaction_daemon:
117+
.. config: option:: from
151118
152-
Configuration of Compaction Daemon
153-
==================================
119+
.. config: option:: to
154120
155-
.. config:section:: compaction_daemon :: Configuration of Compaction Daemon
121+
The time period during which this channel is allowed to execute
122+
compactions. The value for each of these parameters must obey the format
123+
`HH:MM` with HH in [0..23] and MM in [0..59]. Each channel listed in the
124+
top-level daemon configuration continuously builds its priority queue
125+
regardless of the period defined here. The default is to allow the
126+
channel to execute compactions all the time.
156127

157-
.. config:option:: check_interval
128+
.. config: option:: strict_window
158129
159-
The delay, in seconds, between each check for which database and view
160-
indexes need to be compacted. In other words, this delay will occur
161-
after *all* databases and views are compacted (or at least checked)::
130+
If set to `true`, any compaction that is still running after the end of
131+
the allowed perio will be suspended, and then resumed during the next
132+
window. It defaults to `false`, in which case any running compactions
133+
will be allowed to finish, but no new ones will be started.
162134

163-
[compaction_daemon]
164-
check_interval = 3600
135+
There are also several settings that collectively control whether a channel will
136+
enqueue a file for compaction and how it prioritizes files within its queue:
165137

166-
.. config:option:: min_file_size
138+
.. config:option:: max_priority
167139
168-
If a database or view index file is smaller than this value (in bytes),
169-
compaction will not happen. Very small files always have high
170-
fragmentation, so compacting them is inefficient. ::
140+
Each item must have a priority lower than this to be enqueued. Defaults
141+
to infinity.
171142

172-
[compaction_daemon]
173-
min_file_size = 131072
143+
.. config:option:: max_size
174144
175-
.. config:option:: snooze_period_ms
145+
The item must be no larger than this many bytes in length to be
146+
enqueued. Defaults to infinity.
176147

177-
With lots of databases and/or with lots of design docs in one or more
178-
databases, the compaction_daemon can create significant CPU load when
179-
checking whether databases and view indexes need compacting. The
180-
``snooze_period_ms`` setting ensures a smoother CPU load. Defaults to
181-
3000 milliseconds wait.
148+
.. config:option:: min_priority
182149
183-
[compaction_daemon]
184-
snooze_period_ms = 3000
150+
The item must have a priority at least this high to be enqueued.
151+
Defaults to 5.0 for ratio and 16 MB for slack.
185152

186-
.. _config/view_compaction:
153+
.. config:option:: min_changes
187154
188-
Views Compaction Options
189-
========================
155+
The minimum number of changes since last compaction before the item will
156+
be enqueued. Defaults to 0. Currently only works for databases.
190157

191-
.. config:section:: view_compaction :: Views Compaction Options
158+
.. config:option:: min_size
192159
193-
.. config:option:: keyvalue_buffer_size :: Key-Values buffer size
160+
The item must be at least this many bytes in length to be enqueued.
161+
Defaults to 1mb (1048576 bytes).
194162

195-
Specifies maximum copy buffer size in bytes used during compaction::
163+
.. config:option:: priority
196164
197-
[view_compaction]
198-
keyvalue_buffer_size = 2097152
165+
The method used to calculate priority. Can be ratio (calculated as
166+
`sizes.file/sizes.active`) or slack (calculated as `sizes.file -
167+
sizes.active`). Defaults to ratio.

src/config/services.rst

-7
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ CouchDB Daemonized Mini Apps
3232
[daemons]
3333
auth_cache={couch_auth_cache, start_link, []}
3434

35-
.. config:option:: compaction_daemon
36-
37-
:ref:`Automatic compaction <config/compactions>` daemon::
38-
39-
[daemons]
40-
compaction_daemon={couch_compaction_daemon, start_link, []}
41-
4235
.. config:option:: external_manager
4336
4437
`External` processes manager::

0 commit comments

Comments
 (0)