NextJS + Railway Memory Leak
Hello!
I have a NextJS Project that uses websockets. I have deployed to Railway successfully, but am concerned about the memory usages of the server.
The problem is this. After deploying a change to the website the server load is around 200mb. Then when a user connects to the website the server load suddenly jumps up to around 400-500mbs. Even though this is quite a significant load, I am not worried about this spike.
The issue that I am worried about is that this spike seems to persist even if that user ceases to use the website. So that 400mbs-500mbs will stay with the server until after another deployment. It is constantly using resources and I am not quite sure why.
I have stress tested my website with multiple clients open all sending messages and the server spiked to 1.5GB of memory usage which would not fall down even after all clients disconnected.
Here is a list of the things that I have tried to fix this issue:
1) Used export const dynamic = 'force-dynamic' in order to stop caching of data inside of the server in case this was a problem.
2) Disabled Polling Inside Of My Website
3) Checked logs To See if Sockets are disconnecting correctly (They Are)
4) https://github.com/vercel/next.js/issues/49929
I have also checked this github issues post. However most of the comments seem to suggest that the issue is with the appdir. I am using the app directory structure in my application, and cannot turn off the appdir like some in this thread are saying to do as a solution.
Are there any railway/next settings that I can configure to help alleviate these issues?
4 Replies
Project ID:
c143cb36-1764-4a8e-8676-e5c1f4a33422
c143cb36-1764-4a8e-8676-e5c1f4a33422
Hey, this isnt something we would be able to help with at a platform level - https://docs.railway.app/reference/pricing/faqs#why-is-my-resource-usage-higher-than-expected
tl;dr - we simply report what your app uses and have no control over how it uses the memeory.
This is something you would need to fix with your application itself.
thanks ill look into it!