Skip to content

Commit d113f81

Browse files
committed
memtx: apply review suggestions
1 parent a415f14 commit d113f81

File tree

5 files changed

+193
-346
lines changed

5 files changed

+193
-346
lines changed

doc/code_snippets/snippets/config/instances.enabled/memtx/config.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
memtx:
2-
memory: 100000000
3-
allocator: 'small'
2+
memory: 1073741824
43
min_tuple_size: 8
5-
max_tuple_size: 1048576
6-
slab_alloc_factor: 1.05
7-
slab_alloc_granularity: 8
8-
sort_threads: 256
4+
max_tuple_size: 5242880
95

106
groups:
117
group001:

doc/concepts/atomic/thread_model.rst

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,18 @@ 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 ``memtx`` database.
7976

80-
.. note::
77+
.. NOTE::
8178

82-
The maximum number of OpenMP threads can be controlled by the ``OMP_NUM_THREADS`` environment variable.
79+
Since: :doc:`3.0.0 </release/3.0.0>`, this option replaces the approach when OpenMP threads are used to parallelize sorting.
80+
For backward compatibility, the ``OMP_NUM_THREADS`` environment variable is still supported in Tarantool 3.0.
81+
The variable defines the maximum number of OpenMP threads.

doc/concepts/configuration/configuration_memtx.rst

Lines changed: 31 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -8,226 +8,71 @@ In-memory storage
88
In Tarantool, all data is stored in random-access memory (RAM) by default.
99
For this purpose, the :ref:`memtx <engines-memtx>` storage engine is used.
1010

11-
This topic describes how to define settings related to in-memory storage in the
12-
:ref:`memtx <configuration_reference_memtx>` section of a :ref:`YAML configuration <configuration>`.
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>`.
1316

1417
.. NOTE::
1518

16-
To calculate the required amount of memory, you can use the
19+
To estimate the required amount of memory, you can use the
1720
`sizing calculator <https://www.tarantool.io/en/sizing_calculator/>`_.
1821

1922
.. _configuration_memtx-memory:
2023

21-
Configure the memory size
22-
-------------------------
24+
Memory size
25+
-----------
2326

2427
In Tarantool, data is stored in spaces.
2528
Each space consists of tuples -- the database records.
26-
To specify the amount of memory that Tarantool allocates to actually store tuples, use the
27-
:ref:`memtx.memory <configuration_reference_snapshot_dir>` configuration option.
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.
2831

29-
In the example below, the memory size is 100000000 bytes, which is about 95 MB.
30-
The server does not exceeds this limit to allocate tuples.
31-
For indexes and connection information, the additional memory is used.
32-
33-
When the ``memtx.memory`` limit is reached, ``INSERT`` or ``UPDATE`` requests fail with
34-
:ref:`ER_MEMORY_ISSUE <admin-troubleshoot-memory-issues>`.
32+
In the example below, the memory size is set to 1 GB (1073741824 bytes):
3533

3634
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/memtx/config.yaml
3735
:language: yaml
3836
:start-at: memtx:
39-
:end-at: 100000000
37+
:end-at: 1073741824
4038
:dedent:
4139

42-
.. _configuration_memtx-allocator:
43-
44-
Specify the allocator type
45-
--------------------------
46-
47-
The allocators are the memory managers used for different purposes.
48-
To set the allocator type that manages memory for ``memtx`` tuples, use the :ref:`memtx.allocator <configuration_reference_memtx_allocator>`
49-
configuration option.
40+
The server does not exceed this limit to allocate tuples.
41+
For indexes and connection information, additional memory is used.
5042

51-
Possible types:
52-
53-
* ``system`` -- the memory is allocated as needed, checking that the quota is not exceeded.
43+
When the ``memtx.memory`` limit is reached, ``INSERT`` or ``UPDATE`` requests fail with
44+
:ref:`ER_MEMORY_ISSUE <admin-troubleshoot-memory-issues>`.
5445

