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

change image_raw to async #82

Merged
merged 1 commit into from
Jul 31, 2024

Conversation

ratsclub
Copy link
Member

This improved the image loading quite a bit on my cheap VPS 😅

@sirodoht
Copy link
Member

@ratsclub interesting! How do you measure it? I would imagine it makes no different since it's the only operation in the view.

Also, does this require an ASGI server (eg. uvicorn) rather than gunicorn, which is what we currently use?

@ratsclub
Copy link
Member Author

ratsclub commented Jul 29, 2024

interesting! How do you measure it?

I'm hosting my instance on Hetzner with about 250ms of latency. I tested this with a post containing dozens of images. The results I had was that the sync request tried to load the images in order while the async loaded the smaller images first.

Also, does this require an ASGI server (eg. uvicorn) rather than gunicorn

You can continue using gunicorn just fine, but should run uvicorn to have the proper async support which is what I'm running on my server. See Asynchronous support on the docs.

By the way, another thing that could be improved on the html generation is to make all img tags have loading=lazy by default.

@thiagokokada
Copy link

@ratsclub interesting! How do you measure it? I would imagine it makes no different since it's the only operation in the view.

Also, does this require an ASGI server (eg. uvicorn) rather than gunicorn, which is what we currently use?

I can try to answer some questions since I helped @ratsclub with this issue.

@ratsclub said that the issue happens especially in posts with multiple high resolution images in high latency connections (250ms+), when just some images would load at a time.

I imagine the reason is that since each blog post is loaded in a synchronous way, they're going to block the thread until the image is loaded on the other client. Async can help since once the request for the image is waiting for I/O (and this can take a while for bigger images), the thread can be released and and start handle another request.

It seems @ratsclub is using uvicorn, and I am not sure what the impact is on gunicorn, but from looking at the documentation it seems it shouldn't make a difference, it is just that gunicorn wouldn't have the advantages that uvicorn can have.

@sirodoht
Copy link
Member

Thanks @ratsclub and @thiagokokada! That sounds great! I'll test this and merge it :D

@sirodoht sirodoht merged commit 7eaca71 into mataroa-blog:main Jul 31, 2024
4 checks passed
@ratsclub ratsclub deleted the upstream-image_raw branch September 17, 2024 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants