Hi, I have been working on a what I expect is a me...
# ask-community
m
Hi, I have been working on a what I expect is a memory leak and have been led to use memory_profiler. The trouble I'm having is that the output of memory_profiler does not go to the Prefect logger. I have tried to run the deployment from the command line, which I can do, but I don't get any console output, only what is shown below: How can I force the output to show when I run the deployment from the CLI?
Seems like my own lack of understanding of how Linux describes memory is part of the problem. I ended up using a function like this to track memory consumption during my prefect runs.
Copy code
def log_memory_usage(mem_dict, event):
    # Get the memory usage information
    memory_info = psutil.virtual_memory()
    # Convert memory info from bytes to gigabytes
    total_gb = memory_info.total / (1024**3)
    used_gb = memory_info.used / (1024**3)
    available_gb = memory_info.available / (1024**3)

    # Check if mem_dict is empty
    if not mem_dict:
        next_key = 0
    else:
        next_key = max(mem_dict.keys()) + 1

    mem_dict[next_key] = (event, f"Used: {used_gb:.2f} | Tot: {total_gb:.2f} | Avail: {available_gb:.2f}")
    return mem_dict
Availability memory appears to be the correct one to track, this is different than what the VM memory chart in Proxmox seems to be reporting. I can see now that I have much less memory leak as a result of prefect runs. It seems like there is about 250MB that gets consumed after the first prefect run after a reboot. After that it actually seems to stay pretty steady. Monitoring memory with htop from Linux CLI suggests about 10MB memory leak per run, but who knows maybe that is just from some other unrelated process going on. For the time being it seems to be just fine. Maybe one day I'll need to dig deeper, but good enough for now.
m
I made a GH issue about a memory leak using memory_profiler a few weeks back - unsure if it's the same one you're describing. Steps are in there to reproduce