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

Implement ability to reuse session for initial render #3679

Merged
merged 9 commits into from
Apr 16, 2023
Merged

Conversation

philippjfr
Copy link
Member

This is an experiment to see if we can improve the speed of handling the initial request. The basic idea behind this is that in most cases the initial page served to the user is identical, i.e. the template does not differ between sessions. As long as that holds true we can simply cache the first session for each endpoint and reuse that to render the template served to the user. In the background we can then still create a session for each user which the rendered template connects to.

The way this works is that we simply modify the token which tells the frontend which session it should connect to. So the steps are:

  1. User visits application
  2. The DocHandler uses a cached session to render the template
  3. We swap out the session_id in the token so that the frontend does not re-connect to the existing session
  4. When the frontend establishes the Websocket connection a new session is created

This will significantly reduce time to first render but also comes with some caveats and drawbacks:

  • Even though the initial render is faster establishing the websocket connection will be slower because we have simply postponed when the session is created
  • This will not work if the initial page render is dependent on some state, e.g. a query parameter determines the theme or a header/cookie is used to render the user into the header.

@codecov
Copy link

codecov bot commented Jul 9, 2022

Codecov Report

Merging #3679 (90a37e0) into main (0df3be5) will increase coverage by 0.03%.
The diff coverage is 90.51%.

@@            Coverage Diff             @@
##             main    #3679      +/-   ##
==========================================
+ Coverage   83.17%   83.20%   +0.03%     
==========================================
  Files         263      264       +1     
  Lines       37234    37350     +116     
==========================================
+ Hits        30968    31076     +108     
- Misses       6266     6274       +8     
Flag Coverage Δ
ui-tests 39.65% <38.79%> (-0.01%) ⬇️
unitexamples-tests 73.26% <75.86%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
panel/tests/ui/io/test_server.py 73.52% <73.52%> (ø)
panel/io/server.py 76.63% <96.87%> (+1.17%) ⬆️
panel/tests/test_server.py 99.34% <97.29%> (-0.14%) ⬇️
panel/command/serve.py 35.95% <100.00%> (+0.26%) ⬆️
panel/config.py 68.11% <100.00%> (+0.83%) ⬆️
panel/io/state.py 72.72% <100.00%> (+0.09%) ⬆️
panel/tests/conftest.py 90.03% <100.00%> (+0.32%) ⬆️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@philippjfr philippjfr added the type: enhancement Minor feature or improvement to an existing feature label Aug 23, 2022
@philippjfr philippjfr added this to the Version 0.14.0 milestone Aug 23, 2022
@philippjfr philippjfr modified the milestones: Version 0.14.2, v0.14.3 Dec 19, 2022
@philippjfr philippjfr modified the milestones: v0.14.3, next Feb 1, 2023
@philippjfr philippjfr modified the milestones: next, v1.0.0 Mar 14, 2023
@philippjfr philippjfr merged commit ac20c42 into main Apr 16, 2023
@philippjfr philippjfr deleted the reuse_sessions branch April 16, 2023 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants