Monday, June 17, 2013

Server is running slow- how do you debug?

This is a common interview question:
You come to your work and discover that your server seems to run slowly all of a sudden.  You know it was running fast before.  How would you debug it?

Well, after some casual research, this is the response that I would give:

The reason why a computer is running could be one of the following:

  1. The system might be running slow
  2. Internet connection could be slow
  3. The server could be running slow
The system could be running slow if 
  • there is a different process that is taking up resources that server needs.  For example, some hardware scanning is taking place.  Depending on the OS, you can use different commands to list all processes and kill those that are slowing the system down.
Internet connection could be slow for various reasons
  • Use some network softwares to figure out Internet speed.
The server could be running slow if

  • Denial of Service attack happens:  Check the HTTP log file.  If there happens to be too many requests from the same IP address, it is a Denial of Service attack.  Solution is to configure network router to block that particular IP address.
  • The code might have run into infinite loop:  Check CPU usage.  If it is high, probably it is in an infinite loop.  Get heap dump or thread dump over two or three different times.  If it is an infinite loop, you would see the same method listed in thread dump.
  • Garbage Collector is running frequently (memory leak).  If Garbage Collector runs, then, no threads is executed.  Basically, the frequent execution of Garbage Collector means - the application is not getting enough memory for its execution.  Some memory leak could be the reason.  Take a Heap dump to see which objects occupy the maximum memory and using the source, analyze which part of code is contributing to this.
  • Some external system that the application depends upon, may be slow.  Check logs.  The database might be running slow and timing out, some web service may be running slow and timing out.

No comments:

Post a Comment