I am running server-side software on Digital Ocean servers. These include Docker, NPM, Node.js, and others. The server is running Ubuntu 22.04.
Sometimes, the server hangs randomly for several minutes. There is no pattern in hangs. You cannot even SSH into the server. After a few minutes, the server resumes operations normally.
Here are the server performance metrics extracted from Digital Ocean dashboard during the hang:
Digital Ocean servers are installed without a swap file for Linux.
Even if your server has enough RAM to run all the programs, there might be scenarios where the Linux applications struggle because there is no swap file, because how the memory management in Linux is implemented. This is because many applications overcommit and hoard memory they do not use, or there might be usage patterns that cause the fragmented RAM to be unallocable for a moment.
Simply creating a small swap file will likely solve the issues, even if the swap itself is unlikely to see much use.
It is recommend the swap file is the 1-2x size of the RAM.
To create and enable Linux swap file (6 GB):
Check Resource Usage: Use tools like top, htop, or Digital Ocean's monitoring tools to monitor CPU and memory usage when your server hangs. If these resources are consistently maxed out, you might need to upgrade your server plan to one with more resources. Container Limits: Docker containers have resource limits (CPU shares, memory limits) that might be causing issues if exceeded. Check Docker container configurations (docker inspect <container_name> or Docker Compose files) to ensure they are appropriately configured.