Skip to content

Commit 30125ad

Browse files
authored
[Config] Document 'memtx' configuration settings (#4038)
- Add `memtx` section in the Configuration reference - Add `memtx_sort_threads` option to the box.cfg reference and updated box.cfg reference - Add `In-memory storage` topic to the Configuration section - Update `Supplementary threads` topic and added a note about OpenMP threads deprecation - Fix some build warnings Fixes #4012 Fixes #3509
1 parent 16ccbe2 commit 30125ad

File tree

14 files changed

+317
-69
lines changed

14 files changed

+317
-69
lines changed

doc/book/box/limitations.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Limitations
7777
**Space size**
7878

7979
The total maximum size for all spaces is in effect set by
80-
:ref:`memtx_memory <cfg_storage-memtx_memory>`, which in turn
80+
:ref:`memtx.memory <configuration_reference_memtx_memory>`, which in turn
8181
is limited by the total available memory.
8282

8383
.. _limitations_update_ops:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
memtx:
2+
memory: 1073741824
3+
min_tuple_size: 8
4+
max_tuple_size: 5242880
5+
6+
groups:
7+
group001:
8+
replicasets:
9+
replicaset001:
10+
instances:
11+
instance001:
12+
iproto:
13+
listen:
14+
- uri: '127.0.0.1:3301'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
instance001:

doc/concepts/atomic/thread_model.rst

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,22 @@ Supplementary threads
6464

6565
There are also several supplementary threads that serve additional capabilities:
6666

67-
* For :ref:`replication <replication-architecture>`, Tarantool creates a separate thread for each connected replica.
68-
This thread reads a write-ahead log and sends it to the replica, following its position in the log.
69-
Separate threads are required because each replica can point to a different position in the log and can run at different speeds.
67+
* For :ref:`replication <replication-architecture>`, Tarantool creates a separate thread for each connected replica.
68+
This thread reads a write-ahead log and sends it to the replica, following its position in the log.
69+
Separate threads are required because each replica can point to a different position in the log and can run at different speeds.
7070

71-
* There is a thread pool for ad hoc asynchronous tasks,
72-
such as a DNS resolver or :ref:`fsync <configuration_reference_wal_mode>`.
71+
* There is a thread pool for ad hoc asynchronous tasks, such as a DNS resolver or :ref:`fsync <configuration_reference_wal_mode>`.
7372

74-
* There are OpenMP threads used to parallelize sorting
75-
(hence, to parallelize building :ref:`indexes <concepts-data_model_indexes>`).
76-
For example, this is applicable when Tarantool is restoring from a
77-
:ref:`snapshot <internals-snapshot>` with a large amount of data
78-
and needs to sort a secondary index if it is ordered by something other than the primary order.
73+
* There is a thread pool that can be used for parallel sorting (hence, to parallelize building :ref:`indexes <concepts-data_model_indexes>`).
74+
To configure it, use the :ref:`memtx.sort_threads <configuration_reference_memtx_sort_threads>` configuration option.
75+
The option sets the number of threads used to sort keys of secondary indexes on loading a ``memtx`` database.
7976

80-
.. note::
77+
.. note_drop_openmp_start
8178
82-
The maximum number of OpenMP threads can be controlled by the ``OMP_NUM_THREADS`` environment variable.
79+
.. NOTE::
80+
81+
Since :doc:`3.0.0 </release/3.0.0>`, this option replaces the approach when OpenMP threads are used to parallelize sorting.
82+
For backward compatibility, the ``OMP_NUM_THREADS`` environment variable is taken into account to
83+
set the number of sorting threads.
84+
85+
.. note_drop_openmp_end

doc/concepts/configuration.rst

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ The example below shows how to set a listening IP address for ``instance001`` to
393393
You can learn more from the :ref:`configuration_connections` topic.
394394

395395

396-
.. _configuration_options_access_control:
396+
.. _configuration_options_access_control:
397397

398398
Access control
399399
~~~~~~~~~~~~~~
@@ -410,22 +410,25 @@ In the example below, a ``dbadmin`` user with the specified password is created:
410410
To learn more, see the :ref:`configuration_credentials` section.
411411

412412

413-
.. _configuration_options_memory:
413+
.. _configuration_options_memory:
414414

415415
Memory
416416
~~~~~~
417417

418-
The ``memtx.memory`` option specifies how much :ref:`memory <engines-memtx>` Tarantool allocates to actually store data.
418+
The :ref:`memtx.memory <configuration_reference_memtx_memory>` option specifies how much :ref:`memory <engines-memtx>`
419+
Tarantool allocates to actually store data.
419420

420-
.. code-block:: yaml
421-
422-
memtx:
423-
memory: 100000000
421+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/memtx/config.yaml
422+
:language: yaml
423+
:start-at: memtx:
424+
:end-at: 1073741824
425+
:dedent:
424426

425427
When the limit is reached, ``INSERT`` or ``UPDATE`` requests fail with :ref:`ER_MEMORY_ISSUE <admin-troubleshoot-memory-issues>`.
426428

429+
Learn more: :ref:`In-memory storage configuration <configuration_memtx>`.
427430

428-
.. _configuration_options_directories:
431+
.. _configuration_options_directories:
429432

430433
Snapshots and write-ahead logs
431434
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -446,13 +449,12 @@ To learn more about the persistence mechanism in Tarantool, see the :ref:`Persis
446449
Read more about snapshot and WAL configuration: :ref:`Persistence <configuration_persistence>`.
447450

448451

449-
450-
451452
.. toctree::
452453
:hidden:
453454

454455
configuration/configuration_etcd
455456
configuration/configuration_code
457+
configuration/configuration_memtx
456458
configuration/configuration_persistence
457459
configuration/configuration_connections
458460
configuration/configuration_credentials

doc/concepts/configuration/configuration_code.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ In the :ref:`next section <configuration_code_iproto-encryption-config-sc>`, you
356356

357357
Example:
358358

359-
.. literalinclude:: /code_snippets/snippets/replication/instances.enabled/ssl/myapp.lua
359+
.. literalinclude:: /code_snippets/snippets/replication/instances.enabled/ssl_with_ca/myapp.lua
360360
:language: lua
361361
:start-at: net.box
362362
:end-before: return connection
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
.. _configuration_memtx:
2+
3+
In-memory storage
4+
=================
5+
6+
**Example on GitHub**: `memtx <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/config/instances.enabled/memtx>`_
7+
8+
In Tarantool, all data is stored in random-access memory (RAM) by default.
9+
For this purpose, the :ref:`memtx <engines-memtx>` storage engine is used.
10+
11+
This topic describes how to define basic settings related to in-memory storage in the
12+
:ref:`memtx <configuration_reference_memtx>` section of a :ref:`YAML configuration <configuration>`
13+
-- for example, :ref:`memory size <configuration_reference_memtx_memory>` and :ref:`maximum tuple size <configuration_reference_memtx_max_size>`.
14+
For the specific settings related to allocator or sorting threads,
15+
check the corresponding ``memtx`` options in the :ref:`Configuration reference <configuration_reference_memtx>`.
16+
17+
.. NOTE::
18+
19+
To estimate the required amount of memory, you can use the
20+
`sizing calculator <https://www.tarantool.io/en/sizing_calculator/>`_.
21+
22+
.. _configuration_memtx-memory:
23+
24+
Memory size
25+
-----------
26+
27+
In Tarantool, data is stored in spaces.
28+
Each space consists of tuples -- the database records.
29+
To specify the amount of memory that Tarantool allocates to store tuples, use the
30+
:ref:`memtx.memory <configuration_reference_memtx_memory>` configuration option.
31+
32+
In the example below, the memory size is set to 1 GB (1073741824 bytes):
33+
34+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/memtx/config.yaml
35+
:language: yaml
36+
:start-at: memtx:
37+
:end-at: 1073741824
38+
:dedent:
39+
40+
The server does not exceed this limit to allocate tuples.
41+
For indexes and connection information, additional memory is used.
42+
43+
When the ``memtx.memory`` limit is reached, ``INSERT`` or ``UPDATE`` requests fail with
44+
:ref:`ER_MEMORY_ISSUE <admin-troubleshoot-memory-issues>`.
45+
46+
.. _configuration_memtx-tuple-size:
47+
48+
Tuple size
49+
----------
50+
51+
You can configure the minimum and the maximum tuple sizes in bytes.
52+
53+
* If the tuples are small, you can decrease the minimum size.
54+
* If the tuples are large, you can increase the maximum size.
55+
56+
To define the tuple size, use the :ref:`memtx.min_tuple_size <configuration_reference_memtx_min_size>` and
57+
:ref:`memtx.max_tuple_size <configuration_reference_memtx_max_size>` configuration options.
58+
59+
In the example, the minimum size is set to 8 bytes and the maximum size is set to 5 MB:
60+
61+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/memtx/config.yaml
62+
:language: yaml
63+
:start-at: memtx:
64+
:end-at: 5242880
65+
:dedent:

doc/concepts/configuration/configuration_persistence.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ size. The configuration for this option might look as follows:
185185
:end-at: 268435456
186186
:dedent:
187187

188-
.. _configuration_persistence_wal_rescan:
188+
.. _configuration_persistence_cleanup_delay:
189189

190190
Set a delay for the garbage collector
191191
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

doc/concepts/engines/memtx.rst

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33
Storing data with memtx
44
=======================
55

6-
The ``memtx`` storage engine is used in Tarantool by default. It keeps all data in random-access memory (RAM), and therefore has very low read latency.
6+
The ``memtx`` storage engine is used in Tarantool by default.
7+
The engine keeps all data in random-access memory (RAM), and therefore has a low read latency.
78

8-
The obvious question here is:
9-
if all the data is stored in memory, how can you prevent the data loss in case of emergency such as outage or Tarantool instance failure?
9+
Tarantool prevents the data loss in case of emergency, such as outage or Tarantool instance failure, in the following ways:
1010

11-
First of all, Tarantool persists all data changes by writing requests to the write-ahead log (WAL) that is stored on disk.
12-
Read more about that in the :ref:`memtx-persist` section.
13-
In case of a distributed application, there is an option of synchronous replication that ensures keeping the data consistent on a quorum of replicas.
14-
Although replication is not directly a storage engine topic, it is a part of the answer regarding data safety. Read more in the :ref:`memtx-replication` section.
11+
* Tarantool persists all data changes by writing requests to the :ref:`write-ahead log <internals-wal>` (WAL)
12+
that is stored on disk. Also, Tarantool periodically takes the entire
13+
:doc:`database snapshot </reference/reference_lua/box_snapshot>` and saves it on disk.
14+
Learn more: :ref:`Data persistence <memtx-persist>`.
1515

16-
In this chapter, the following topics are discussed in brief with the references to other chapters that explain the subject matter in details.
16+
* In case of a distributed application, a synchronous replication is used to ensure keeping the data consistent on a quorum of replicas.
17+
Although replication is not directly a storage engine topic, it is a part of the answer regarding data safety.
18+
Learn more: :ref:`Replicating data <memtx-replication>`.
19+
20+
In this section, the following topics are discussed in brief with the references to other sections that explain the
21+
subject matter in details.
1722

1823
.. contents::
1924
:local:
@@ -43,7 +48,7 @@ Within the TX thread, there is a memory area allocated for Tarantool to store da
4348

4449
.. image:: memtx/arena2.svg
4550

46-
Data is stored in :term:`spaces <space>`. Spaces contain database records:term:`tuples <tuple>`.
51+
Data is stored in :term:`spaces <space>`. Spaces contain database records -- :term:`tuples <tuple>`.
4752
To access and manipulate the data stored in spaces and tuples, Tarantool builds :doc:`indexes </concepts/data_model/indexes>`.
4853

4954
Special `allocators <https://github.com/tarantool/small>`__ manage memory allocations for spaces, tuples, and indexes within the Arena.
@@ -52,43 +57,43 @@ Tarantool has a built-in module called ``box.slab`` which provides the slab allo
5257
that can be used to monitor the total memory usage and memory fragmentation.
5358
For more details, see the ``box.slab`` module :doc:`reference </reference/reference_lua/box_slab>`.
5459

55-
.. image:: memtx/spaces_indexes.svg
60+
.. image:: memtx/spaces_indexes.svg
5661

5762
Also inside the TX thread, there is an event loop. Within the event loop, there are a number of :ref:`fibers <fiber-fibers>`.
5863
Fibers are cooperative primitives that allow interaction with spaces, that is, reading and writing the data.
5964
Fibers can interact with the event loop and between each other directly or by using special primitives called channels.
6065
Due to the usage of fibers and :ref:`cooperative multitasking <app-cooperative_multitasking>`, the ``memtx`` engine is lock-free in typical situations.
6166

62-
.. image:: memtx/fibers-channels.svg
67+
.. image:: memtx/fibers-channels.svg
6368

6469
To interact with external users, there is a separate :ref:`network thread <thread_model>` also called the **iproto thread**.
6570
The iproto thread receives a request from the network, parses and checks the statement,
6671
and transforms it into a special structure—a message containing an executable statement and its options.
6772
Then the iproto thread ships this message to the TX thread and runs the user's request in a separate fiber.
6873

69-
.. image:: memtx/iproto.svg
74+
.. image:: memtx/iproto.svg
7075

7176
.. _memtx-persist:
7277

7378
Data persistence
7479
----------------
7580

76-
To ensure :ref:`data persistence <index-box_persistence>`, Tarantool does two things.
81+
Tarantool ensures :ref:`data persistence <index-box_persistence>` as follows:
7782

7883
* After executing data change requests in memory, Tarantool writes each such request to the :ref:`write-ahead log (WAL) <internals-wal>` files (``.xlog``)
7984
that are stored on disk. Tarantool does this via a separate thread called the **WAL thread**.
8085

81-
.. image:: memtx/wal.svg
86+
.. image:: memtx/wal.svg
8287

8388
* Tarantool periodically takes the entire :doc:`database snapshot </reference/reference_lua/box_snapshot>` and saves it on disk.
8489
It is necessary for accelerating instance's restart because when there are too many WAL files, it can be difficult for Tarantool to restart quickly.
8590

86-
To save a snapshot, there is a special fiber called the **snapshot daemon**.
91+
To save a snapshot, there is a special fiber called the :ref:`snapshot daemon <configuration_persistence_checkpoint_daemon>`.
8792
It reads the consistent content of the entire Arena and writes it on disk into a snapshot file (``.snap``).
8893
Due of the cooperative multitasking, Tarantool cannot write directly on disk because it is a locking operation.
8994
That is why Tarantool interacts with disk via a separate pool of threads from the :doc:`fio </reference/reference_lua/fio>` library.
9095

91-
.. image:: memtx/snapshot03.svg
96+
.. image:: memtx/snapshot03.svg
9297

9398
So, even in emergency situations such as an outage or a Tarantool instance failure,
9499
when the in-memory database is lost, the data can be restored fully during Tarantool restart.
@@ -150,7 +155,7 @@ For more information on replication, refer to the :ref:`corresponding chapter <r
150155
.. _memtx-summary:
151156

152157
Summary
153-
--------
158+
-------
154159

155160
The main key points describing how the in-memory storage engine works can be summarized in the following way:
156161

doc/enterprise/wal_extensions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ Inside the ``wal.ext`` block, you can enable storing old and new tuples as follo
2323
:ref:`wal.ext.old <configuration_reference_wal_ext_old>` and :ref:`wal.ext.new <configuration_reference_wal_ext_new>`
2424
options to ``true``:
2525

26-
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/persistence/config.yaml
26+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/persistence_wal/config.yaml
2727
:language: yaml
28-
:start-at: wal:
28+
:start-at: ext:
2929
:end-at: old: true
3030
:dedent:
3131

0 commit comments

Comments
 (0)