How to Diagnose and Fix High CPU Usage in a Java Web Portal
This guide walks through diagnosing a Java portal's high CPU usage by checking system load, identifying the offending thread, analyzing JVM stack traces, pinpointing a slow MySQL query, and resolving the issue with data cleanup and index creation, reducing CPU load from 800% to 40%.
1. System Check
A portal page timed out; OS load average was over 4 and process 7163 consumed more than 800% CPU.
2. Fault Localization
Identify the high‑CPU thread, examine its stack, and find the problematic database call. top -Hbp 7163 | awk '/java/ && $9>50' Thread ID 16298 converts to hex 3faa.
printf "%x
" 16298
3faaUse jstack to view the stack for that thread: jstack 7163 | grep "3faa" -A 30 The stack trace reveals a database query.
List MySQL processes and save to a log:
mysql -uroot -p -e "show full processlist" >mysql_full_process.logFind the most frequently queried table: grep Query mysql_full_process.log The table contains nearly three million rows, causing long query times.
Check the table size and existing indexes:
use databases_name;
select count(1) from table_name; show create table table_name\G3. Confirmation and Fix
Data older than one month is not needed; delete it:
delete from table_name where xxxx_time < '2019-07-01 00:00:00' or xxxx_time is null;Create an index on the device_uuid column: alter table table_name add index (device_uuid); Verify the index was created:
show create table table_name;4. Result
CPU usage dropped to about 40%; the root cause was a database query without an appropriate index.
5. Other Tips
Adjusting MySQL's innodb_buffer_pool_size (e.g., to 4G) can improve query performance, but adding proper indexes remains the primary optimization method.
Source: https://blog.51cto.com/rongshu/2426712
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
