How “Niceness” impacts shared servers!

A very well known word in linux server is “nice” value. I have seen many people discussing about the effectiveness of Apache/Mysql tweaking, but eventually, if the throughput of your linux system isn’t good enough, apahce/mysql tweaking can fail. In this article, I am going to try explaining how “Nice” value of linux system can impact the performance of linux shared servers.

Lets first try to understand what “nice” value is. Following is from wikipedia:

nice is a program found on Unix and Unix-like operating systems such as Linux. nice directly maps to a kernel call of the same name. For a given process, it changes the priority in the kernel’s scheduler. A niceness of ?20 is the highest priority and 19 or 20 is the lowest priority. The default niceness for processes is inherited from its parent process, usually 0.

Linux scheduler uses a dynamic priority algorithm that a end user can not alter. But it can have an effect from the nice value. This is why nice value is sometimes called “Staic Priority”. This priority alters the dynamic priority at a static level. Let me go into analysis of how nice value can improve the overall system throughput rather than discussing the inside of nice value.

Altering nice value practically means altering the available time slice for a specific process. In a time sharing system, time slice is pretty essential. In today’s hosting world, there are lots more than one process run every second. To ensure correct cpu time for each of the process, time slice can perform a good role. For example, lets imagine, one of our cpu is capable to perform 4 processes at once. When you see a CPU load above 0, that means there are couple of processes holding to get cpu time. Now, if we expect they are all from apache (suppose), and there are 4 extra processes waiting for service, then we can improve the performance by dividing the time slice by 2 and ensuring 8 processes to run within the previous time interval. Now one more fact come in action, would that time slice be enough for my specific process? That is what you need to find out by analyzing the system overall throughput. Because if the time slice isn’t enough, this can potentially impacts the server performance.

Nice value can efficiently help you in determining the time slice for a specific group of processes (due to his habit of inheriting). For example, if you see the fork rate of your system is pretty high, you would probably want the nice value higher for the group of processes who are forking higher. For example, it could be apache, mysql, cpanel or cron. Again, if the fork rate is pretty low, then a lower nice value can improve the performance of the system. Now, setting higher or lower nice value can be tricky sometimes. For example, you have set a nice value of -19 for httpd process and a nice value of 10 for mysql process. This would potentially slow down the system performance if there are lots of database driven websites. httpd will call for mysql, but due to having less cpu time, they will respond slower than httpd and result a slow down in the system. A rule of thumb is to set similar nice value for correlated processes. When a shared server grows, fork rate grows as well. This is why higher nice values impacts tremendously a shared server.

If you are not experiencing a IO problem, then the throughput would be noticeable for your shared server with proper nice value and you would see reduces load average value due to cpu sharing his time with more processes resulting less waiting processes.

I was actually testing “CloudLinux” in a test server for last couple of days, and planning to write down some analogy on how the system is improving the performance. A basic understanding of cloudlinux is the “CPU time” and the idea cloudlinux follow is pretty similar to the Niceness. This article was the starting of the series regarding the discussion related to CloudLinux and impacts of altering scheduler CPU Time.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.