55-
* ``small`` (default) -- a `slab allocator <https://github.com/tarantool/small>`_ mechanism is used.
46+
.. _configuration_memtx-tuple-size:
5647

57-
The example below shows how to specify the ``small`` allocator type:
48+
Tuple size
49+
----------
5850

59-
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/memtx/config.yaml
60-
:language: yaml
61-
:start-at: allocator:
62-
:end-at: 'small'
63-
:dedent:
64-
65-
.. _configuration_memtx-min-max:
51+
You can configure the sizes of the smallest and the largest units to allocate.
6652

67-
Specify the size limitations of the allocation unit
68-
---------------------------------------------------
53+
.. _configuration_memtx-tuple-size-min:
6954

70-
You can configure the sizes of the smallest and the largest units to allocate.
55+
Minimum size
56+
~~~~~~~~~~~~~
7157

72-
To set the minimum size in bytes, use the :ref:`memtx.min_tuple_size <configuration_reference_memtx_min_size>` configuration option.
73-
The setting can be useful if the tuples that you store are small.
74-
The minimum size is a value between 8 and 1048280 inclusive.
58+
To set the minimum size in bytes, use the :ref:`memtx.min_tuple_size <configuration_reference_memtx_min_size>` configuration option:
7559

7660
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/memtx/config.yaml
7761
:language: yaml
7862
:start-at: min_tuple_size: 8
7963
:end-at: min_tuple_size: 8
8064
:dedent:
8165

82-
To set the maximum size in bytes, use the :ref:`memtx.max_tuple_size <configuration_reference_memtx_max_size>` configuration option.
83-
The setting can be useful if the tuples that you store are large.
84-
85-
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/memtx/config.yaml
86-
:language: yaml
87-
:start-at: max_tuple_size:
88-
:end-at: 1048576
89-
:dedent:
90-
91-
92-
.. _configuration_memtx-slab-alloc-granularity:
93-
94-
Specify the granularity for slab allocation
95-
-------------------------------------------
96-
97-
If you use the :ref:`small <configuration_reference_memtx_allocator>` type of allocator, you can set the granularity of
98-
memory allocation in it.
99-
To do it, use the :ref:`memtx.slab_alloc_granularity <configuration_reference_memtx_slab_alloc_granularity>` configuration option.
100-
The granularity value should meet the following conditions:
101-
102-
* The value is a power of two.
103-
* The value is greater than or equal to 4.
104-
105-
If the tuples in space are small and have about the same size, set the option to 4 bytes to save memory.
106-
If the tuples are different-sized, increase the option value to allocate tuples from the same ``mempool`` (memory pool).
107-
108-
In the example below, the value is increased to store different-sized tuples:
109-
110-
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/memtx/config.yaml
111-
:language: yaml
112-
:start-at: slab_alloc_granularity:
113-
:end-at: 8
114-
:dedent:
115-
116-
.. _configuration_memtx-slab-alloc-factor:
117-
118-
Specify the slab allocation factor
119-
----------------------------------
120-
121-
The size and number of memory pools depends on allocation factor and granularity.
122-
The allocation factor is a multiplier used to calculate the sizes of memory chunks that tuples are stored in.
123-
To configure the allocation factor, use the :ref:`memtx.slab_alloc_factor <configuration_reference_memtx_slab_alloc_factor>`
124-
configuration option.
125-
The option is a value between 1 and 2.
126-
127-
In the example below, the option is set to the default value:
128-
129-
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/memtx/config.yaml
130-
:language: yaml
131-
:start-at: slab_alloc_factor:
132-
:end-at: 1.05
133-
:dedent:
134-
135-
.. _configuration_memtx-sort-threads:
66+
.. _configuration_memtx-tuple-size-max:
13667

137-
Set the number of the sorting threads
138-
-------------------------------------
68+
Maximum size
69+
~~~~~~~~~~~~
13970

