Welcome to follow our wechat official account: Shishan100
My new course ** “C2C e-commerce System Micro-service Architecture 120-day Practical Training Camp” is online in the public account ruxihu Technology Nest **, interested students, you can click the link below for details:
120-Day Training Camp of C2C E-commerce System Micro-Service Architecture
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
This article comes from headline number: Bobo says operations
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
An overview of the
Recently, an IDC monitoring alarm was received indicating that the CPU of a server was too high. The following is the troubleshooting process for your reference. Details are not important.
1. Observe the server resource consumption
You can see that the server is experiencing CPU problems and memory consumption is normal.
1.1. View the SPECIFIC CPU
ps -mp 2289 -o THREAD,tid,time
1.2. Find the thread TID that consumes the most time and convert its thread ID to hexadecimal format:
printf “%x\n” tid
1.3. Print stack information about threads, thread dump
jstack pid |grep tid -A 30
Further analyze the stack information
2. Check the database thread
It turns out there are about eight threads, all of which are the same SQL
3. View the SQL execution plan
This single SQL can be run in 2s, but the execution plan is full table scan, not index
4, slow query analysis
set global slow_query_log=on; set global long_query_time=30; set global log_output='TABLE'; show variables like '%slow%'; select * from mysql.slow_log order by 1;Copy the code
The following is because the first open index is recorded, so you can see this SQL, but after the slow query does not exceed 30 seconds of slow SQL.
5. Timed tasks?
After confirming with the development, there is a scheduled task. Every time, we need to check the attendance time of each user, and finally summarize the statistics. This scheduled task needs to run for one day.
The problem here is mainly nested loop. The outer loop traverses the work number (8000), and the inner loop traverses the number of days (30). Then the inner loop needs to interact with the database every time it looks up the data, inserts the data into the cache, and finally summarizes the calculation to the summary table.
6. Optimization scheme
1, summary table split
The commonly used fields are divided into a table, and the infrequently used fields are divided into another table. Then the commonly used fields are only summarized and calculated, and the infrequently used fields (such as marriage leave, sick leave, etc.) are cycled.
2. Optimize a single query
This is indexed in 1s
-- Create index idx_hwb1 on T_att_DD_attendance_info (user_id,class_id,check_type,plan_check_time)Copy the code
3. Logical optimization
Here with the development mentioned to change the logic, but the development has not been implemented, so I will not post the implementation code. The logic goes like this:
END
“21 days Internet Java Advanced Interview Training Camp (distributed)” details, scan the two-dimensional code at the end of the picture, try the course