Score:1

Finding out specific processes that are running php commands shown in 'top -i'

im flag

I have been scouring the forums to find the next step in analysing what process specifically is requesting the usage of a php command shown when running the top -i in an Ubuntu 20.04 server cli.

After SSH'ing into a server that is reporting 100% CPU usage, I can see:

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
18266 mysql 20 0 1354720 496864 38872 S 45.1 24.5 7:01.28 mysqld
17012 hills 20 0 337656 67748 43384 R 14.4 3.3 0:45.32 php-fpm8.0
17017 hills 20 0 339840 66492 40040 R 12.7 3.3 0:40.82 php-fpm8.0
13618 hills 20 0 341960 69600 41128 R 12.4 3.4 1:23.47 php-fpm8.0
13612 hills 20 0 340016 67796 41256 S 11.8 3.3 1:26.96 php-fpm8.0

The obvious is that the mysqld is requesting a lot from the CPU. I can figure out what specifically is being ran that is costing so much memory within the mysqld command by finding its process ID pidstat -t -p {PID} 1 collecting its {TID} signing into mysql mysql -u root -p then selecting that process with a select query select * from performance_schema.threads where THREAD_OS_ID = {TID} \G.

I am wondering if there is an equivalent that will show me what specifically is requesting each of the php-fpm8.0 commands running that are shown in the list above?

mondotofu avatar
cn flag
sounds like a PHP question, not Ubuntu. Perhaps phmypadmin https://www.phpmyadmin.net/ would help you. I know it's a GUI tool, but it may help you figure out which queries or processes consume the memory in its dashboards.
Doopz avatar
im flag
You might be correct, @mondotofu. I will leave this here just in case as I do see some overlap, but it is regarding the PHP processes!
mondotofu avatar
cn flag
Another option in Ubuntu is the **pstree** command.
Doopz avatar
im flag
@mondotofu, this is a good idea, however if I use pstree {ONE_OF_THE_PIDs_IN_top -i_LIST} it simply returns php-fpm8.0 which doesn't get me much further, unless you know of an option I need to add to show the full tree?
Score:1
cn flag

perhaps a combination of

ps -ef | grep php

and

pstree -a -l -h -p  {ONE_OF_THE_PIDs}

would help. I'm not running php, but I am running postgres. Here's a sample output for you.

steve@AntHill2:~$ ps -ef | grep post
postgres    1115       1  0 08:39 ?        00:00:01 /usr/lib/postgresql/12/bin/postgres -D /var/lib/postgresql/12/main -c config_file=/etc/postgresql/12/main/postgresql.conf
postgres    1153    1115  0 08:39 ?        00:00:00 postgres: 12/main: checkpointer   
postgres    1154    1115  0 08:39 ?        00:00:00 postgres: 12/main: background writer   
postgres    1155    1115  0 08:39 ?        00:00:00 postgres: 12/main: walwriter   
postgres    1156    1115  0 08:39 ?        00:00:00 postgres: 12/main: autovacuum launcher   
postgres    1157    1115  0 08:39 ?        00:00:00 postgres: 12/main: stats collector   
postgres    1158    1115  0 08:39 ?        00:00:00 postgres: 12/main: logical replication launcher   
steve      17723   17577  0 20:10 pts/0    00:00:00 grep --color=auto post
steve@AntHill2:~$ pstree -a -l -h -p  1115
postgres,1115 -D /var/lib/postgresql/12/main -c config_file=/etc/postgresql/12/main/postgresql.conf
  ├─postgres,1153
  ├─postgres,1154
  ├─postgres,1155
  ├─postgres,1156
  ├─postgres,1157
  └─postgres,1158

If this does not help, try the arguments for pstree. If still no luck, then I recommend phpadmin or look in the php Stack Exchange forum.

Doopz avatar
im flag
again helpful answer! I think this has indirectly highlighted it is the pools that are appearing as duplicate entries for php-fpm8.0
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.