Skip to content

Add Fastly session-reuse to WSGI HTTP handler, and demo it in game-of-life.#17

Merged
erikrose merged 2 commits into
mainfrom
multi-request
Nov 18, 2025
Merged

Add Fastly session-reuse to WSGI HTTP handler, and demo it in game-of-life.#17
erikrose merged 2 commits into
mainfrom
multi-request

Conversation

@erikrose
Copy link
Copy Markdown
Member

@erikrose erikrose commented Nov 4, 2025

Implementation is ugly as sin due to the early state of Python WIT bindings, but the user-facing API should be fine.

Interestingly, it doesn't make any speed difference on my local machine, but maybe it would in prod.

…-life.

Implementation is ugly as sin due to the early state of Python WIT bindings, but the user-facing API should be fine.
`sys` is no longer needed to pull in shims. `noqa`s don’t seem to be needed either.
@erikrose erikrose requested a review from posborne November 4, 2025 20:27
Copy link
Copy Markdown
Member

@posborne posborne left a comment

Choose a reason for hiding this comment

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

I just noticed that I failed to submit the review I started on this, apologies!

Generally I think things look good -- it would be awesome to be able to showcase the actual timing improvement of reusable sessions, but I guess I'm not surprised to see much difference given that the component-init bits used by componentize-py are doing what they ought to do.

Comment thread fastly_compute/wsgi.py
body,
self.wsgi_app,
handle_errors=self.handle_errors,
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not critical and possibly better left outside the SDK (or configurable), but I could see it potentially making sense to use intra-request periods as being good times to force gc with an otherwise relaxed gc policy to avoid it being hit while processing a request in most cases.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's a neat idea. We could make it so there's a pluggable callback that we call inter-request, and you can take whatever breaths you need therein. A GC-nudging one could be the default or a publicly available one.

@erikrose erikrose merged commit 715dc14 into main Nov 18, 2025
3 checks passed
Comment thread fastly_compute/wsgi.py
self,
wsgi_app: Callable,
handle_errors: bool = False,
reuse_sessions_for_ms: int = 0,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should rename this to reuse_sandboxes_for_ms, to align with Compute eg. https://github.com/fastly/ExecuteD/pull/5981.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ha, I got the timing exactly wrong! Will do.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

#21

@erikrose erikrose deleted the multi-request branch February 3, 2026 16:10
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.

3 participants