Troubleshooting CPU Spike on ServiceNow MID Server

Troubleshooting JVM CPU spike errors on ServiceNow servers is crucial for maintaining optimal system performance.  In this blog post, we will discuss how to simulate CPU spike problems in the MID Server, which is running on ServiceNow, AWS EC2 environment. We will also show an effective strategy to troubleshoot and fix this CPU spike problem.

What can cause a CPU spike in ServiceNow?

Below are some of the reasons that can cause CPU spikes in the ServiceNow environment:

  1. In large applications integrated with ServiceNow, unexpected CPU spikes can occur when there are inefficiently designed or poorly optimized code segments that lead to excessive resource consumption.
  2. The improper handling of multithreading within the application, such as creating numerous threads without proper management, can contribute to CPU spikes, impacting the overall performance.
  3. Integration issues or bugs between the application and the ServiceNow platform may result in repetitive or resource-intensive operations, causing spikes in CPU usage during data exchanges or service interactions.
  4. Memory leaks in the application, where allocated memory is not released properly, can lead to increased CPU usage over time as the system struggles to manage available resources.
  5. External factors such as sudden increases in user traffic, unexpected data loads, or service disruptions within the ServiceNow environment can also trigger CPU spikes in the integrated application.

Configuration MID server on ServiceNow infrastructure

We have provided a detailed walk-through on essential steps on how to set up, configure MID Server in ServiceNow infrastructure in this guide. From creating a ServiceNow application and incorporating Java apps to optimizing MID Server performance, the guide is a valuable resource for enhancing IT service management. It also emphasizes on the importance of launching a Windows Server EC2 instance on AWS and integrating a JAR file into the MID Server. Additionally, installing JDK 21 ensures compatibility with the latest Java features, aligning with industry standards. Check out the full guide for an in-depth exploration of each crucial step in configuring the MID Server for ServiceNow.

Simulating CPU spike in MID Server

The Java program given below simulates CPU spike on any machine/container in which it’s launched:

public class CPUSpike {


public static void main(String[] args) {
System.out.println("Java Process ID (PID): " + getProcessId());
start();
}

public static void start() {
new CPUSpikerThread().start();
new CPUSpikerThread().start();
new CPUSpikerThread().start();
new CPUSpikerThread().start();
new CPUSpikerThread().start();
new CPUSpikerThread().start();
System.out.println("6 threads launched!");
}

private static String getProcessId() {
// Attempt to get the process ID
String processName = java.lang.management.ManagementFactory.getRuntimeMXBean().getName();
if (processName != null && processName.indexOf('@') != -1) {
return processName.substring(0, processName.indexOf('@'));
}
return "Unknown";
}
}

class CPUSpikerThread extends Thread {

@Override
public void run() {
while (true) {
// Just looping infinitely
}
}
}

You can notice the ‘CPUSpike’ class, launches six threads by name ‘CPUSpikerThread’. Each thread loops on the condition ‘while(true)’. It means each thread would loop infinitely. Even if one thread loops infinitely, CPU will start to spike up on the ServiceNow’s MID server, needless to say what will happen to CPU consumption when six threads start to loop infinitely.

Let’s create a JAR (Java Archive) file from this program and upload it to MID Server as documented in this MID Server setup guide. So that this program can simulate CPU spikes in the ServiceNow’s MID Server. Note, you can create jar file by issuing below command:

jar cfme CPUSpike.jar Manifest.txt CPUSpike CPUSpike.class

yCrash’s CPU spike diagnosis in ServiceNow

yCrash is a simple, robust monitoring tool that identifies performance bottlenecks and provides actionable recommendations in the ServiceNow environment. Infact, ServiceNow organization itself internally uses yCrash to troubleshoot their performance problems.

When the above CPU spike program was run in ServiceNow’s MID Server, yCrash monitored the micro-metrics of the ServiceNow environment and immediately detected problems and reported them in the dashboard.

yCrash’s report summary indicating CPU Spike problem
Fig 1: yCrash’ report summary indicating CPU Spike problem

In the summary, you can observe that yCrash is reporting that 6 threads are looping, which is causing the application’s CPU to spike up. In fact, it’s also giving the ‘stacktrace’ hyperlink of the threads which are looping. When we clicked on the ‘stacktrace’ hyperlink in the report, it showed the detailed thread stack traces unraveling the mystery behind a persistent CPU spike issue.

yCrash pointing out threads & lines of code that were causing the CPU to spike
Fig 2: yCrash pointing out threads & lines of code that were causing the CPU to spike

Above is the screenshot from yCrash showing the stackstraces of the threads that were looping. You can notice that it’s pointing out exact line of code #32 in the CPUSpike.java, where we have written ‘while(true)’ in the program. This is the exact line of code that is causing the CPU to spike up.

By examining the stacktraces, one can gain a comprehensive understanding of the execution flow during the heightened CPU utilization. This level of granularity will allow us to pinpoint specific threads and identify the precise line of code contributing to the CPU spike.

Conclusion

In essence, yCrash’s analysis will not only help you to isolate CPU spikes, but also plays a crucial role in formulating an effective resolution strategy. It empowers you to make informed decisions based on real-time runtime behavior, resulting in a more optimized and resilient ServiceNow application. If you want to diagnose performance problems in your ServiceNow deployment using yCrash you may register here.

Share your Thoughts!

Up ↑

Index

Discover more from yCrash

Subscribe now to keep reading and get access to the full archive.

Continue reading