140-
It is possible to configure the number of threads that are used to sort keys of secondary indexes on loading
141-
``memtx`` database.
142-
To do it, use the :ref:`memtx.sort_threads <configuration_reference_memtx_sort_threads>` configuration option.
143-
144-
In the example, the maximum number of threads is used (256):
71+
To set the maximum size in bytes, use the :ref:`memtx.max_tuple_size <configuration_reference_memtx_max_size>` configuration option.
72+
In the example, the maximum size is set to 5 MB:
14573

14674
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/memtx/config.yaml
14775
:language: yaml
148-
:start-at: sort_threads:
149-
:end-at: 256
76+
:start-at: max_tuple_size:
77+
:end-at: 5242880
15078
:dedent:
151-
152-
.. _configuration_memtx-statistics:
153-
154-
Check the database statistics
155-
-----------------------------
156-
157-
Tarantool provides the statistics about memory consumption for the given space or specific tuples.
158-
Available statistics:
159-
160-
* The amount of memory used for the :ref:`data of the specified space <configuration_memtx-statistics-space>`.
161-
* The amount of :ref:`additional memory <configuration_memtx-statistics-additional>` used for the supplementary information.
162-
* The :ref:`total memory usage <configuration_memtx-statistics-total>`.
163-
164-
.. _configuration_memtx-statistics-space:
165-
166-
Space
167-
~~~~~
168-
169-
To get the get the amount of memory in bytes occupied by the specified space, use the :ref:`space_object:bsize() <box_space-bsize>` method.
170-
The function returns the total number of bytes in all tuples.
171-
172-
.. code-block:: console
173-
174-
memtx:instance001> box.space.books:bsize()
175-
---
176-
- 70348673
177-
...
178-
179-
.. _configuration_memtx-statistics-additional:
180-
181-
Additional memory
182-
~~~~~~~~~~~~~~~~~
183-
184-
To check the usage of the additional memory, use the ``space_object:stat()`` method.
185-
The following information is provided:
186-
187-
- ``header_size`` and ``field_map_size``: the size of service information.
188-
- ``data_size``: the actual size of data, which equals to ``space_object:bsize()``.
189-
- ``waste_size``: the size of memory wasted due to internal fragmentation in the `slab allocator <https://github.com/tarantool/small>`_.
190-
191-
.. code-block:: console
192-
193-
memtx:instance001> box.space.books:stat()
194-
---
195-
- tuple:
196-
memtx:
197-
waste_size: 1744011
198-
data_size: 70348673
199-
header_size: 2154132
200-
field_map_size: 0
201-
malloc:
202-
waste_size: 0
203-
data_size: 0
204-
header_size: 0
205-
field_map_size: 0
206-
...
207-
208-
To get the usage of the additional memory (5 Mb) for the specified tuple, use ``tuple_object:info()``:
209-
210-
.. code-block:: console
211-
212-
memtx:instance001> box.space.books:get('1853260622'):info()
213-
---
214-
- data_size: 277
215-
waste_size: 9
216-
arena: memtx
217-
field_map_size: 0
218-
header_size: 10
219-
...
220-
221-
.. _configuration_memtx-statistics-total:
222-
223-
Total memory usage
224-
~~~~~~~~~~~~~~~~~~
225-
226-
To get the total memory usage in bytes for the slab allocator, use the :ref:`box.slab.info() <box_slab_info>` function:
227-
228-
.. code-block:: console
229-
230-
memtx:instance001> box.slab.info().items_used
231-
---
232-
- 75302024
233-
...

doc/reference/configuration/cfg_storage.rst

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
Since version 1.7.4.
2424

25-
How much memory Tarantool allocates to actually store tuples.
25+
How much memory Tarantool allocates to store tuples.
2626
When the limit is reached, :ref:`INSERT <box_space-insert>` or
2727
:ref:`UPDATE <box_space-insert>` requests begin failing with
2828
error :errcode:`ER_MEMORY_ISSUE`. The server does not go beyond the
@@ -43,7 +43,6 @@
4343

4444
Size of the largest allocation unit, for the memtx storage engine. It can be
4545
increased if it is necessary to store large tuples.
46-
See also: :ref:`vinyl_max_tuple_size <cfg_storage-vinyl_max_tuple_size>`.
4746

