@@ -8,226 +8,71 @@ In-memory storage
8
8
In Tarantool, all data is stored in random-access memory (RAM) by default.
9
9
For this purpose, the :ref: `memtx <engines-memtx >` storage engine is used.
10
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 >`.
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 >`.
13
16
14
17
.. NOTE ::
15
18
16
- To calculate the required amount of memory, you can use the
19
+ To estimate the required amount of memory, you can use the
17
20
`sizing calculator <https://www.tarantool.io/en/sizing_calculator/ >`_.
18
21
19
22
.. _configuration_memtx-memory :
20
23
21
- Configure the memory size
22
- -------------------------
24
+ Memory size
25
+ -----------
23
26
24
27
In Tarantool, data is stored in spaces.
25
28
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.
28
31
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):
35
33
36
34
.. literalinclude :: /code_snippets/snippets/config/instances.enabled/memtx/config.yaml
37
35
:language: yaml
38
36
:start-at: memtx:
39
- :end-at: 100000000
37
+ :end-at: 1073741824
40
38
:dedent:
41
39
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.
50
42
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 >`.
54
45
55
- * `` small `` (default) -- a ` slab allocator < https://github.com/tarantool/small >`_ mechanism is used.
46
+ .. _ configuration_memtx-tuple-size :
56
47
57
- The example below shows how to specify the ``small `` allocator type:
48
+ Tuple size
49
+ ----------
58
50
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.
66
52
67
- Specify the size limitations of the allocation unit
68
- ---------------------------------------------------
53
+ .. _configuration_memtx-tuple-size-min :
69
54
70
- You can configure the sizes of the smallest and the largest units to allocate.
55
+ Minimum size
56
+ ~~~~~~~~~~~~~
71
57
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:
75
59
76
60
.. literalinclude :: /code_snippets/snippets/config/instances.enabled/memtx/config.yaml
77
61
:language: yaml
78
62
:start-at: min_tuple_size: 8
79
63
:end-at: min_tuple_size: 8
80
64
:dedent:
81
65
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 :
136
67
137
- Set the number of the sorting threads
138
- -------------------------------------
68
+ Maximum size
69
+ ~~~~~~~~~~~~
139
70
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:
145
73
146
74
.. literalinclude :: /code_snippets/snippets/config/instances.enabled/memtx/config.yaml
147
75
:language: yaml
148
- :start-at: sort_threads :
149
- :end-at: 256
76
+ :start-at: max_tuple_size :
77
+ :end-at: 5242880
150
78
: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
- ...
0 commit comments