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.
Reasoning: I thought that the server would cache the html from the webstie into the server and serve it to the client, in order to prevent this i disabled caching in the routes with the most html.
Reasoning: I thought that the server would cache the html from the webstie into the server and serve it to the client, in order to prevent this i disabled caching in the routes with the most html.
2) Disabled Polling Inside Of My Website
Reasoning: My project Uses Websockets, and when a socket is not connected it reverts to polling. I figured that this setup could be persistantly calling the server and putting on a load.
Reasoning: My project Uses Websockets, and when a socket is not connected it reverts to polling. I figured that this setup could be persistantly calling the server and putting on a load.
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?
No description
4 Replies
Percy
Percy3mo ago
Project ID: c143cb36-1764-4a8e-8676-e5c1f4a33422
ImaMoonky
ImaMoonkyOP3mo ago
c143cb36-1764-4a8e-8676-e5c1f4a33422
Brody
Brody3mo ago
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.
ImaMoonky
ImaMoonkyOP3mo ago
thanks ill look into it!
Want results from more Discord servers?
Add your server