The memory usage of the TiKV process remains high in TiDB version 5.1

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: TIDB5.1版本tikv进程占用的内存居高不下。

| username: TiDBer_RQobNXGv

During this period, I manually restarted once, and the memory usage went down, but after a month, it went up again. The block cache is set to 6GB.

| username: Kongdom | Original post link

:thinking: Check the TopSQL on the Dashboard to see if there are any large SQL queries?

| username: TiDBer_RQobNXGv | Original post link

Do you think it’s a large SQL?

| username: TiDBer_小阿飞 | Original post link

You have mixed nodes here! The configuration is 1 PD, 1 TiDB, and 2 TiKV.

| username: TiDBer_RQobNXGv | Original post link

Yes, even with hybrid deployment, it’s strange that the TIKV process is consuming so much memory.

| username: Kongdom | Original post link

The first SQL, executing it twice per second? The execution frequency is a bit high.

I just noticed it’s a mixed deployment, and it’s a single server with 2 TiKV instances mixed. This can easily cause resource contention.

| username: Jolyne | Original post link

It looks like an SQL issue, or you can check the TopSQL in the dashboard. Additionally, mixed deployment can cause resource contention.

| username: 像风一样的男子 | Original post link

Your configuration resources are insufficient, consider scaling up. Don’t mix deployments; one server should have only one node.

| username: TiDBer_小阿飞 | Original post link

Has storage.block-cache taken effect? Versions prior to v6.6.0 only work when shared block cache is enabled.

[storage.block-cache]
Whether to create a shared block cache for all CFs of RocksDB.
RocksDB uses block cache to cache uncompressed data blocks. A larger block cache can speed up read operations.
It is recommended to enable the shared block cache parameter. This way, you only need to set the total cache size, making the configuration process more convenient.
In most cases, the LRU algorithm can automatically balance cache usage among different CFs.
The remaining configurations in the storage.block-cache session only take effect when shared block cache is enabled.
Starting from v6.6.0, this option is always enabled and cannot be disabled.

shared = true

The size of the shared block cache. Normally, it should be set to 30%-50% of the total system memory.
If this parameter is not set, it is determined by the sum of the following fields or their default values.

* rocksdb.defaultcf.block-cache-size or 25% of the total system memory

* rocksdb.writecf.block-cache-size or 15% of the total system memory

* rocksdb.lockcf.block-cache-size or 2% of the total system memory

* raftdb.defaultcf.block-cache-size or 2% of the total system memory

To deploy multiple TiKV nodes on a single physical machine, this parameter needs to be explicitly configured.

Otherwise, OOM errors may occur in TiKV.

capacity = “1GB”

| username: TiDBer_小阿飞 | Original post link

Note this sentence: ## To deploy multiple TiKV nodes on a single physical machine, you need to explicitly configure this parameter.

| username: dba远航 | Original post link

TiDB uses the LSM-Tree memory algorithm, which is inherently memory-intensive. If you want to reduce memory usage, you can adjust its parameters to flush memory to disk more quickly for persistence.

| username: TiDBer_RQobNXGv | Original post link

I have configured it.

| username: TiDBer_RQobNXGv | Original post link

Is there a problem?

| username: TiDBer_RQobNXGv | Original post link

My fifth node is a standalone TiKV, and its memory usage is also too high.

| username: oceanzhang | Original post link

Can you post the slow SQL here? Maybe the read/write load is too high???

| username: oceanzhang | Original post link

Is the issue resolved?

| username: TiDBer_RQobNXGv | Original post link

The image is not visible. Please provide the text you need translated.

| username: Kongdom | Original post link

Take a look at this to see if there are any hotspots.

| username: TiDBer_RQobNXGv | Original post link

The image is not visible. Please provide the text you need translated.

| username: dba远航 | Original post link

Take a look at this parameter, which adjusts memory writing to disk: max-write-buffer-number.