Identifying and Reducing Memory Usage
On this page
SingleStore maintains a detailed account of memory usage.
Query the MV_ information schema view or run the SHOW STATUS EXTENDED command to view memory usage.
MV_ MEMORY_ USAGE
The MV_MV_ to monitor and identify the most significant memory consumers, including running processes, tables in memory, or internal data structures of running queries.
Introductory Example
This example shows how to use MV_ to break down and understand memory usage at a fine-grained level.
In MV_, groups and sub-groups provide a memory usage hierarchy.
Memory usages (ALLOC_s) with the same ID are disjoint and can be aggregated.
Note
Do not aggregate across different groups (different IDs).
The following query displays the total amount of memory used on node 1.GROUP_ indicates the ALLOC_ Total_, which displays total memory used by the server.
SELECT *FROM information_schema.MV_MEMORY_USAGEWHERE NODE_ID = 1AND GROUP_ID = 1;
*** 1. row ***
NODE_ID: 1
ALLOC_BYTES: 298188800
ALLOC_PROFILE: Total_server_memory
OWNER: {"SERVER":"MEMSQLD"}
OWNER_TYPE: SERVER
GROUP_ID: 1
SUBGROUP_IDS: {"subgroup_ids":[10]}
AGGREGATE_COUNT: 1To obtain a breakdown of the total memory used by the server (Total_), use the IDs from the SUBGROUP_ field.
The following query uses the predicate GROUP_, where 10 is from the SUBGROUP_ from the preceding query, to show memory usage for each of those subgroups.
The ORDER BY ALLOC_ clause sorts by memory usage to identify the top memory users.
SELECT *FROM information_schema.MV_MEMORY_USAGEWHERE NODE_ID = 1AND GROUP_ID = 10ORDER BY ALLOC_BYTES DESCLIMIT 3;
*** 1. row ***
NODE_ID: 1
ALLOC_BYTES: 159776768
ALLOC_PROFILE: Total_tracked_mmap_memory
OWNER: {"SERVER":"MEMSQLD"}
OWNER_TYPE: SERVER
GROUP_ID: 10
SUBGROUP_IDS: NULL
AGGREGATE_COUNT: 1
*** 2. row ***
NODE_ID: 1
ALLOC_BYTES: 69638456
ALLOC_PROFILE: Malloc_active_memory
OWNER: {"SERVER":"MEMSQLD"}
OWNER_TYPE: SERVER
GROUP_ID: 10
SUBGROUP_IDS: {"subgroup_ids":[500]}
AGGREGATE_COUNT: 1
*** 3. row ***
NODE_ID: 1
ALLOC_BYTES: 60948480
ALLOC_PROFILE: Buffer_manager_memory
OWNER: {"SERVER":"MEMSQLD"}
OWNER_TYPE: SERVER
GROUP_ID: 10
SUBGROUP_IDS: {"subgroup_ids":[200]}
AGGREGATE_COUNT: 1To break down memory used by Malloc_, query the subgroup of Malloc_, ID 500, using the following query.
SELECT *FROM information_schema.MV_MEMORY_USAGEWHERE NODE_ID = 1AND GROUP_ID = 500ORDER BY ALLOC_BYTES DESC;
To break down memory used by Buffer_, query the subgroup of Buffer_, ID 200, using the following query.
SELECT *FROM information_schema.MV_MEMORY_USAGEWHERE NODE_ID = 1AND GROUP_ID = 200ORDER BY ALLOC_BYTES DESC;
Important
It is acceptable to aggregate memory groups with the same ID.
Remarks
-
The value of
ALLOC_may be negative.BYTES A negative ALLOC_indicates the entity has freed memory that was allocated by other threads.BYTES A garbage collector is an example of an entity that frees memory allocated by other threads. -
Refer to MV_
MEMORY_ USAGE for additional information.
Groups
The following query lists the ALLOC_s and their group ID.
SELECT GROUP_CONCAT(DISTINCT ALLOC_PROFILE) AS AllocProfileList, GROUP_IDFROM information_schema.MV_MEMORY_USAGEGROUP BY GROUP_IDORDER BY GROUP_ID;
Examples
Example 1 - Find Total Memory Usage by Node
Find the total memory usage (Total_) of each node in a cluster using the following query.GROUP_ indicates Total_.
SELECT *FROM information_schema.MV_MEMORY_USAGEWHERE GROUP_ID = 1;
*** 1. row ***
NODE_ID: 1
ALLOC_BYTES: 219938816
ALLOC_PROFILE: Total_server_memory
OWNER: {"SERVER":"MEMSQLD"}
OWNER_TYPE: SERVER
GROUP_ID: 1
SUBGROUP_IDS: {"subgroup_ids":[10]}
AGGREGATE_COUNT: 1
*** 2. row ***
NODE_ID: 2
ALLOC_BYTES: 221380608
ALLOC_PROFILE: Total_server_memory
OWNER: {"SERVER":"MEMSQLD"}
OWNER_TYPE: SERVER
GROUP_ID: 1
SUBGROUP_IDS: {"subgroup_ids":[10]}
AGGREGATE_COUNT: 1
*** 3. row ***
NODE_ID: 3
ALLOC_BYTES: 221380608
ALLOC_PROFILE: Total_server_memory
OWNER: {"SERVER":"MEMSQLD"}
OWNER_TYPE: SERVER
GROUP_ID: 1
SUBGROUP_IDS: {"subgroup_ids":[10]}
AGGREGATE_COUNT: 1Example 2 - Find Top Types of Memory Usage by Node
Example 1 shows the total memory used by node.
In Example 1, group 10 is shown as the subgroup of group 1 (Total_).GROUP_) to show a breakdown of the results from Example 1.
SELECT *FROM information_schema.MV_MEMORY_USAGEWHERE GROUP_ID = 10ORDER BY NODE_ID, ALLOC_BYTES DESC;
+---------+-------------+---------------------------+----------------------+------------+----------+------------------------+-----------------+
| NODE_ID | ALLOC_BYTES | ALLOC_PROFILE | OWNER | OWNER_TYPE | GROUP_ID | SUBGROUP_IDS | AGGREGATE_COUNT |
+---------+-------------+---------------------------+----------------------+------------+----------+------------------------+-----------------+
| 1 | 177995776 | Total_tracked_mmap_memory | {"SERVER":"MEMSQLD"} | SERVER | 10 | NULL | 1 |
| 1 | 27131904 | Buffer_manager_memory | {"SERVER":"MEMSQLD"} | SERVER | 10 | {"subgroup_ids":[200]} | 1 |
| 1 | 10069424 | Malloc_active_memory | {"SERVER":"MEMSQLD"} | SERVER | 10 | {"subgroup_ids":[500]} | 1 |
| 1 | 7340032 | Total_thread_stack_memory | {"SERVER":"MEMSQLD"} | SERVER | 10 | NULL | 1 |
| 1 | 786432 | Total_io_pool_memory | {"SERVER":"MEMSQLD"} | SERVER | 10 | NULL | 1 |
| 2 | 177340416 | Total_tracked_mmap_memory | {"SERVER":"MEMSQLD"} | SERVER | 10 | NULL | 1 |
| 2 | 28049408 | Buffer_manager_memory | {"SERVER":"MEMSQLD"} | SERVER | 10 | {"subgroup_ids":[200]} | 1 |
| 2 | 8393952 | Malloc_active_memory | {"SERVER":"MEMSQLD"} | SERVER | 10 | {"subgroup_ids":[500]} | 1 |
| 2 | 8388608 | Total_thread_stack_memory | {"SERVER":"MEMSQLD"} | SERVER | 10 | NULL | 1 |
| 2 | 786432 | Total_io_pool_memory | {"SERVER":"MEMSQLD"} | SERVER | 10 | NULL | 1 |
| 3 | 177340416 | Total_tracked_mmap_memory | {"SERVER":"MEMSQLD"} | SERVER | 10 | NULL | 1 |
| 3 | 28180480 | Buffer_manager_memory | {"SERVER":"MEMSQLD"} | SERVER | 10 | {"subgroup_ids":[200]} | 1 |
| 3 | 8388608 | Total_thread_stack_memory | {"SERVER":"MEMSQLD"} | SERVER | 10 | NULL | 1 |
| 3 | 8366984 | Malloc_active_memory | {"SERVER":"MEMSQLD"} | SERVER | 10 | {"subgroup_ids":[500]} | 1 |
| 3 | 655360 | Total_io_pool_memory | {"SERVER":"MEMSQLD"} | SERVER | 10 | NULL | 1 |
+---------+-------------+---------------------------+----------------------+------------+----------+------------------------+-----------------+Example 3 - Find Memory Usage by Node Using Aggregation
The following query aggregates memory usage for all items with ID 10.
This query demonstrates aggregation within a group.
SELECT NODE_ID, SUM(ALLOC_BYTES)FROM information_schema.MV_MEMORY_USAGEWHERE GROUP_ID = 10GROUP BY NODE_ID;
+---------+------------------+
| node_id | sum(ALLOC_BYTES) |
+---------+------------------+
| 1 | 221360784 |
| 3 | 221528896 |
| 2 | 221949104 |
+---------+------------------+Example 4 - Find the User Tables Using the Most Memory
Find the top two user tables that use the most memory on a particular node, node 1 in this example.
SELECT *FROM information_schema.MV_MEMORY_USAGEWHERE NODE_ID = 1 AND OWNER_TYPE LIKE 'USER_TABLE'ORDER BY ALLOC_BYTES DESC LIMIT 2;
+---------+-------------+-------------------------+------------------------------------------+------------+----------+--------------+-----------------+
| NODE_ID | ALLOC_BYTES | ALLOC_PROFILE | OWNER | OWNER_TYPE | GROUP_ID | SUBGROUP_IDS | AGGREGATE_COUNT |
+---------+-------------+-------------------------+------------------------------------------+------------+----------+--------------+-----------------+
| 1 | 8519680 | Buffer_memory_for_table | {"DATABASE":"XDB_0","TABLE":"my_table2"} | USER_TABLE | 400 | NULL | 1 |
| 1 | 7208960 | Buffer_memory_for_table | {"DATABASE":"XDB_0","TABLE":"Xtab1"} | USER_TABLE | 400 | NULL | 1 |
+---------+-------------+-------------------------+------------------------------------------+------------+----------+--------------+-----------------+Example 5 - Find the Top Three Malloc Memory Users
Find the top three tasks or processes that are using the most Malloc memory on node 1.
SELECT NODE_ID, ALLOC_BYTES, OWNER
FROM information_schema.MV_MEMORY_USAGE
WHERE ALLOC_PROFILE LIKE 'Malloc'
AND NODE_ID = 1
ORDER BY ALLOC_BYTES DESC LIMIT 3;+---------+-------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| NODE_ID | ALLOC_BYTES | OWNER |
+---------+-------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 1 | 161122592 | {"ACTIVITY":"memsqld_main","ACTIVITY_TRACKING_ID":null,"AGGREGATOR_ACTIVITY":"memsqld_main","DATABASE":null,"RAW_TASK":null,"THREAD_ID":1176552,"TYPE":"System"} |
| 1 | 17881984 | {"ACTIVITY":"Unclassified_malloc_total","ACTIVITY_TRACKING_ID":null,"AGGREGATOR_ACTIVITY":null,"DATABASE":null,"RAW_TASK":null,"THREAD_ID":-1,"TYPE":null} |
| 1 | 185888 | {"ACTIVITY":"ReplLogContainer::BottomlessUploadLogChunksThreadFn","ACTIVITY_TRACKING_ID":null,"AGGREGATOR_ACTIVITY":"ReplLogContainer::BottomlessUploadLogChunksThreadFn","DATABASE":null,"RAW_TASK":null,"THREAD_ID":1176585,"TYPE":"System"} |
+---------+-------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+SHOW STATUS EXTENDED
The SHOW STATUS EXTENDED command displays a list of engine variable values as described in the following sections.
Summary variables
The following summary variables describe overall memory usage.
Total_ server_ memory
Total_ tracks the server’s overall memory use.maximum_.Total_ reaches maximum_, memory allocations start failing.1712 - "Not enough memory available to complete the current request.
In addition, the trace log shows the following: "Nonfatal buffer manager memory allocation failure.
Alloc_ table_ memory
Alloc_ tracks the memory stored inside of all rowstore tables (memory for rows, indexes, variable-length columns like VARCHAR or JSON that are stored off row).Alloc_ reaches maximum_, INSERT, UPDATE, and LOAD DATA operations against the tables receive the following error: 1720 - "Memory usage by SingleStore for tables (XXXXX MB) has reached the value of 'maximum_.
Buffer_ manager_ memory
Buffer_ tracks memory that is allocated by the Buffer Manager for SingleStore’s built-in memory allocators.Buffer_ to be a large percentage of Total_.
Buffer_ manager_ cached_ memory
Buffer_ tracks cached memory blocks allocated by the Buffer Manager that are currently not in use, but still mapped.Buffer_ reflects the memory that may still be referenced until the check is complete.
While Total_ is at or below 90% of maximum_ or at least 10 GB of free memory remains, Buffer_ is capped at 25% of maximum_ on each node.maximum_.
When Total_ is above 90% of maximum_ and less than 10 GB of free memory remains, newly freed buffers are cached only until the cache size reaches approximately 1% of maximum_ (vs.
As cached memory stays mapped, Total_ includes Buffer_.DELETE, Alloc_ can fall while Total_ stays high because the freed memory blocks are still held as unrecycled or cached memory.
Refer to buffer_
Alloc_ query_ execution
Alloc_ tracks memory allocated by currently executing queries for sorts, hash tables, result tables, etc.
Alloc_ variable
Alloc_ tracks memory allocated for variable-length columns inside rowstore tables, or for other variable-length memory allocations inside query execution (i.
Alloc_ vector_ index
Alloc_ specifies the total size of vector indexes currently residing in memory.
Row store variables
Row store has a set of allocators it uses for various part of an index.
Alloc_ skiplist_ towers
Alloc_ tracks memory used by the towers for skiplist indexes.
Alloc_ table_ primary
Alloc_ tracks memory used for on-row data for rowstore tables.VARCHAR, VARBINARY, BLOB, TEXT, JSON, etc).Alloc_ that was previously discussed in this topic.
Alloc_ deleted_ version
Alloc_ tracks memory used to mark rows as deleted in rowstore tables.DELETE queries in SingleStore don’t free up memory when they commit.
Alloc_ hash_ buckets
Alloc_ tracks memory used for HASH index buckets (by default 4 million buckets per index, which would use 32 MB).
Other variables
A few variables describe memory used by components that are not directly related to running queries or storing data.
Alloc_ replication
Alloc_ tracks the amount of memory used during replication.
Malloc_ active_ memory
Malloc_ tracks memory allocated directly from the Linux OS and managed by the C runtime allocators (not SingleStore’s built-in memory allocators that use the Buffer Manager).
Alloc_ thread_ stacks
Alloc_ tracks memory used by thread stacks.thread_ session variable, but SingleStore does not recommend changing this value.idle_ variable).
In this section
Last modified: