DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Real-World Garbage Collection Scenarios and Solutions
  • SQream Accelerates Time to Insight Across Massive Datasets
  • Power of Azure B Series Virtual Machines
  • From CPU to Memory: Techniques for Tracking Resource Consumption Over Time

Trending

  • Analyzing “java.lang.OutOfMemoryError: Failed to create a thread” Error
  • Beyond ChatGPT, AI Reasoning 2.0: Engineering AI Models With Human-Like Reasoning
  • Your Ultimate Website QA Checklist
  • Platform Engineering for Cloud Teams
  1. DZone
  2. Software Design and Architecture
  3. Performance
  4. Nice CPU Time – ‘ni’ Time in Top

Nice CPU Time – ‘ni’ Time in Top

The series continues with a look at nice time.

By 
Ram Lakshmanan user avatar
Ram Lakshmanan
DZone Core CORE ·
Feb. 21, 21 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
9.8K Views

Join the DZone community and get the full member experience.

Join For Free

CPU consumption in Unix/Linux operating systems are studied using 8 different metrics: User CPU time, System CPU time, nice CPU time, Idle CPU time, Waiting CPU time, Hardware Interrupt CPU time, Software Interrupt CPU time, and Stolen CPU time. In this article, let's study ‘nice CPU time’.

What Is ‘nice’ CPU Time?

To understand ‘nice’ CPU time, one must first understand ‘nice’. When there is a CPU contention (i.e., multiple processes contend for CPU cycles), the process with higher priority are given more chances to run. In Unix/Linux operating systems, processes are launched with a priority 0 (default). However, using the ‘nice’ command, super users (like ‘root’) can set the priority for the processes as shown below:

Shell
 




x


 
1
nice -n nice_val [command]



Example:

Shell
 




xxxxxxxxxx
1


 
1
nice -n 15 java -jar buggApp.jar



Priority can range from -20 to 19. -20 is the highest priority with which a process can be launched. 19 is the lowest priority. For more options on how to launch process with nice priority or change the priority level using the renice command, refer to this article.

‘nice CPU time’ is the amount of time a CPU spends in running low priority processes (whose nice values are greater than 0). 

How to Find ‘nice’ CPU Time

nice CPU time can be found from the following sources:

a. You can use web-based root cause analysis tools to report ‘nice’ CPU time. Use a tool capable of generating alerts if the ‘nice’ CPU time goes beyond a threshold. It should generate alerts if your application process is running with low priority.

b. ‘nice’ CPU time is also reported in the Unix/Linux command line tool ‘top’ in the field ‘ni’ as highlighted in the below image..

                                                                         Fig: ni time in top

How to Simulate High ‘nice’ CPU Time

To simulate high ‘nice’ CPU reporting, let’s use BuggyApp. BuggyApp is an open source Java project that can simulate various sort of performance problems. When you launch  BuggyApp with the following arguments, it will cause the CPU consumption to spike up on the host. 

Shell
 




xxxxxxxxxx
1


 
1
 java -jar buggyApp.jar PROBLEM_CPU



Now let’s launch BuggyApp with three different priorities and study the ‘nice’ CPU time reporting in the ‘top’. 

1. Default Priority

Now let’s launch BuggyApp with default priority using the command:

Shell
 




xxxxxxxxxx
1


 
1
java -jar buggyApp.jar PROBLEM_CPU



 Below is the screenshot of ‘top’ reporting on the host:

Fig: Normal priority process CPU consumption reported under ‘user’ in top

You can see that BuggyApp’s CPU utilization is reported under ‘user’ CPU utilization. You can see the ‘user’ CPU time is at 99.3%, whereas ‘nice’ CPU utilization is at 0.0%.

Note: ‘user’ CPU utilization is the amount of time your application spends executing application level code. To learn more about ‘user’ CPU time, refer to this article.

2. Low Priority

Now let’s launch the same BuggyApp with a low priority nice value ’10’. (Note: As values go higher than 0, priority becomes lower). You can launch the BuggyApp with low priority 10 using the ‘nice’ command:

Shell
 




xxxxxxxxxx
1


 
1
nice -n 10 java -jar buggyApp.jar PROBLEM_CPU



 Below is the screenshot of ‘top’ reporting on the host:

Fig: Low priority process CPU consumption reported under ‘nice’ in top

You can see that BuggyApp’s CPU utilization is reported under ‘nice’ CPU utilization. You can see the ‘nice’ CPU time is at 99.3%, whereas ‘user’ CPU utilization is at 0.3%. The reporting is the total opposite of what we saw when the process was launched with default priority.

3. High Priority

Now let’s launch BuggyApp with a high priority nice value of ‘-10’. You can launch BuggyApp with high priority -10 using the ‘nice’ command:

Shell
 




xxxxxxxxxx
1


 
1
nice -n -10 java -jar buggyApp.jar PROBLEM_CPU



 Below is the screenshot of the ‘top’ reporting on the host:

Fig: High priority process CPU consumption reported under ‘user’ in top

You can see that BuggyApp’s CPU utilization is reported under ‘user’ CPU utilization. You can see the ‘user’ CPU time is at 99.3%, whereas ‘user’ CPU utilization is at 0.0%. Note: Reporting is totally opposite of what we saw when the process was launched with lower priority.

What to Do if ‘nice’ CPU Time Is High

1. If your production application (and its dependent processes) are running with low priority and it is causing the nice CPU time to get too high, then increase the priority. Production applications should always run with default or high priority. 

2. If ‘nice’ CPU consumption is intermittently high, then identify the process with high CPU time using a tool or the top command. Once identified, the tactical/short-term solution is to restart the offending process. The strategic/permanent solution is to optimize application performance.

3. If ‘nice’ CPU consumption is consistently high, then it could be indicative that you are running short on compute capacity. In such circumstances, you can do a couple of things:

  • a. Upgrade the capacity of your device. Maybe move to a better EC2 instance (if you are in a cloud environment).
  • b. Reduce the number of processes running on that device.
  • c. Try adding more devices (i.e., EC2 instances) to your application pool so that your workload can be distributed.
CPU time

Opinions expressed by DZone contributors are their own.

Related

  • Real-World Garbage Collection Scenarios and Solutions
  • SQream Accelerates Time to Insight Across Massive Datasets
  • Power of Azure B Series Virtual Machines
  • From CPU to Memory: Techniques for Tracking Resource Consumption Over Time

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!