Next Image and Caching. High RAM usage.

Hi, recently i've been looking more closely at my RAM usage on my nextjs droplet. And i've noticed that the RAM on a fresh instance of the app sits at around 150mb (on the node process), but after some time and clicking around on the website it starts racking up to as much as 1.4GB/1.5GB I have available - this dramatically slows down everything. I turned image optimization off, and it never got higher than 300mb with it off. Is this normal? Am I doing something wrong?
22 Replies
Neto
Neto2y ago
Wonders of caching Next needs to cache the images somewhere to avoid lookups
Xaohs
Xaohs2y ago
Ye but it shouldn't fill that much RAM up should it??? Like that's actually nuts. I have a lot of images, but still. Is there no way to use optimization but still keep my RAM usage low?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Xaohs
Xaohs2y ago
Not an option. I have over 20k images
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Xaohs
Xaohs2y ago
Hey thanks for the idea. I had already read through this but read this: The expiration (or rather Max Age) of the optimized image is defined by either the minimumCacheTTL or the upstream image Cache-Control header, whichever is larger. Where can I check my upstream image Cache-Control header? I had already messed around with the TTL but didn't get any results out of it. So i'm wondering if the upstream header is set to something high
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Xaohs
Xaohs2y ago
I'll try that thank you
Xaohs
Xaohs2y ago
Yeah the cache control from the img is
Xaohs
Xaohs2y ago
So i'll try putting a TTL to see if my RAM get's reduced after some time Yeah made zero difference putting a TTL of 60s My RAM still stays the exact same after rendering in images
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Xaohs
Xaohs2y ago
Ah yeah, that won't fix my problem then. The problem is once an image is called it is stored permanently in my server's RAM Which I don't want as I have over 20k images, and if every image takes up 700kb of RAM, my RAM will be filled after 3K images
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Xaohs
Xaohs2y ago
Yeah but will this really be the solution to my problem? Another thing I have noticed. When I go through a page with 500 images the following happens: Optimized - true -> RAM starts out at 150mb before opening page. While scrolling through, my CPU will hit around 83% usage consistently, Images will load in pretty slow, as in 2-3sec per image. RAM usage will start skyrocketing. After loading in all 500 images RAM hits 900mb. This stays forever until server restarts, not a single MB gets dropped. Optimized - false -> RAM starts out at 150mb before opening page While scrolling through, CPU is around 60% consistantly (less than optimized images) Images will load in extremely fast, in split second. Even though resolution loaded in is 1700x1100 instead of ~400px RAM usage will go pretty high, after all 500 images loaded, around 700mb. But after around a minute or two, it will dip down back to ~150mb. The overall performance of optimized images seems absolutely terrible to me? even tuogh they are being loaded in at a lower resolution, my CPU usage is way higher, and my RAM skyrockets permanently, images also get loaded in WAY slower
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server