I am using Ubuntu 18.04 with PHP application connected to MySQL database. Often, using Mytop, I detect some stuck MySQL threads:
Id User Host/IP DB Time Cmd State
-- ---- ------- -- ---- --- -----
1725310 ms_db_use 184.126.65.142 app_pro 19716 Sleep
2370165 ms_db_use localhost:58210 app_pro 1385 Query Copying
As you can see above, some threads are stucked for 19k seconds. This is putting overload on my cpu sometimes so my question is:
Is there any way to automate this to automatically kill the thread if it is not resolved in X Amount of seconds? The purpose of this is to remove overload from CPU.
According to this it is PHP application on my server, just I am not sure how to troubleshoot that part:
PID USER PRI VIRT RES SHR S CPU MEM% COMMAND 124 megax 20 335M 19254 21212 S 100.00% 0.0 php-fpm: pool www 125 megax 20 335M 19254 21212 S 100.00% 0.0 php-fpm: pool www 126 megax 20 335M 19254 21212 S 100.00% 0.0 php-fpm: pool www 127 megax 20 335M 19254 21212 S 100.00% 0.0 php-fpm: pool www