How to Analyze Memory Usage of tidb-server?

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

Original topic: 如何分析tidb-server的内存占用?

| username: DBRE

[TiDB Usage Environment] Production Environment

[TiDB Version] 5.2.3

[Encountered Problem: Phenomenon and Impact]
Our TiDB cluster has a dedicated tidb-server for backups, using dumpling for daily full backups at night. After a period of time, this tidb-server occupies tens of gigabytes or even over a hundred gigabytes of memory. Currently, this tidb-server has no connections, and the memory is not being released. How can we analyze the memory usage of this tidb-server? Is it a memory leak or some other reason? What are the solutions?

[Resource Configuration]
Server memory status:

[Attachments: Screenshots/Logs/Monitoring]

| username: BraveChen | Original post link

I suggest checking the TiDB logs to see what information is being written normally.

| username: DBRE | Original post link

The logs are basically related to TIME_COP_PROCESS.

| username: TiDBer_pkQ5q1l0 | Original post link

Capture it a few more times, then install the Graphviz tool and call it in cmd to check the memory usage.

| username: BraveChen | Original post link

Check this TiDB node separately to see if there are any SQL processes, use show processlist; Also check the DDL job; and in this situation, will restarting release the memory?

| username: BraveChen | Original post link

:+1: :+1: :+1:

| username: DBRE | Original post link

  1. There is no SQL thread, this TiDB server does not handle online traffic and is only used for backups.
  2. Restarting can free up memory, but it does not solve the root problem.
| username: DBRE | Original post link

I’ll try this method.

| username: DBRE | Original post link

Is there an analysis method using Graphviz?

| username: srstack | Original post link

Use the go tool pprof to analyze~

| username: TiDBer_pkQ5q1l0 | Original post link

pprof memory analysis
First, install on Windows: https://www2.graphviz.org/Packages/stable/windows/10/cmake/Release/x64/
Generate configuration file
Then find the solution, right-click to open cmd as administrator, and enter the directory:
C:\Program Files\Graphviz 2.44.1\bin
Execute: dot -c
pprof view tidb heap log
go tool pprof -http :8081 c:\heap_xxx
This is my previous note for reference.

| username: DBRE | Original post link

:+1: :+1: :+1:

| username: liuis | Original post link

pprof can analyze