1

I have developed a chat application using node JS, express JS, mongodb and socket io. Messages sent & received are stored in mongodb. But when I run the chat application the server CPU usage spikes continuously. See the attached screenshot:enter image description here

It seems that something is stacking up. When I stop the chat application then the usage is resumed to minimum. What can be possible methods to fix this ?

2
  • Just to clarify/confirm here - what is running on the server where you are observing the elevated CPU usage? Just the Node app or are there more components (eg the database) on that server as well? Commented Oct 6, 2022 at 12:27
  • Only node app is running on this server. No database, no other app. Commented Oct 7, 2022 at 10:21

1 Answer 1

1

There are a few potential methods you could use to debug this issue:

  1. Use the node.js built-in debugger. You can set breakpoints in your code and then run your chat application under the debugger to see where the CPU usage is spikes are happening.

  2. Use a profiler to take a look at what your chat application is doing when it's running. This can help you to identify which parts of the code are using up the most CPU time.

  3. Use a performance monitoring tool to track the CPU usage of your chat application over time. This can help you to identify whether the issue is getting worse or if there are any patterns to the spikes in usage.

  4. Try to reproduce the issue in a test environment and then use a debugging tool like strace or ltrace to see what system calls are being made when the CPU usage spikes. This can help you to identify what the chat application is doing that is causing the issue.

It's hard to answer your question without more information, but some sanity checks:

  • Make sure that you are not running too many processes on your server. If you are running multiple node.js applications on the same server, that can lead to high CPU usage. Try running each application on its own server, or limiting the number of processes that are running on each server.

  • Try using a different server environment. If you are using a shared hosting environment, the CPU usage may be spikes due to other users on the same server. Try using a dedicated server, or a virtual private server, which can help to reduce the CPU usage.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.