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

Worker memory determination relies on psutils, may fail in certain docker configurations #337

Open
tazlin opened this issue Nov 3, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@tazlin
Copy link
Member

tazlin commented Nov 3, 2024

Notably, Docker resource limits are only available by cgroups. The worker's reliance of psutil apparently gives the same/similar results as running free -m would, rather than the Docker-configured memory limits, if they exist.

  • It should be possible to incorporate some shell calls into the docker entrypoint.sh to dump/store the system memory statistics and use those values instead.
@CIB
Copy link
Contributor

CIB commented Nov 3, 2024

Since comfyui is using psutil as well, this issue is relevant for us:

giampaolo/psutil#490

Unfortunately the system (free -m) reports memory usage inside of docker that includes processes outside the current container. I verified it by using ps (which will only list processes inside the same container) and summing the memory usage.

# ps aux --sort=-%mem | awk '{sum += $6} END {print sum / 1024 " MB"}' && echo "" && free -m
85884.6 MB

               total        used        free      shared  buff/cache   available
Mem:          128722       94672        1079         318       32970       32512
Swap:              0           0           0

More evidence this is how it works:
https://stackoverflow.com/questions/74052985/how-to-get-containter-memory-limit-in-python
https://forums.docker.com/t/how-to-limit-the-cpu-and-memory-of-a-docker-container/108417

So to get the currently used memory inside docker:

ps aux --sort=-%mem | awk '{sum += $6} END {print sum / 1024 " MB"}'

To get the total available memory inside docker:

cat /sys/fs/cgroup/memory.max

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants