Skip to content

Commit

Permalink
Merge pull request #953 from jeff4747/release-daemon-memory
Browse files Browse the repository at this point in the history
Release memory when a deamon exits
  • Loading branch information
nolar authored Feb 7, 2023
2 parents b65aad0 + 286b74e commit 7072788
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions kopf/_core/engines/daemons.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,20 @@ async def _runner(
if stopper.reason is None:
memory.forever_stopped.add(handler.id)

# If this daemon is never going to be called again, we can release the
# live_fresh_body to save some memory.
if handler.id in memory.forever_stopped:
# If any other running daemon is referencing this Kubernetes
# resource, we can't free it
can_free = True
this_daemon = daemons[handler.id]
for running_daemon in memory.running_daemons.values():
if running_daemon is not this_daemon:
can_free = False
break
if can_free:
memory.live_fresh_body = None

# Save the memory by not remembering the exited daemons (they may be never re-spawned).
del daemons[handler.id]

Expand Down

0 comments on commit 7072788

Please sign in to comment.