Skip to content

Conversation

@dancoates
Copy link
Contributor

@dancoates dancoates commented Mar 26, 2025

PR #729 aimed to improve performance by removing the use of stream_with_context from the response handling. While this did improve performance it meant that we're now hitting the 32mb response size limit that cloud run imposes for non-streaming responses.

This update reintroduces a streaming response, but using a different method that doesn't have the same small chunk size that was causing the performance issue previously. The docs on this are pretty minimal but this is pulling together some info from both the flask docs on streaming:
https://flask.palletsprojects.com/en/stable/patterns/streaming/

and the fast api docs on streaming a file-like binary response: https://fastapi.tiangolo.com/advanced/custom-response/#using-streamingresponse-with-file-like-objects

PR #729 aimed to improve performance by removing the use of
stream_with_context from the response handling. While this did improve
performance it meant that we're now hitting the 32mb response size limit
that cloud run imposes for non-streaming responses.

This update reintroduces a streaming response, but using a different
method that doesn't have the same small chunk size that was causing the
performance issue previously. The docs on this are pretty minimal but
this is pulling together some info from both the flask docs on
streaming:
https://flask.palletsprojects.com/en/stable/patterns/streaming/

and the fast api docs on streaming a file-like binary response:
https://fastapi.tiangolo.com/advanced/custom-response/#using-streamingresponse-with-file-like-objects
@dancoates dancoates requested a review from violetbrina March 26, 2025 04:50

@app.route('/<dataset>/<path:filename>')
def handler(
def handler( # noqa: C901
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding the extra iterfile function took this over an arbitrary complexity limit, to fix would need to refactor out some of the other code in the handler function, not keen to do that in this PR as it would make the diff and intent of the change unclear.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fine by me.

Copy link
Collaborator

@violetbrina violetbrina left a comment

Choose a reason for hiding this comment

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

Thanks for the links in the description. Made this a super fast review. Conceptually the returning the generator makes sense. Hope this works!

@dancoates dancoates merged commit 4ea26a2 into main Mar 26, 2025
9 of 10 checks passed
@dancoates dancoates deleted the change-web-server-back-to-streaming branch March 26, 2025 05:23
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