Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pool memory utilization display is incorrect (not quite the template's fault though) #60

Open
victor-sudakov opened this issue Jun 11, 2021 · 13 comments
Assignees
Labels
enhancement New feature or request

Comments

@victor-sudakov
Copy link

Hello!

The "pool XXX memory utilization" item uses proc.mem["XXX",,,,pmem] and is very incorrect for this reason. When you have many php-fpm children, this item may show 400% or more of RAM (and an alarm triggers), but in fact there is still plenty of free RAM on the host (as top shows).

This happens IMHO because proc.mem calculates the memory incorrectly: it just multiplies each child's %MEM by the number of children, not taking into account that most memory is shared between children. This is not your template's fault per se, this is the fault of the Zabbix agent logic.

Still, can we think of providing a more realistic picture of the memory consumption of a pool? By analyzing something in /proc for example?

@welcome
Copy link

welcome bot commented Jun 11, 2021

Hello welcome GIF
Thank you so much for opening your first issue here! 🌸
✅ I hope you have kindly checked any other opened issues to make sure that it's not a duplicate 🙏
✅ And you have read the Wiki of this project that contains a full documentation, specifically the Installation instructions and Troubleshooting guide 😇
ℹ️ You may add any additional information by editing your original post or by posting additional comments below.
ℹ️ We need some time to read your issue and verify it, so please, be patient 😇
ℹ️ Any questions or comments regarding your issue will be posted here below that may require your response. So, please, don't miss the Github notifications about new updates on this topic 😉

We will kindly investigate the information you provided and hopefully return to you as soon as possible! 😊

@stale
Copy link

stale bot commented Jul 21, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Jul 21, 2021
@victor-sudakov
Copy link
Author

Ping!

@stale stale bot removed the wontfix This will not be worked on label Jul 21, 2021
@stale
Copy link

stale bot commented Jan 8, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Jan 8, 2022
@rvalitov rvalitov self-assigned this Jan 9, 2022
@stale stale bot removed the wontfix This will not be worked on label Jan 9, 2022
@rvalitov
Copy link
Owner

rvalitov commented Jan 9, 2022

@victor-sudakov Thank you for your comments and sorry for a late reply. According to the Zabbix manual the pmem is supposed to show the percentage of real memory used. May be you're right and the proc.mem calculation is not correct. You said that memory is shared between PHP-FPM children. Perhaps you know documentation where I can read about it? If you have any ideas how to improve this, please kindly share them. I think that reading /proc will gave exactly the same results as proc.mem. Or do you suggest to do some processing to the data received from /proc?

@victor-sudakov
Copy link
Author

I've studied the matter a bit and come to the conclusion that there is not much we can do about it. A good explanation of this effect is at http://virtualthreads.blogspot.com/2006/02/understanding-memory-usage-on-linux.html

The moral of this story is that process memory usage on Linux is a complex matter; you can't just run ps and know what is going on. This is especially true when you deal with programs that create a lot of identical children processes

@rvalitov
Copy link
Owner

@victor-sudakov Thank you for the link. A very good explanation.
After a little googling I found the following methods to get the memory consumption that we need:

  1. Use smem

Use smem, which is an alternative to ps which calculates the USS and PSS per process. You probably want the PSS.

USS - Unique Set Size. This is the amount of unshared memory unique to that process (think of it as U for unique memory). It does not include shared memory. Thus this will under-report the amount of memory a process uses, but it is helpful when you want to ignore shared memory.

PSS - Proportional Set Size. This is what you want. It adds together the unique memory (USS), along with a proportion of its shared memory divided by the number of processes sharing that memory. Thus it will give you an accurate representation of how much actual physical memory is being used per process - with shared memory truly represented as shared. Think of the P being for physical memory.

It seems that PSS is exactly what we need.

  1. Use pmap
  2. Use smaps

@rvalitov rvalitov added the enhancement New feature or request label Jan 20, 2022
@victor-sudakov
Copy link
Author

smem has too many runtime dependencies. pmap and smaps will probably require root privileges.

@stale
Copy link

stale bot commented Apr 18, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Apr 18, 2022
@victor-sudakov
Copy link
Author

ping

@stale stale bot removed the wontfix This will not be worked on label Apr 18, 2022
@jbgomond
Copy link

jbgomond commented Jun 7, 2022

Hello :)

I was looking into this problem that I have myself. Do you have some news about it ?

Thanks a lot

@c0r3dump3d
Copy link

I have the same problem ...

@c0r3dump3d
Copy link

In theory, with this script, some values are obtained that are more or less consistent, although I don't know if they are totally true, because in some cases the total value of the php-fpm processes exceeds the total memory of the system.

#!/bin/bash
ps -eo size,pid,user,command --sort -size | awk '{ hr=$1*1024 ; printf("%d Bytes ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }' | grep php-fpm | grep -v grep | grep -v master | awk '{ sum +=$1} END {print sum}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants