Skip to content

Commit e7a2d9d

Browse files
committed
memtx: add In-memory storage page
1 parent 36b5ee1 commit e7a2d9d

File tree

9 files changed

+304
-48
lines changed

9 files changed

+304
-48
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
memtx:
2+
memory: 100000000
3+
allocator: 'small'
4+
min_tuple_size: 8
5+
max_tuple_size: 1048576
6+
slab_alloc_factor: 1.05
7+
slab_alloc_granularity: 8
8+
sort_threads: 256
9+
10+
groups:
11+
group001:
12+
replicasets:
13+
replicaset001:
14+
instances:
15+
instance001:
16+
iproto:
17+
listen:
18+
- 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/configuration.rst

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

391391

392-
.. _configuration_options_access_control:
392+
.. _configuration_options_access_control:
393393

394394
Access control
395395
~~~~~~~~~~~~~~
@@ -406,22 +406,25 @@ In the example below, a ``dbadmin`` user with the specified password is created:
406406
To learn more, see the :ref:`configuration_credentials` section.
407407

408408

409-
.. _configuration_options_memory:
409+
.. _configuration_options_memory:
410410

411411
Memory
412412
~~~~~~
413413

414-
The ``memtx.memory`` option specifies how much :ref:`memory <engines-memtx>` Tarantool allocates to actually store data.
414+
The :ref:`memtx.memory <configuration_reference_memtx_memory>` option specifies how much :ref:`memory <engines-memtx>`
415+
Tarantool allocates to actually store data.
415416

416-
.. code-block:: yaml
417-
418-
memtx:
419-
memory: 100000000
417+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/memtx/config.yaml
418+
:language: yaml
419+
:start-at: memtx:
420+
:end-at: 100000000
421+
:dedent:
420422

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

425+
Learn more: :ref:`In-memory storage configuration <configuration_memtx>`.
423426

424-
.. _configuration_options_directories:
427+
.. _configuration_options_directories:
425428

