-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Investigate memory usage with Image Optimization enabled #54482
Comments
Hey Tim, I've been looking into this for our site that is deployed on Railway and realized that it may be purely driven by the fact that optimized images are stored in memory. If a site has a lot of images, I assume that the build up of optimized images could look like a memory leak? Our images aren't huge but we do have quite a few, say 10,000, and this is what our memory usage looks like over a few hours with optimized images enabled: This builds up to like 7gb over a ~24 hour period which then forces us to restart the server. A similar thing happens in this reproduction: https://github.com/AlphaBravoIndia/next-image-memory-leak Whenever I refresh the page a bunch of times it generates more optimized images and memory usage spikes and stays higher than the previous point. This makes me think that it's purely the optimized images pushing memory usage up rather than a leak. If I stop refreshing the page, the memory usage stays consistent (at the new level). Should optimized images be dumped from memory after a certain amount of time automatically or is this something that we need (or can) configure? Cheers! |
Can confirm we are seeing this issue in production on Setting unoptimised images in the {
images: { unoptimized: true },
} Note: we are not using sharp |
Thanks @csi-lk |
Any ideas on how to fix this issue other than setting unoptimized? We would still like to optimize the image but this memory leak is forcing us no choice but to turn optimization off |
This comment has been minimized.
This comment has been minimized.
Do we have an update on this? As @mengqing mentioned it would be great to have the possibility to still optimize the images 😃 |
It's probably better to offload the compute to its own service rather than forcing the main app server to handle it... which will block the main server and significantly reduce your throughput/latency. |
Do you guys think the cause of the memory leak is sharp or image optimised? |
Hmmm, as I mentioned above "Note: we are not using sharp" so I doubt it's related to sharp I also haven't looked back into this for a while as we are just "pre-optimizing" our images manually (using img-optim then shipping those) |
We have the same issue. We have thousands of images and very quickly our server gets crushed if we have optimization enabled across the site, even with very little traffic routed that server (lets say 100 page views/hour). We've since kept it to our ~30 or so static images and have offloaded everything else to Cloudinary, but it would be nice to use this function in more places. Edit: turns out this is likely because we are on Heroku and it's filesystem is ephemeral. I think this looks for the file in the filesystem, can't find it, then generates a new image, but doesn't purge from memory until it can be found in or saved to the filesystem or something. |
Are you guys seriously not gonna fix that? It's been a long time now, and I'm getting frustrated overtime, by having poor developer experience. |
I think I'm also seeing this issue. I'm deploying to a linux VM and I find myself often restarting my machines every few days. My apps almost no users, but still the memory slowly climbs from 300mb up to 700mb over days. I'm assuming it's related to images but I haven't verified. I'm using Sharp as well if that helps debug anything. |
Are you using |
I'm also experiencing this issue running Nextjs in a DO Droplet with sharp. Same thing where the app consumes significantly more memory as images are fetched. Irony is that it's a demo app that gets maybe 1 or 2 users every now and then, and has like 30 images in total. Next is consuming 300mb of ram almost immediately after serving the app and slowly gains more.
|
My vercel deployment's taking up 6gb ram on my computer when I open a production build 😵💫😵💫 we need an update on this Nextjs team |
For me this issue is also present in development. Running a simple 2 pages app with next 14.2.5 and having a big hero taser (9.4mb). When setting images.unoptimized to true, memory maxes out at 900mb (already quite a lot but okay). When removing this option and refreshing the page with the image in the browser a few times it spikes at 3.5-4GB. Also removing the image from the page decreses memory significantly so I am sure this is the reason for my high consumption. |
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
Image optimization (next/image, next/legacy/image)
Link to the code that reproduces this issue or a replay of the bug
Reproduction was left out in reports in #49929
To Reproduce
Unfortunately we haven't received a reproduction of these reports so this needs a reproduction in order to investigate. We'll keep this issue open for the standard 30 days before closing it if there is no reproduction provided.
Describe the Bug
In #49929 some people reported high memory usage / some claim a memory leak when image optimization is enabled. Unfortunately we haven't been able to verify this as there is no reproduction provided for these, only monitoring tool screenshots.
We'll keep this issue open temporarily hoping that someone will provide a reproduction so that it can be investigated.
Expected Behavior
Unclear as of right now, as there is no reproduction yet.
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: