- This information is applicable to FE nodes and Coordinator nodes (shared-data deployments). For readability, we will use “FE” to refer to both types of frontend nodes.
- This article mainly analyzes the situation and solutions of in-heap memory, without covering off-heap memory. If the OOM is caused by off-heap memory issues, consider reducing the JVM XMX configuration or expanding the machine’s memory.
FE Memory Structure and Allocation Recommendations
FE Memory Composition
The front-end service (FE) runs on the JVM, and its memory consumption is from the Java heap and from off-heap memory overhead.Overview of JVM Memory Modules
All memory allocated through the JVM during the FE process can be roughly divided into the following modules:
Considering the operating characteristics of JVM and the database, the memory of FE mainly consists of the following parts:
-
JVM Heap Memory (Heap)
- Stores Java object instances, such as Plan Cache, metadata cache, etc.
- The maximum size is set via the parameter
-Xmxand is significantly affected by the garbage collection mechanism.
-
Non-heap Memory (Metaspace)
- Metadata such as storage class definitions, constant pool, etc.
- Java 8 and later replaced PermGen.
-
Direct Memory
- Off-heap memory used by Netty, ByteBuffer, log buffer, RPC framework, etc.
- Allocated by
sun.misc.Unsafe, usually not controlled by GC.
-
Thread Stack Memory
- Each Java thread will request a thread stack when created, with a default size of approximately 1MB (configurable via
-Xss). - When the number of threads is large (such as in high-concurrency scenarios), it is easy to cause memory backlog.
- Each Java thread will request a thread stack when created, with a default size of approximately 1MB (configurable via
-
JNI / Native Memory Call
- The database may consume memory when calling the native layer through logging components (such as RocksDB, Netty), Cache, etc.
JVM Parameter Configuration Recommendations
In the JVM, the heap memory is configured viaXmx. Generally, it is reasonable for the memory used by the process to be less than 130% of Xmx. That is to say, in addition to the memory configured by JVM Xmx, a portion of off-heap memory will also be used. For example, if JVM is configured with 21g, the RSS memory usage of the process seen in top will be approximately 27g.
Based on experience, the recommended relationship between the number of tablets and FE memory is:
For independently deployed environments, it is recommended to reserve sufficient memory for the system. In addition to the memory reserved for the system, off-heap memory also needs to be considered.
For hybrid deployment environments, it is necessary to reserve sufficient memory as much as possible based on the usage considerations of other services to prevent OOM.
In the case of independent deployment of FE (mixed deployment is not recommended):
- When the machine memory is less than 32G,
-Xmx(Max Heap Size) should be configured to a maximum of 70% of the machine memory. - When the machine memory is greater than 32G,
-Xmx(Max Heap Size) should be configured to a maximum of 80% of the machine memory. - Since the FE leader node needs to perform checkpoints, in general, the memory of the leader node will be about twice that of the follower node.
FE JVM Monitoring and Memory Profile Deployment
For FE state, heap monitoring and GC monitoring can effectively monitor the state of the service and are also key clues for troubleshooting issues afterwards. It is recommended to configure monitoring in a timely manner, and configure corresponding alerts if necessary. The specific monitoring indicators are as follows:
Monitoring information for these metrics and others is at Monitoring and alerting
Memory profile can analyze sudden heap increases. It is necessary to confirm whether it works properly after the service installation is completed.
In 3.3.6+, the database will periodically print the memory profile and output it to
log/proc_profile, in HTML format, compressed via tgz.
Control configuration:
proc_profile_collect_time_s seconds. In earlier versions, the default value of proc_profile_collect_time_s is 300, and proc_profile_collect_interval_s (default: 600) controls the interval between collections.
For versions prior to 3.3.6, you can periodically print the profile via a script. Create a new script file named mem_profiler.sh under the installation directory of each FE and copy the following content into the file.
Note
This script has no impact on the FE process, does not affect the normal use of the service, and will automatically clean up files that have expired for 48 hours.
FE Crash
The causes of FE crashes are roughly divided into 4 types.1. The FE process has high memory usage and was killed by the operating system
You can check whether this is the cause by querying the system logs:total_vm and rss displayed by OOM are in units of pages, with the default being 1 page = 4KB:
total_vm = 8793525→ indicates that it has requested approximately 8793525 × 4KB ≈ 33.5 GB of virtual memoryrss = 7218120→ indicates that approximately 27.5 GB of physical memory has been actually used, which is 7218120 × 4KB
2. The FE leader heap memory is high, triggering a Full GC, leading to a leader switch
When the old leader exits due to a leader switch, the following information is printed infe.out:
jstack.
Analyzing GC logs:
Upload the GC log to https://gceasy.io/ and click Pause GC Duration. If the duration of a single pause GC exceeds 30 seconds, or if there are frequent pause GCs exceeding 10 seconds, it will trigger a leader switch.
Click Heap before GC to find the time point when heap memory rises. Use this time range to locate the memory profile file for that period, which will identify which module was requesting memory at that time.
3. An internal bug in the FE program caused a crash
This situation is not within the scope of this discussion. Refer to the Restore Metadata documentation.4. JVM bug causes FE crash
This situation is very rare. After encountering it, the cause can be investigated by checking the crash log, located atlog/hs_err_pid%p.log, where %p is the process ID.
FE Process Is Normal But Memory Is High
During the long-term operation of the FE, the in-heap memory usage may abnormally increase, frequently triggering Full GC, which causes queries or imports to slow down. The problem may manifest as heap sudden increase or continuous slow growth.Process of On-site Investigation
Open your monitoring tool: Monitoring and alerting Step 1: Check the following monitoring- FE JVM Panel: JVM Heap Memory Used metric
Memory Spike Investigation
Whether the request pressure increases within a short period — high QPS or highly concurrent metadata operations can lead to a surge in memory. 1. Check the following monitoring:- QPS Panel: Has the number of requests received by FE suddenly increased?
- Connections Panel: Does the number of concurrent connections of FE spike instantaneously?
- Statements with deep subqueries, multiple JOINs, and complex aggregations
- Unconventional business SQL (such as concurrent SQL for datasets generated by the BI platform)
- In version 3.3.13+, you can check the FE audit log for the
queryFeMemoryfield, which indicates how much memory a query has applied for in total in the FE. - When the FE process exits due to FE OOM, it will automatically print the query being executed and the corresponding
QueryFEAllocatedMemory.
Memory Slowly Increasing
4. The memory configured for the JVM is too small Monitor the GC status of the FE process to determine whether Full GC occurs frequently. Check the JVM memory usage through thejstat command:
O (Old Generation) percentage has been relatively high, it indicates a problem with the JVM memory configuration, and the JVM memory needs to be increased.
5. Observe whether there is a leak through the FE’s memory tracker (3.3.7+)
You can locate which module has a memory leak by checking the logs of MemoryUsageTracker, which prints the object count of each module every memory_tracker_interval_seconds (default: 60) seconds. From v4.0.7 and v4.1.0 onwards, these periodic logs no longer include the estimated memory size of each module. You can query sys.fe_memory_usage (v4.0.17, v4.1.7, and later) to get the estimated sizes. In earlier versions, each log line also includes the estimated memory size of the module, for example, LocalMetastore estimated 3.8MB of memory.
On-site Information Collection
If the process has not been restarted yet, collectjmap information immediately.
jmap Memory Troubleshooting Process
Step 1: Confirm the process PID of FEjmap -dumpwill pause the FE process for a short period of time. Use with caution when high online stability is required, and it is recommended to notify in advance.jmap -histogenerally has no impact on the process; GC triggering may take dozens of milliseconds.- Frequent use of
-dumpto export heap files is not recommended, as it incurs significant overhead. histois sufficient for preliminary judgment of large objects and does not necessarily require a dump.
jmap -histo:live (Use with caution in production environments)
Captures the current in-heap object distribution by forcing a GC. Using the live parameter may resolve high memory usage issues:
jmap -histo pid (lightweight, does not trigger Full GC)
Compare
histo_1 and histo_2 to identify which classes have significantly increased instances or memory.
Example: Classes starting with java are utility classes referenced by business classes. Looking from top to bottom, related classes at the front account for a larger proportion. For example, com.starrocks.lake.LakeTablet occupying significant memory indicates excessive tablet usage.
Step 4: Export a complete heap dump (if histo is insufficient)
fe.conf to automatically generate a dump file when FE runs out of memory:
HeapDumpPath specifies a directory path, not a file name.
Keep Memory Profile Files for Analysis
Starting from version 3.3.6, memory profiles are output to thelog/proc_profile directory, in HTML format, compressed using tgz.
Find the file corresponding to the time of memory increase, decompress it, and open it in a browser to see the flame graph of memory allocation. The wider part of the stack represents more memory allocation.
If no memory profile is printed during the period of memory increase, you can turn off the CPU profile so that only the memory profile is collected:
proc_profile_collect_interval_s to 300 to adjust the printing interval to 5 minutes.
This is a dynamic parameter that can be modified directly without restart:
Emergency Recovery
1. Stop the FE service 2. Adjust the heap memory configuration to a larger value and restart Modify the-Xmx value in fe.conf:
Case Collection
Case 1: Frequent and large-scale metadata operations cause high FE memory usage
Background: A client’s business requires regular table creation and cleanup, with sequential operations creating dozens of tables per second and synchronous operations deleting them, resulting in the creation of hundreds of thousands of tables throughout the process. Problem manifestation: Heap memory and machine CPU continue to rise, and query response slows down. After checking the FE logs, a large number of table creation and deletion operations were found, which led to a sharp increase in service pressure. Recovery Method: Stop the table creation and deletion jobs, restart the service, and resume normal use. Solution: For this business scenario, when usingDROP TABLE, FORCE must be added; otherwise, the metadata will continue to be occupied. At the same time, reduce the concurrency frequency of table creation.
Case 2: Complex concurrent SQL causes a sudden increase in FE memory
Problem manifestation: Heap memory suddenly increased, and scheduled import tasks were significantly delayed. QPS and the number of connections were within the normal range of variation. Review of audit logs and FE logs revealed many highly complex queries in concurrent scheduled SQL, which resulted in a large amount of memory being occupied during query plan parsing. Recovery Method: Expand the memory of the FE service — stop the machine to expand its memory, increase the JVM XMX configuration, and restart the service. Solution: Split complex SQL, observe the memory usage during peak job periods, and ensure it stays below 80%.Case 3: MV refresh is too frequent, causing the leader FE memory to grow slowly and remain high
Background: The user has MV refresh tasks, and many tasks are configured for minute or second-level refresh. Problem manifestation: FE leader memory continues to rise, and queries are laggy. Checking the FE log reveals many slow locks, causing occupied resources to fail to be released. Example slow lock log:Case 4: Querying external tables in the Iceberg catalog causes an increase in FE memory
Background: User executes a query job on an Iceberg table. Problem manifestation: After submitting the SQL, the memory of the FE leader increased significantly, and CPU also continued to rise. Other query and import tasks reported errors. Checking the process status revealed that frequent GC was triggered, causing abnormal service status. Recovery Method: Restart the leader node and regularly manage the delete files of the corresponding Iceberg table.Case 5: Insert memory leak issue causes abnormal increase in FE memory
Background: During user operation, it was found that the FE memory abnormally increased, the process restarted, and the leader was not properly switched. The main task of the client cluster was import tasks. Problem manifestation: Exportjmap for the leader node process for troubleshooting:
InsertLoadJob instances is 520,000. When this number exceeds 10,000, it indicates that a memory leak has occurred.
Affected versions:
- 3.1.0 - 3.1.16
- 3.2.0 - 3.2.12
- 3.3.0 - 3.3.7
Case 6: async-profiler causes JVM crash, leading to FE crash
Problem manifestation: FE process crashed or restarted. Problem Troubleshooting: When the process is abnormal and the filehs_err_pid$pid.log is generated in the log directory, the FE crash may be caused by a JVM crash.
PerfEvents::signalHandler is caused by async-profiler. The tool triggered a segmentation fault inside the JVM while attempting to obtain the Java call stack. In the enterprise version, this tool is deployed by default to periodically obtain process information.
Processing Method: Stop async-profiler CPU information collection:
fe.conf:
Case 7: OOM caused by insufficient JVM heap configuration
Under normal circumstances, with 3 FEs, if the leader node crashes due to insufficient memory, the remaining 2 FEs can elect a new leader and provide services. If the 2 follower nodes cannot communicate properly after the leader crashes, the FE that is about to be promoted to leader may also exit due to insufficient metadata replicas, resulting in 2 FEs crashing. Problem Troubleshooting: FE leader log shows:Case 8: Slow FE response leads to increased time consumption for import tasks
Problem Phenomenon: The agent printsjstack when communicating with FE and encountering a situation where FE does not respond in a timely manner. The logs of the two follower FEs contain the printed message “notify new FE type”. There are a large number of jstack collection records in the agent log.
jstack collection exacerbated the unresponsive state duration of FE.
Processing Method: Turn off jstack collection. Version 3.3+ has already turned it off by default. You can remove the jstack command in the cluster configuration.
Case 9: FE Memory Slowly Increasing (version 3.3.13 - 3.3.18)
Version scope: This issue occurs between versions 3.3.13 and 3.3.18. Problem Phenomenon: If the FE heap memory is found to continuously and slowly increase, it may be caused by this issue. Obtainingjmap and checking reveals that com.starrocks.catalog.Replica occupies excessive memory. All operations involving large amounts of DROP, SWAP, and INSERT OVERWRITE may trigger this issue.
This issue is due to the optimization of the tablet deletion path in version 3.3.13, which introduced a memory leak and was fixed in 3.3.18.
- Optimization PR in 3.3.13: [BugFix] Fix recycle bin missing to delete lake mv’s expired partitions after mv refreshed
- Fix PR in 3.3.18
- Temporary workaround: Restart FE
- Fundamental solution: Upgrade to a fixed version
Appendix: Tool Usage Commands
jstat — Monitor JVM GC Status
Purpose: Quickly determine whether GC is frequent, whether the old generation is approaching full, and whether there is a Full GC.
jmap — View JVM Memory Object Distribution
Method 1: View objects in the current heap (including garbage objects)byte[], String, HashMap, etc.
Method 2: Check live objects after forcing GC