Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions examples/benchmark_perf/benchmark_workers_n.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class RunResult:
base_cache_bytes: int
task_cache_bytes: int
peak_rss_bytes: int
peak_pss_bytes: int


def format_size(size_bytes: int) -> str:
Expand Down Expand Up @@ -108,6 +109,7 @@ def __init__(self, poll_interval_s: float = 0.1) -> None:
self._stop = threading.Event()
self._lock = threading.Lock()
self._peak = 0
self._peak_pss = 0
self._thread = threading.Thread(target=self._run, daemon=True)

def start(self) -> None:
Expand All @@ -116,14 +118,41 @@ def start(self) -> None:
def reset(self) -> None:
with self._lock:
self._peak = 0
self._peak_pss = 0

def stop(self) -> None:
self._stop.set()

def peak_pss_bytes(self) -> int:
with self._lock:
return self._peak_pss

def peak_bytes(self) -> int:
with self._lock:
return self._peak

def _total_pss_bytes(self) -> int:
"""Proportional set size across the process tree.

Summing RSS over forked workers counts every shared page once per
process; PSS divides it among the mappers, so the total is additive.
Falls back to RSS where PSS is unavailable (non-Linux, or no perms).
"""
total = 0
try:
procs = [self._proc] + self._proc.children(recursive=True)
except (psutil.NoSuchProcess, psutil.AccessDenied):
return 0
for p in procs:
try:
total += p.memory_full_info().pss
except (psutil.NoSuchProcess, psutil.AccessDenied, AttributeError):
try:
total += p.memory_info().rss
except (psutil.NoSuchProcess, psutil.AccessDenied):
pass
return total

def _total_rss_bytes(self) -> int:
total = 0
try:
Expand All @@ -140,9 +169,12 @@ def _total_rss_bytes(self) -> int:
def _run(self) -> None:
while not self._stop.is_set():
rss = self._total_rss_bytes()
pss = self._total_pss_bytes()
with self._lock:
if rss > self._peak:
self._peak = rss
if pss > self._peak_pss:
self._peak_pss = pss
time.sleep(self._poll_interval_s)


Expand Down Expand Up @@ -329,6 +361,7 @@ def main() -> None:
base_cache_bytes=base_cache_bytes,
task_cache_bytes=task_cache_bytes,
peak_rss_bytes=peak_rss_bytes,
peak_pss_bytes=tracker.peak_pss_bytes(),
)
)

Expand Down
33 changes: 33 additions & 0 deletions examples/benchmark_perf/benchmark_workers_n_drug_recommendation.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class RunResult:
base_cache_bytes: int
task_cache_bytes: int
peak_rss_bytes: int
peak_pss_bytes: int


def format_size(size_bytes: int) -> str:
Expand Down Expand Up @@ -108,6 +109,7 @@ def __init__(self, poll_interval_s: float = 0.1) -> None:
self._stop = threading.Event()
self._lock = threading.Lock()
self._peak = 0
self._peak_pss = 0
self._thread = threading.Thread(target=self._run, daemon=True)

def start(self) -> None:
Expand All @@ -116,14 +118,41 @@ def start(self) -> None:
def reset(self) -> None:
with self._lock:
self._peak = 0
self._peak_pss = 0

def stop(self) -> None:
self._stop.set()

def peak_pss_bytes(self) -> int:
with self._lock:
return self._peak_pss

def peak_bytes(self) -> int:
with self._lock:
return self._peak

def _total_pss_bytes(self) -> int:
"""Proportional set size across the process tree.

Summing RSS over forked workers counts every shared page once per
process; PSS divides it among the mappers, so the total is additive.
Falls back to RSS where PSS is unavailable (non-Linux, or no perms).
"""
total = 0
try:
procs = [self._proc] + self._proc.children(recursive=True)
except (psutil.NoSuchProcess, psutil.AccessDenied):
return 0
for p in procs:
try:
total += p.memory_full_info().pss
except (psutil.NoSuchProcess, psutil.AccessDenied, AttributeError):
try:
total += p.memory_info().rss
except (psutil.NoSuchProcess, psutil.AccessDenied):
pass
return total

def _total_rss_bytes(self) -> int:
total = 0
try:
Expand All @@ -140,9 +169,12 @@ def _total_rss_bytes(self) -> int:
def _run(self) -> None:
while not self._stop.is_set():
rss = self._total_rss_bytes()
pss = self._total_pss_bytes()
with self._lock:
if rss > self._peak:
self._peak = rss
if pss > self._peak_pss:
self._peak_pss = pss
time.sleep(self._poll_interval_s)


Expand Down Expand Up @@ -331,6 +363,7 @@ def main() -> None:
base_cache_bytes=base_cache_bytes,
task_cache_bytes=task_cache_bytes,
peak_rss_bytes=peak_rss_bytes,
peak_pss_bytes=tracker.peak_pss_bytes(),
)
)

Expand Down
33 changes: 33 additions & 0 deletions examples/benchmark_perf/benchmark_workers_n_length_of_stay.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class RunResult:
base_cache_bytes: int
task_cache_bytes: int
peak_rss_bytes: int
peak_pss_bytes: int


def format_size(size_bytes: int) -> str:
Expand Down Expand Up @@ -108,6 +109,7 @@ def __init__(self, poll_interval_s: float = 0.1) -> None:
self._stop = threading.Event()
self._lock = threading.Lock()
self._peak = 0
self._peak_pss = 0
self._thread = threading.Thread(target=self._run, daemon=True)

def start(self) -> None:
Expand All @@ -116,14 +118,41 @@ def start(self) -> None:
def reset(self) -> None:
with self._lock:
self._peak = 0
self._peak_pss = 0

def stop(self) -> None:
self._stop.set()

def peak_pss_bytes(self) -> int:
with self._lock:
return self._peak_pss

def peak_bytes(self) -> int:
with self._lock:
return self._peak

def _total_pss_bytes(self) -> int:
"""Proportional set size across the process tree.

Summing RSS over forked workers counts every shared page once per
process; PSS divides it among the mappers, so the total is additive.
Falls back to RSS where PSS is unavailable (non-Linux, or no perms).
"""
total = 0
try:
procs = [self._proc] + self._proc.children(recursive=True)
except (psutil.NoSuchProcess, psutil.AccessDenied):
return 0
for p in procs:
try:
total += p.memory_full_info().pss
except (psutil.NoSuchProcess, psutil.AccessDenied, AttributeError):
try:
total += p.memory_info().rss
except (psutil.NoSuchProcess, psutil.AccessDenied):
pass
return total

def _total_rss_bytes(self) -> int:
total = 0
try:
Expand All @@ -140,9 +169,12 @@ def _total_rss_bytes(self) -> int:
def _run(self) -> None:
while not self._stop.is_set():
rss = self._total_rss_bytes()
pss = self._total_pss_bytes()
with self._lock:
if rss > self._peak:
self._peak = rss
if pss > self._peak_pss:
self._peak_pss = pss
time.sleep(self._poll_interval_s)


Expand Down Expand Up @@ -331,6 +363,7 @@ def main() -> None:
base_cache_bytes=base_cache_bytes,
task_cache_bytes=task_cache_bytes,
peak_rss_bytes=peak_rss_bytes,
peak_pss_bytes=tracker.peak_pss_bytes(),
)
)

Expand Down
33 changes: 33 additions & 0 deletions examples/benchmark_perf/legacy_ver/benchmark_legacy_drug_rec.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class RunResult:
total_s: float
base_cache_bytes: int
peak_rss_bytes: int
peak_pss_bytes: int
num_samples: int


Expand Down Expand Up @@ -186,6 +187,7 @@ def __init__(self, poll_interval_s: float = 0.1) -> None:
self._stop = threading.Event()
self._lock = threading.Lock()
self._peak = 0
self._peak_pss = 0
self._thread = threading.Thread(target=self._run, daemon=True)

def start(self) -> None:
Expand All @@ -194,14 +196,41 @@ def start(self) -> None:
def reset(self) -> None:
with self._lock:
self._peak = 0
self._peak_pss = 0

def stop(self) -> None:
self._stop.set()

def peak_pss_bytes(self) -> int:
with self._lock:
return self._peak_pss

def peak_bytes(self) -> int:
with self._lock:
return self._peak

def _total_pss_bytes(self) -> int:
"""Proportional set size across the process tree.

Summing RSS over forked workers counts every shared page once per
process; PSS divides it among the mappers, so the total is additive.
Falls back to RSS where PSS is unavailable (non-Linux, or no perms).
"""
total = 0
try:
procs = [self._proc] + self._proc.children(recursive=True)
except (psutil.NoSuchProcess, psutil.AccessDenied):
return 0
for p in procs:
try:
total += p.memory_full_info().pss
except (psutil.NoSuchProcess, psutil.AccessDenied, AttributeError):
try:
total += p.memory_info().rss
except (psutil.NoSuchProcess, psutil.AccessDenied):
pass
return total

def _total_rss_bytes(self) -> int:
total = 0
try:
Expand All @@ -218,9 +247,12 @@ def _total_rss_bytes(self) -> int:
def _run(self) -> None:
while not self._stop.is_set():
rss = self._total_rss_bytes()
pss = self._total_pss_bytes()
with self._lock:
if rss > self._peak:
self._peak = rss
if pss > self._peak_pss:
self._peak_pss = pss
time.sleep(self._poll_interval_s)


Expand Down Expand Up @@ -411,6 +443,7 @@ def main() -> None:
total_s=total_s,
base_cache_bytes=base_cache_bytes,
peak_rss_bytes=peak_rss_bytes,
peak_pss_bytes=tracker.peak_pss_bytes(),
num_samples=num_samples,
)
)
Expand Down
33 changes: 33 additions & 0 deletions examples/benchmark_perf/legacy_ver/benchmark_legacy_los.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class RunResult:
total_s: float
base_cache_bytes: int
peak_rss_bytes: int
peak_pss_bytes: int
num_samples: int


Expand Down Expand Up @@ -186,6 +187,7 @@ def __init__(self, poll_interval_s: float = 0.1) -> None:
self._stop = threading.Event()
self._lock = threading.Lock()
self._peak = 0
self._peak_pss = 0
self._thread = threading.Thread(target=self._run, daemon=True)

def start(self) -> None:
Expand All @@ -194,14 +196,41 @@ def start(self) -> None:
def reset(self) -> None:
with self._lock:
self._peak = 0
self._peak_pss = 0

def stop(self) -> None:
self._stop.set()

def peak_pss_bytes(self) -> int:
with self._lock:
return self._peak_pss

def peak_bytes(self) -> int:
with self._lock:
return self._peak

def _total_pss_bytes(self) -> int:
"""Proportional set size across the process tree.

Summing RSS over forked workers counts every shared page once per
process; PSS divides it among the mappers, so the total is additive.
Falls back to RSS where PSS is unavailable (non-Linux, or no perms).
"""
total = 0
try:
procs = [self._proc] + self._proc.children(recursive=True)
except (psutil.NoSuchProcess, psutil.AccessDenied):
return 0
for p in procs:
try:
total += p.memory_full_info().pss
except (psutil.NoSuchProcess, psutil.AccessDenied, AttributeError):
try:
total += p.memory_info().rss
except (psutil.NoSuchProcess, psutil.AccessDenied):
pass
return total

def _total_rss_bytes(self) -> int:
total = 0
try:
Expand All @@ -218,9 +247,12 @@ def _total_rss_bytes(self) -> int:
def _run(self) -> None:
while not self._stop.is_set():
rss = self._total_rss_bytes()
pss = self._total_pss_bytes()
with self._lock:
if rss > self._peak:
self._peak = rss
if pss > self._peak_pss:
self._peak_pss = pss
time.sleep(self._poll_interval_s)


Expand Down Expand Up @@ -412,6 +444,7 @@ def main() -> None:
total_s=total_s,
base_cache_bytes=base_cache_bytes,
peak_rss_bytes=peak_rss_bytes,
peak_pss_bytes=tracker.peak_pss_bytes(),
num_samples=num_samples,
)
)
Expand Down
Loading
Loading