bloomberg / memray

Memray is a memory profiler for Python
https://bloomberg.github.io/memray/
Apache License 2.0
13.17k stars 392 forks source link

Memory allocations with `???` location for gunicorn process running in docker #663

Closed jaideep329 closed 1 month ago

jaideep329 commented 1 month ago

Is there an existing issue for this?

Current Behavior

Im trying to debug memory leak for a Django application which uses gunicorn. The process runs inside docker container. When i run memray attach <pid>, i do not see any memory allocations, just one entry with ???:

Screenshot 2024-08-09 at 5 30 36 PM

When i add -- native to the command, then i am able to see the allocations but not without it:

Screenshot 2024-08-09 at 5 31 25 PM

Expected Behavior

Im able to see memory allocations properly in live mode using memray attach <pid> on my mac(running using gunicorn as well) which look something like:

Screenshot 2024-08-09 at 5 26 59 PM

I was expecting a similar view for my production environment.

Steps To Reproduce

I'm running the gunicorn processes inside a docker container running with base python image from AWS(public.ecr.aws/ews-network/python:3.9.20230614). When i run memray attach <pid> on any gunicorn worker process i see no memory allocations being made, i just see a single entry with ???.

Memray Version

1.13.4

Python Version

3.9

Operating System

Linux

Anything else?

No response

pablogsal commented 1 month ago

This is not a bug. In non-native mode, memray only tracks Python stack frames so if the allocation happens in a thread that doesn't have any Python code above it it will not be resolved and will be shown as ???. When you pass --native then memray activates machinery that allows it to resolve the native location for that and therefore it doesn't show ??? anymore.

If you want to do this with memray attach you can do memray attach --native.

pablogsal commented 1 month ago

Check also https://github.com/bloomberg/memray/discussions/70#discussioncomment-2675361

pablogsal commented 1 month ago

If you think there is still something here and you want us to investigate further, you need to provide a self-contained reproducer