8000 Use GC natively by denniswittich · Pull Request #301 · zauberzeug/rosys · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use GC natively #301

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
42 changes: 21 additions & 21 deletions rosys/analysis/memory.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ def compare_tracemalloc_snapshots(snapshot, prev_snapshot):

def observe_memory_growth(with_tracemalloc: bool = False) -> None:
log.info('Observing memory growth')
prev_memory: int = 0
prev_snapshot: tracemalloc.Snapshot | None = None
if with_tracemalloc:
tracemalloc.start(10)

async def stats() -> None:
nonlocal prev_memory
nonlocal prev_snapshot
gc.collect()
growth = get_process_memory() - prev_memory
# log.info('==============')
log.info("memory growth: %s, now it's %s", bytes2human(growth), get_humanreadable_process_memory())
# log.info('==============')
prev_memory = get_process_memory()
if with_tracemalloc:
snapshot = tracemalloc.take_snapshot()
if growth > 4 * 1e-6 and prev_snapshot is not None:
await run.cpu_bound(compare_tracemalloc_snapshots, snapshot, prev_snapshot)
prev_snapshot = snapshot

rosys.on_repeat(stats, 60.0)
# prev_memory: int = 0
# prev_snapshot: tracemalloc.Snapshot | None = None
# if with_tracemalloc:
# tracemalloc.start(10)

# async def stats() -> None:
# nonlocal prev_memory
# nonlocal prev_snapshot
# gc.collect()
# growth = get_process_memory() - prev_memory
# # log.info('==============')
# log.info("memory growth: %s, now it's %s", bytes2human(growth), get_humanreadable_process_memory())
# # log.info('==============')
# prev_memory = get_process_memory()
# if with_tracemalloc:
# snapshot = tracemalloc.take_snapshot()
# if growth > 4 * 1e-6 and prev_snapshot is not None:
# await run.cpu_bound(compare_tracemalloc_snapshots, snapshot, prev_snapshot)
# prev_snapshot = snapshot

# rosys.on_repeat(stats, 60.0)
4 changes: 2 additions & 2 deletions rosys/rosys.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,11 @@ def reset_after_test() -> None:


def register_base_startup_handlers() -> None:
on_repeat(_garbage_collection, 60)
# on_repeat(_garbage_collection, 60)
on_repeat(_watch_emitted_events, 0.1)


gc.disable() # NOTE disable automatic garbage collection to optimize performance
# gc.disable() # NOTE disable automatic garbage collection to optimize performance
register_base_startup_handlers()

app.on_startup(startup)
Expand Down
Loading
0