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

Changing memory calculation methodology from RSS to PSS #935

Closed
nishikantparmariam opened this issue May 23, 2022 · 3 comments · Fixed by #948
Closed

Changing memory calculation methodology from RSS to PSS #935

nishikantparmariam opened this issue May 23, 2022 · 3 comments · Fixed by #948

Comments

@nishikantparmariam
Copy link

Problem

usage_request should probably use PSS instead of RSS. As RSS overestimates due to copy-on-write. See the below reproducer -

import multiprocessing
import time
import psutil

def foo():
    time.sleep(10000)

parents_original_memory = bytearray(int(1e9)) # 1GB

for i in range(10):
    multiprocessing.Process(target=foo).start()

def get_memory_info(type):
    process_metric_value = lambda process: getattr(process.memory_full_info(), type)
    current_process = psutil.Process()
    all_processes = [current_process] + current_process.children(recursive=True)
    return (
        f"{sum([process_metric_value(process) for process in all_processes]) / 1e9} GB"
    )

print("RSS: ", get_memory_info("rss"))
print("PSS: ", get_memory_info("pss"))

Output is -

RSS: 11.590012928 GB 
PSS: 1.082778624 GB

PSS seems to be more accurate here.

Additional context

This is very similar to - jupyter-server/jupyter-resource-usage#130

@mlucool
Copy link
Contributor

mlucool commented May 23, 2022

CC @echarles

@echarles
Copy link
Member

Thx for the report. I have opened #936 to request memory usage with pss.

@nishikantparmariam
Copy link
Author

We will have to use memory_full_info to get PSS and since PSS is a linux only feature, we might want to check if memory_full_info is an attribute of psutil.Process() (reference), and fallback to RSS if not supported by the OS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants