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

Avoid overeager garbage collection #6518

Merged
merged 2 commits into from
Mar 18, 2024
Merged

Avoid overeager garbage collection #6518

merged 2 commits into from
Mar 18, 2024

Conversation

philippjfr
Copy link
Member

As part of #6502 I discovered that we still run garbage collection whenever a session is destroyed. Previously we had set up scheduled tasks to run garbage collection AFTER a session is destroyed ensuring that if multiple sessions are closed in succession we only run the task once. In this PR we do two things:

  1. Replace the _on_session_destroyed handler on DocumentLifecycleHandler overriding the default handler which runs garbage collection
  2. Add debouncing to the Document.destroy garbage collection task so it runs 5 seconds after the last session was destroyed, i.e. if multiple sessions are destroyed in quick succession we only run the garbage collection cycle 5 seconds after the last session is destroyed.

Copy link

codecov bot commented Mar 18, 2024

Codecov Report

Attention: Patch coverage is 59.45946% with 15 lines in your changes are missing coverage. Please review.

Project coverage is 82.92%. Comparing base (ddedd8d) to head (31f7ff6).
Report is 3 commits behind head on main.

Files Patch % Lines
panel/io/document.py 47.82% 12 Missing ⚠️
panel/io/application.py 78.57% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6518      +/-   ##
==========================================
- Coverage   82.93%   82.92%   -0.02%     
==========================================
  Files         313      313              
  Lines       45864    45902      +38     
==========================================
+ Hits        38039    38063      +24     
- Misses       7825     7839      +14     
Flag Coverage Δ
ui-tests 40.11% <45.94%> (+<0.01%) ⬆️
unitexamples-tests 71.13% <59.45%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

panel/io/application.py Outdated Show resolved Hide resolved
panel/io/document.py Outdated Show resolved Hide resolved
@philippjfr philippjfr merged commit 864a514 into main Mar 18, 2024
15 checks passed
@philippjfr philippjfr deleted the gc_sessions branch March 18, 2024 13:30
at = dt.datetime.now() + dt.timedelta(seconds=new_time)
state.schedule_task('gc.collect', _garbage_collect, at=at)
return
gc.collect()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can set _panel_last_cleanup here so that if a session is destroyed say every 4 seconds (maybe some automated polling script), then we don't end up never running cleanup!

That would also mean the first session destroyed will cause very quick gc but any immediately following session destruction will only call gc at 5s intervals.

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

Successfully merging this pull request may close these issues.

None yet

3 participants