426429
Snapshots and write-ahead logs
427430
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -442,14 +445,13 @@ To learn more about the persistence mechanism in Tarantool, see the :ref:`Persis
442445
Read more about snapshot and WAL configuration: :ref:`Persistence <configuration_persistence>`.
443446

444447

445-
446-
447448
.. toctree::
448449
:hidden:
449450

450451
configuration/configuration_etcd
451452
configuration/configuration_code
452453
configuration/configuration_persistence
454+
configuration/configuration_memtx
453455
configuration/configuration_connections
454456
configuration/configuration_credentials
455457
configuration/configuration_authentication
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
.. _configuration_memtx:
2+
3+
In-memory storage
4+
=================
5+
6+
**Example on GitHub**: `snapshot <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 settings related to in-memory storage in the
12+
:ref:`memtx <configuration_reference_memtx>` section of a :ref:`YAML configuration <configuration>`.
13+
14+
.. NOTE::
15+
16+
To calculate the required amount of memory, you can use the
17+
`sizing calculator <https://www.tarantool.io/en/sizing_calculator/>`_.
18+
19+
.. _configuration_memtx-memory:
20+
21+
Configure the memory size
22+
-------------------------
23+
24+
In Tarantool, data is stored in spaces.
25+
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.
28+
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>`.
35+
36+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/memtx/config.yaml
37+
:language: yaml
38+
:start-at: memtx:
39+
:end-at: 100000000
40+
:dedent:
41+
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.
50+
51+
Possible types:
52+
53+
* ``system`` -- the memory is allocated as needed, checking that the quota is not exceeded.
54+
55+
* ``small`` (default) -- a `slab allocator <https://github.com/tarantool/small>`_ mechanism is used.
56+
57+
The example below shows how to specify the ``small`` allocator type:
58+
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:
66+
67+
Specify the size limitations of the allocation unit
68+
---------------------------------------------------
69+
70+
You can configure the sizes of the smallest and the largest units to allocate.
71+
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.
75+
76+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/memtx/config.yaml
77+
:language: yaml
78+
:start-at: min_tuple_size: 8
79+
:end-at: min_tuple_size: 8
80+
:dedent:
81+
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+
The granularity value should meet the following conditions:
100+
101+
* The value is a power of two.
102+
* The value is greater than or equal to 4.
103+
104+
If the tuples in space are small and have about the same size, set the option to 4 bytes to save memory.
105+
If the tuples are different-sized, increase the option value to allocate tuples from the same ``mempool`` (memory pool).
106+
107+
In the example below, the value is increased to store different-sized tuples:
108+
109+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/memtx/config.yaml
110+
:language: yaml
111+
:start-at: slab_alloc_granularity:
112+
:end-at: 8
113+
:dedent:
114+
115+
.. _configuration_memtx-slab-alloc-factor:
116+
117+
Specify the slab allocation factor
118+
----------------------------------
119+
120+
The size and number of memory pools depends on allocation factor and granularity.
121+
The allocation factor is a multiplier used to calculate the sizes of memory chunks that tuples are stored in.
122+
To configure the allocation factor, use the :ref:`memtx.slab_alloc_factor <configuration_reference_memtx_slab_alloc_factor>`
123+
configuration option.
124+
The option is a value between 1 and 2.
125+
126+
In the example below, the option is set to the default value:
127+
128+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/memtx/config.yaml
129+
:language: yaml
130+
:start-at: slab_alloc_factor:
131+
:end-at: 1.05
132+
:dedent:
133+
134+
.. _configuration_memtx-sort-threads:
135+
136+
Set the number of the sorting threads
137+
-------------------------------------
138+
139+
It is possible to configure the number of threads that are used to sort keys of secondary indexes on loading
140+
``memtx`` database.
141+
To do it, use the :ref:`memtx.sort_threads <configuration_reference_memtx_sort_threads>` configuration option.
142+
143+
In the example, the maximum number of threads is used (256):
144+
145+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/memtx/config.yaml
146+
:language: yaml
147+
:start-at: sort_threads:
148+
:end-at: 256
149+
:dedent:
150+
151+
.. _configuration_memtx-statistics:
152+
153+
Check the database statistics
154+
-----------------------------
155+
156+
Tarantool provides the statistics about memory consumption for the given space or specific tuples.
157+
Available statistics:
158+
159+
* The amount of memory used for the data of the specified space.
160+
* The amount of additional memory used for the supplementary information.
161+
* The total memory usage.
162+
163+
.. _configuration_memtx-statistics-space:
164+
165+
Space
166+
~~~~~
167+
168+
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.
169+
The function returns the total number of bytes in all tuples.
170+
171+
.. code-block:: console
172+
173+
memtx:instance001> box.space.books:bsize()
174+
---
175+
- 70348673
176+
...
177+
178+
.. _configuration_memtx-statistics-additional:
179+
180+
Additional memory
181+
~~~~~~~~~~~~~~~~~
182+
183+
To check the usage of the additional memory (5 Mb), use the ``space_object:stat()`` method.
184+
The following information is provided:
185+
186+
- ``header_size`` and ``field_map_size``: the size of service information.
187+
- ``data_size``: the actual size of data, which equals to ``space_object:bsize()``.
188+
- ``waste_size``: the size of memory wasted due to internal fragmentation in the `slab allocator <https://github.com/tarantool/small>`_.
189+
190+
.. code-block:: console
191+
192+
memtx:instance001> box.space.books:stat()
193+
---
194+
- tuple:
195+
memtx:
196+
waste_size: 1744011
197+
data_size: 70348673
198+
header_size: 2154132
199+
field_map_size: 0
200+
malloc:
201+
waste_size: 0
202+
data_size: 0
203+
header_size: 0
204+
field_map_size: 0
205+
...
206+
207+
To get the usage of the additional memory (5 Mb) for the specified tuple, use ``tuple_object:info()``:
208+
209+
.. code-block:: console
210+
211+
memtx:instance001> box.space.books:get('1853260622'):info()
212+
---
213+
- data_size: 277
214+
waste_size: 9
215+
arena: memtx
216+
field_map_size: 0
217+
header_size: 10
218+
...
219+
220+
.. _configuration_memtx-statistics-total:
221+
222+
Total memory usage
223+
~~~~~~~~~~~~~~~~~~
224+
225+
To get the total memory usage in bytes for the slab allocator, use the :ref:`box.slab.info() <box_slab_info>` function:
226+
227+
.. code-block:: console
228+
229+
memtx:instance001> box.slab.info().items_used
230+
---
231+
- 75302024
232+
...

0 commit comments

Comments
 (0)