4847
| Type: integer
4948
| Default: 1024 * 1024 = 1048576 bytes
@@ -57,11 +56,11 @@
5756
Since version 1.7.4.
5857

5958
Size of the smallest allocation unit. It can be decreased if most
60-
of the tuples are very small. The value must be between 8 and 1048280
61-
inclusive.
59+
of the tuples are very small.
6260

6361
| Type: integer
6462
| Default: 16 bytes
63+
| Possible values: between 8 and 1048280 inclusive
6564
| Environment variable: TT_MEMTX_MIN_TUPLE_SIZE
6665
| Dynamic: no
6766
@@ -71,13 +70,13 @@
7170

7271
Since version :doc:`2.10.0 </release/2.10.0>`.
7372

74-
Specify the allocator used for memtx tuples.
75-
The possible values are ``system`` and ``small``:
73+
Specify the allocator that manages memory for ``memtx`` tuples.
74+
Possible values:
7675

77-
* ``system`` is based on the ``malloc`` function.
78-
The allocator allocates memory as needed, checking that the quota is not exceeded.
76+
* ``system`` -- the memory is allocated as needed, checking that the quota is not exceeded.
77+
THe allocator is based on the ``malloc`` function.
7978

80-
* ``small`` is a special `slab allocator <https://github.com/tarantool/small>`_.
79+
* ``small`` -- a `slab allocator <https://github.com/tarantool/small>`_.
8180
The allocator repeatedly uses a memory block to allocate objects of the same type.
8281
Note that this allocator is prone to unresolvable fragmentation on specific workloads,
8382
so you can switch to ``system`` in such cases.
@@ -91,6 +90,8 @@
9190

9291
.. confval:: memtx_sort_threads
9392

93+
Since: :doc:`3.0.0 </release/3.0.0>`.
94+
9495
The number of threads used to sort keys of secondary indexes on loading ``memtx`` database.
9596
The maximum value is 256, the minimum value is 1.
9697
The default is to use all available cores.
@@ -108,12 +109,13 @@
108109
The multiplier for computing the sizes of memory
109110
chunks that tuples are stored in. A lower value may result in less wasted
110111
memory depending on the total amount of memory available and the
111-
distribution of item sizes. Allowed values range from 1 to 2.
112+
distribution of item sizes.
112113

113114
See also: :ref:`slab_alloc_granularity <cfg_storage-slab_alloc_granularity>`
114115

115116
| Type: float
116117
| Default: 1.05
118+
| Possible values: between 1 and 2 inclusive
117119
| Environment variable: TT_SLAB_ALLOC_FACTOR
118120
| Dynamic: no
119121
@@ -124,13 +126,15 @@
124126
Since version :doc:`2.8.1 </release/2.8.1>`.
125127

126128
Specify the granularity (in bytes) of memory allocation in the :ref:`small allocator <cfg_storage-memtx_allocator>`.
127-
The value of ``slab_alloc_granularity`` should be a power of two and should be greater than or equal to 4.
128-
Below are few recommendations on how to adjust the ``slab_alloc_granularity`` value:
129+
The ``memtx.slab_alloc_granularity`` value should meet the following conditions:
130+
131+
* The value is a power of two.
132+
* The value is greater than or equal to 4.
129133

130-
* To store small tuples of approximately the same size, set ``slab_alloc_granularity`` to 4 bytes to save memory.
134+
Below are few recommendations on how to adjust the ``memtx.slab_alloc_granularity`` option:
131135

132-
* To store tuples of different sizes, you can increase the ``slab_alloc_granularity`` value.
133-
This results in allocating tuples from the same ``mempool``.
136+
* If the tuples in space are small and have about the same size, set the option to 4 bytes to save memory.
137+
* If the tuples are different-sized, increase the option value to allocate tuples from the same ``mempool`` (memory pool).
134138

135139
See also: :ref:`slab_alloc_factor <cfg_storage-slab_alloc_factor>`
136140

0 commit comments

Comments
 (0)