jacebrowning / memegen

The free and open source API to generate memes.
https://memegen.link
MIT License
1.36k stars 192 forks source link

Tricks to make it faster? #860

Open mikealche opened 6 months ago

mikealche commented 6 months ago

Hey there! What a fun project!! I'm having loads of fun using it.

I want to render a page where there are many memes (well 12 really) , and this seems to almost take down the deployment (the cheapest Heroku Dyno).

What tricks can I use to make it lighter on the server? Specifying smaller dimensions? Upgrading the Heroku Dyno? Thanks!

jacebrowning commented 6 months ago

https://api.memegen.link is running as a single basic Dyno and handling about 2k requests per hour.

For the provided Procfile, the following environment variables are set:

MAX_REQUESTS=400
MAX_REQUESTS_JITTER=50

It's also running behind Cloudflare to cache images, but that shouldn't impact server performance for new images.

mikealche commented 6 months ago

Thanks for the tip! yesterday I've added those env vars. However, Heroku keeps restarting bc of memory quota exceeded. (each red box in the above graph is a critical event that shuts down the Dyno)

image

Could there may be a memory leak somewhere?

jacebrowning commented 6 months ago

It's possible there could be a memory leak, though I suspect that would be in the image generation library (Pillow). Any investigation into that would be appreciated!