Slashdot Mirror


Nice Performance Tuning For UNIX

Professor writes "Be 'nice' to your computers and examine some general guidelines for tuning server performance. A computer is like an employee who does tasks for you -- it's a good idea to keep from overburdening them. Keep this from happening by using the UNIX 'nice' command."

44 of 206 comments (clear)

  1. Scheduling Priority is for sissys by SatanicPuppy · · Score: 5, Funny

    Set 'em all to -19, and let the best program win! If they don't have to fight each other for CPU cycles they will grow up weak and feeble.

    --
    ad logicam Claiming a proposition is false because it was presented as the conclusion of a fallacious argument.
    1. Re:Scheduling Priority is for sissys by Gothmolly · · Score: 2, Interesting

      If they're lucky, they'll get placed on the game grid, where they'll use futuristic "light cycles" and weird jai-lai pelotas to battle for supremacy.

      --
      I want to delete my account but Slashdot doesn't allow it.
    2. Re:Scheduling Priority is for sissys by hackstraw · · Score: 2, Insightful

      Set 'em all to -19, and let the best program win! If they don't have to fight each other for CPU cycles they will grow up weak and feeble.

      Very funny. Its like when I'm talking to people that believe in heaven and hell, I just say "Kill 'em all and let God sort them out!"

      But back on the topic. Err, I'm new to UNIX/Linux, I've only been using it since 1993, but nice and getpriority() setpriority() and scheduling have been around for a _long_ time.

      Debian launches services via the start-stop-daemon program that has the -N|--nicelevel option. RedHat has a function called daemon() in /etc/init.d/functions that takes a nice argument.

      In other words, I'm not impressed with the IBM article or with slashdot for printing this. Oh, and the slocate cron job in most Linux distros has been niced to -19 for years. I guess copying and pasting the contents of the cron script is helpful for people that don't have access to a Linux box. Next week, they are going to HTMLize the kernel source for those that can't download that either.

      I hate being negative here, but what is the target audience for the IBM article and this slashdot reprinting of it?

    3. Re:Scheduling Priority is for sissys by hackstraw · · Score: 2, Insightful

      I consider myself pretty "new" to the UNIX/Linux world, too, and I've been using some variation since 1993. I'll stop considering myself new when I can remember every command ;)

      While we are on the topic, is there a market for a slashdot style site that is more geared for computer professionals?

      Slashdot has a very smart userbase, and I would not abandon slashdot, but I would like to get away from the highschool and undergrad "know it all" people. Articles like this one are way below anyone who does Linux or UNIX professionally, and when I mention things like this the /. moderators slap me with an overrated moderation.

      I'm serious, would there be a target audience of professionals that would like a website geared for them? Does one already exist that I don't know about that has active readers and interactive discussions?

    4. Re:Scheduling Priority is for sissys by cortana · · Score: 2, Informative

      For Linux news, LWN; for general tech/sci news, Technocrat.

      Slashdot has a *lot* more users than either though. Although some times it can seem otherwise, the good comments can show though... you just need to browse at +4 and ignore anything posted = 25 minutes after a story is posted. :)

    5. Re:Scheduling Priority is for sissys by hackstraw · · Score: 2

      Slashdot has a *lot* more users than either though. Although some times it can seem otherwise, the good comments can show though... you just need to browse at +4 and ignore anything posted = 25 minutes after a story is posted. :)

      Hey, I browse at +4 already. 90% of my foes are those MMLM people with "free" iPods in their sigs. That has gotten rid of most of the college kids. I'm a subscriber and give bonus points to friends, friend of friends, interesting, informative, yada yada. I've been reading slashdot before it was slashdot, AKA chips and dips. I really like slashdot for the discussions. I wish that there was a more professional side to it. Personally, this topic about nice is way too low for me. I would love to see discussions about software trends, especially things like learning software, cool new APIs or libraries or things like memcached which drives slashdot and other high volume DB based sites. I've used memcached successfully and really like it. I would like to see Linux topics like about the preemptive kernel patches. I like the MySQL/PostgreSQL/Oracle debates, but even those are not lead by very informed people. Basically, I would like a more experienced, professional twist to the discussions. I guess the saying that "Knowledge shared is power lost" is true. The people that know keep it to themselves, while the people that know next to nothing will tell you all about it, with confidence and conviction, yet no working experience is behind the wisdom.

  2. First Post? by bje2 · · Score: 5, Funny

    nice -19 -n doFirstPost

    i'll surely get first post this way!!!

    --

    "Facts are meaningless. You could use facts to prove anything that's even remotely true." - Homer Simpson
  3. Next up: "man nice" "man man" "man mount" ? by Gothmolly · · Score: 4, Insightful

    Performance tuning means that IO and other resources are sufficient to run tasks. The 'nice' command isn't that. 'nice' lets you run jobs whose complete time can vary, since you can put them on the bottom of the list.

    Performance tuning is fiddling with /proc, and matching file and FS parameters with your page size.

    This is a non-article.

    --
    I want to delete my account but Slashdot doesn't allow it.
    1. Re:Next up: "man nice" "man man" "man mount" ? by eln · · Score: 4, Funny

      Whoa whoa whoa, slow down. First I learn there's a "nice" command, and now you're telling me there's a "man" command too? This is way too much information for one day.

    2. Re:Next up: "man nice" "man man" "man mount" ? by SatanicPuppy · · Score: 4, Insightful

      One of the things I don't like about nice is that people often use it to baby weak code. Some joker writes the world most inefficient Perl script, and then, because it takes forever to run, uses nice to give it a higher priority than it deserves, thus cutting it's runtime down to an acceptable time, rather than just fixing the damn code. I hardly ever see anyone use it nicely (har har), setting a non-critical job to run at a lower priority.

      So I'm always suspicious when I see nice used. I really prefer to just schedule more intelligently, so things don't overlap as much, and running daemons that hog cycles 24/7 on their own hardware.

      --
      ad logicam Claiming a proposition is false because it was presented as the conclusion of a fallacious argument.
    3. Re:Next up: "man nice" "man man" "man mount" ? by hackstraw · · Score: 2, Insightful

      Some joker writes the world most inefficient Perl script, and then, because it takes forever to run, uses nice to give it a higher priority than it deserves, thus cutting it's runtime down to an acceptable time, rather than just fixing the damn code.

      Well, this joker has root access, because only root can increase a priority of a process.

      No system I run with multiple users would have such an incompetent person that is allowed to have root access. In fact, when a user writes some broken perl script that burns a processor for days, I do a trace on the procesws to see what it is doing, kill the process and email the user to fix the code.

      Yes, I'm a BOFH, and proud of it!

    4. Re:Next up: "man nice" "man man" "man mount" ? by wild_berry · · Score: 5, Funny

      "mount nice man" doesn't sound like my cup of tea.

    5. Re:Next up: "man nice" "man man" "man mount" ? by smoker2 · · Score: 2, Informative

      I renice 10 Folding@home so that the computer is actually useable when I need it. When I'm out, it can do what it wants !

    6. Re:Next up: "man nice" "man man" "man mount" ? by Anonymous Coward · · Score: 2, Funny

      I like the *nix guru's view of sex better:

      gawk; talk; nice; date; wine; grep; touch; unzip; strip; touch; gasp; finger; gasp; mount; fsck; more; yes; gasp; umount; make clean; make mrproper; sleep

  4. Here's a tip. by Anonymous Coward · · Score: 5, Funny

    When using 'nice' try the -666 option to enable the evil bit. Hilarity will ensue.

    1. Re:Here's a tip. by rcamans · · Score: 2, Funny

      When I saw 666, the evil bit and Hilarity, I immediately thought Hillary (Clinton)???

      --
      wake up and hold your nose
  5. Have a DVD-ripping death match! by MoxFulder · · Score: 4, Funny

    Now here's a fun thing to do: rip a DVD with several programs at once, all at nice -19 at you suggest, and encode it to XVid and DivX and Theora all at once for good measure.

    Watch the DVD drive churn and seek and gasp!
    Watch the encoders fight for CPU time with top open in a terminal window!
    Run some unnecessary I/O-bound process like updatedb in the background so that the hard drive can get in on the thrashing!

    Wheeee! What fun...

    1. Re:Have a DVD-ripping death match! by dpilot · · Score: 2, Funny

      Do you complain about the lousy framerate you get playing your FPS while the rest of this is happening?

      --
      The living have better things to do than to continue hating the dead.
    2. Re:Have a DVD-ripping death match! by eyeball · · Score: 2, Interesting

      This brings up a good point. CPU isn't the only limited resource. I've often ran applications that saturate IO busses or network interfaces, or eat up a ton of memory, but only used a fraction of CPU time.

      In the first case, a large simple parsing app or file compression/decompression can saturate an IO bus. While performing such operations, other user-sensitive tasks like opening an application or checking mail. Granted most users don't do a lot of IO-flooding apps, but what's more prevalent are network-flooding operations. Just recently, while I was downloading some linux ISOs via HTTP, my web browsing was slow the whole time. Sure QoS can help some of these issues, like putting a higher priority on Game network traffic, but probably wouldn't help web browsing while downloading large files.

      It would be nice (no pun intended) to be able to restrict or throttle other resources besides CPU. i.e.:

      nice -n-19 wget http://example.com/linux.iso
      nice -i-19 gzip bighugefile.csv

      This probably exists in Linux already.

      --

      _______
      2B1ASK1
    3. Re:Have a DVD-ripping death match! by MoxFulder · · Score: 2, Informative

      Yes, that's a very good point. It would be nice if it was possible to throttle other resources in a uniform fashion.

      With network bandwidth it's quite application-specific. For example I can tell Azureus (uber-featureful bittorrent client) to only use a certain amount of upload bandwidth. But I can't do this with Gaim, and when I'm sending someone a big file too fast, my web browsing grinds to a halt. It'd be handy to have a uniform way to restrict the bandwidth of apps.

      Storage device accesses would be a LOT trickier IMHO. Without knowing the specifics of the device geometry and seek times etc., it's very hard to know how much of a drive's capacity is being used. As I suggested above, it's efficient to have one program read a DVD start-to-finish as fast as it can. It's *HORRIBLY* *AWFULLY* inneficient for TWO programs to do so at once (and from the sound of it, I worry that it will literally break my DVD drive :-)

  6. I got my server tuned by Anonymous Coward · · Score: 2, Funny

    You don't need the nice utility.

    Some "R" stickers along the side, a huge wing on top of the box, and replacing the sound card with a fart can is all you need to tune your server.

  7. Bad teacher, no cookie! by Fubar420 · · Score: 5, Insightful

    FTFA: "In fact, only the ps command was running when I generated this list. Most tasks are designed to do what they need to do quickly and then exit or sleep."

    Of course, because all other processes, at the instant PS was running, were blocking on the CPU. In other words, on a uniprocessor system, you can only have one process running at a time, and in the case of a process that reports the state of other processes, its only THAT PROCESS THAT WILL APPEAR RUNNING...

    Go play in /proc/self for a while.

    --
    -- (appended to the end of comments you post, 120 chars)
    1. Re:Bad teacher, no cookie! by alexhs · · Score: 4, Insightful

      Of course, on a uniprocessor system only one task can run at a time. However, (GNU) ps and (GNU) top report R as Running or Ready to Run, so there may be more than one at any time. Average of runnable tasks count get you the load.

      Nota : I put the GNU because BSD equivalent behaves differently, I just checked and I get details like "select" where I guess I would only get "Sleep" on GNU/Linux.

      --
      I have discovered a truly marvelous proof of killer sig, which this margin is too narrow to contain.
    2. Re:Bad teacher, no cookie! by ultranova · · Score: 3, Insightful

      Of course, because all other processes, at the instant PS was running, were blocking on the CPU. In other words, on a uniprocessor system, you can only have one process running at a time, and in the case of a process that reports the state of other processes, its only THAT PROCESS THAT WILL APPEAR RUNNING...

      Not true. "Running" as a process status doesn't mean that the process is burning CPU time right now, it means that it is in the runqueue and will round-robin with all the other running processes for the CPU time.

      The opposite state, sleeping, means that the process is not currently in the runqueue because it is waiting for something - for a disk read to conclude, for some data from the network, for your keypress, or simply that some time has elapsed.

      I repeat: a "running" process is one that is in the runqueue, not neccessarily being run by the CPU at this particular microsecond.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

  8. Re:what about killall by LLuthor · · Score: 4, Informative
    Umm. You can't sigkill init on Linux (at least on moderately recent kernels). I am pretty sure that is also the case on BSD systems.

    Yep ...
    In arch/i386/kernel/signal.c [2.6.17-rc1-mm2]
    563 /*
    564 * Note that 'init' is a special process: it doesn't get signals it doesn't
    565 * want to handle. Thus you cannot kill init even with a SIGKILL even by
    566 * mistake.
    567 */
    568 static void fastcall do_signal(struct pt_regs *regs)
    --
    LL
  9. Worst. Advice. Ever. by V.+Mole · · Score: 3, Informative

    Ah, yes, the extremely bad idea of running updatedb at low priority surfaces again. Then, instead of finishing during the early morning hours, it lasts all day, interferring with real work. Yes, this is what really happens: we tried this quite a while ago in Debian, and it's a Bad Idea(tm). What happens, IIRC, is that updatedb gets CPU so rarely that other tasks end up flushing the file buffers, and updatedb has to re-read the disk, over and over.

    If the problem is that your system isn't on all the time, and anacron is running updatedb when you log in, then just disable updatedb. You probably never use 'locate' anyway.

    1. Re:Worst. Advice. Ever. by gowen · · Score: 4, Informative
      Then, instead of finishing during the early morning hours, it lasts all day, interferring with real work.
      If there are no other processes competing for resources, niced and non-niced processes will complete in approximately the same time. If your niced late-night updatedb is taking forever, its because you've chosen to run other processes overnight as well. And if your updatedb runs quickly, then the other processes will "interfere with real work".

      In short : nice doesn't change the total amount of time your processes take (or, at least, not by very much), it just changes which one finishes first.
      --
      Athletic Scholarships to universities make as much sense as academic scholarships to sports teams.
    2. Re:Worst. Advice. Ever. by Black+Copter+Control · · Score: 2, Informative
      In short : nice doesn't change the total amount of time your processes take

      No. In the instant case, the problem was that the system was 'thrashing'. Useful data was being flushed, and it had to be reloaded from disk again and again. That causes the system to chew up extra resources and slows things down. In a case like that, increasing the priority of updatedb would have it get it's work done quickly during low priority times and then get out of the way. (of course, if you're on a server, you probably need to run updatedb weekly if at all.).

      The real answer to his problem is to add more memory. I can't believe the number of people who will get a hot CPU and not enough memory, then find out that they're bogged down because of paging. Disk I/O is orders of magnitude slower than memory. The only things you should be paging out is (almost) completely inactive tasks, or the inactive parts of running tasks. If working tasks regularly get paged out, it was time to add RAM a while ago.

      I'll almost always suggest to people to add memory before you jack up the CPU. It's usually way more efficient in terms of speeding the system up. 1Gz machine with 1GB of ram is often going to be way more usable than a 2Gz machine with 256MB, but the cost of upgrading your ram is way less than replacing the CPU (and probably the motherboard to boot). (YMMV).

      --
      OS Software is like love: The best way to make it grow is to give it away.
    3. Re:Worst. Advice. Ever. by asuffield · · Score: 2, Insightful

      In short : nice doesn't change the total amount of time your processes take (or, at least, not by very much), it just changes which one finishes first.

      Actually it does change the total amount of time. The issue in question here is about disk caching. The problem was that, if you run updatedb niced, then it doesn't get to run as often. In fact, it can run so infrequently that between one timeslice and the next, the disk cache has been replaced by other stuff, because of all the processes that ran in between the two.

      The result is that updatedb runs with permanently cold cache. That makes it take hours instead of minutes. Hence the problem. It's not immediately obvious because it only happens when there is a moderate amount of background usage of disk resources - like an active mail server, or a backup job.

      Nice isn't very nice to disk-intensive processes. This feature of unix was designed for cpu-intensive processes. It doesn't work very well on things like updatedb - you tend to get bad interactions like this one. If the system is truly idle then you're safe, but if it isn't then you're screwed.

  10. nice good, kill better by DesertWolf0132 · · Score: 2

    There are two keys to efficient server tuning. One, build the server with the capability to run at least 3 times as much as you need right now. Then kill -9 any process that slows your watching the p0rn filter go nuts during lunch and breaks. Who really needs a freaking relational database engine anyway? The accounting department can kiss off, you have blackmail to collect.

    --
    No animals were harmed in the making of this sig.
    Well, there was that one puppy, but he is all better now.
  11. Re:"nice" as a performance tool? by robipilot · · Score: 2

    I just don't get the whole submission thing here sometimes. My submission on the value of tr got rejected!

  12. Re:what about killall by Stradenko · · Score: 4, Informative

    The above post refers to the killall from the psmisc package.

    The Sun Solaris "killall" command kills *all* processes.

    AIX "killall" kills all processes (except those in its family tree) owned by the calling user (maybe owned by the calling user *and* attached to the current terminal...).

  13. Repetitive tasks and tuning... by Dr.+Zowie · · Score: 5, Interesting

    I used to work at NASA/GSFC, and one of the workstations there sat all day running periodic housekeeping tasks from cron -- parsing telemetry, handling command load updates, etc. The problem was that every once in a while something would stall and the next batch of cron jobs would launch before the first ones completed. Instant snowballing death would ensue as nothing completed and the load average would soar into the hundreds as cron maniacally, stupidly spawned more and more processes into the poor overloaded workstation.

    There are several relevant tools available now but then I wrote my own - a perl script called "qproc" that would queue up jobs for execution, kill them if they hung too long, and refrain from launching multiple copies of the same job at the same time.

    Until I got hit by that, I never thought about the fact that cron is very dangerous to use on a production server. But it is -- if cron tasks use a non-infinitesimal part of the computer, you have to take steps to prevent the same marching-broomsticks failure mode.

  14. Off topic: Zombies by smcdow · · Score: 3, Interesting
    As someone who just had to deal with a machine becoming inoperable because the process table filled up with thousands of zombies because 3rd party software wasn't reaping its children.....

    Please, for the love of all that's holy and Unixy, teach yourselves what a SIGCHLD is and how to use wait(2).

    --
    In the course of every project, it will become necessary to shoot the scientists and begin production.
  15. nice is great for running long jobs in background by Quevar · · Score: 2, Insightful

    I use it on my own system all the time. I've got a dual processor Mac, but once in a while I have too many things running in the background (encoding a movie, analyzing my data in Matlab, etc) and want to keep manipulating some images in the foreground, so I set Quicktime and Matlab and whatever else to -19 priority. They still finish, but when I need the processor to open/close/resize/apply a filter to my image, it takes it and then lets the rest work on the past stuff. I find that it can greatly increase the amount I get done in a day and makes my Mac feel as fast as it is when I'm not doing anything else.

    I also tend to increase the priority on httpd processes on the same Mac since I host my website from it. It doesn't take much CPU time, but when a request comes in, I want it to respond as quickly as possible, so if I'm doing a lot, it will give priority to it.

    Also, Boinc (the grid client for distributed computing) always sets all the jobs to -19 when they are run. I barely even notice if they are running in the background.

  16. Low numbers == High priority??? by AmbushBug · · Score: 2, Interesting

    Does anyone know why lower numbers give higher priority? Isn't it more intuitive to use higher numbers for higher priority? I'm curious as to why it was done this way...

    1. Re:Low numbers == High priority??? by NereusRen · · Score: 2, Informative

      It's because they changed the metaphor from "having priority" to "being nice." If a process is more nice, it lets other processes use CPU time first. If it is less nice, it hogs it all for itself.

      It's confusing if you are used to thinking in terms of priority, but it makes sense after the first few times you see it.

  17. Ric Romero? by cashman73 · · Score: 2, Funny

    Is Ric Romero taking notes on this article?

  18. Re:Negative numbers for higher priority? by Adam+Heath · · Score: 2, Interesting

    This is really rather simple. Let's say you have a number, X. What comes before X? X-1. And what comes before that? X-2.

    So, now with that out of the way, let's say you want to iterate all numbers. Most sane people would start at either the beginning(low value) or the end(high value). And probably most would start at the beginning.

    When walking the list of things to run, a simple scheduler would act on the first thing it finds. This means that something that existed lower in this list would be run more often than something that existed later. So, that means that lower priority number actually means run more often.

  19. Re:Negative numbers for higher priority? by Hatta · · Score: 2, Informative

    Anyone know the historic reason why negative numbers are used for processes with HIGHER priority? It's counterintuitive and everything that's not *nix-like does it differently.

    Nice values measure how nice your programs are. Being nice means it gets out of the way for other programs. So a program with a nice value of 10 is nicer than that with a nice value of 0 and will get out of the way.

    We could do it the other way around and have a 'mean' program that assigns 'mean' values to programs which then hog the CPU. But only the super user would be able to assign positive values.

    --
    Give me Classic Slashdot or give me death!
  20. Jesus, what kind of a commie pinko are you? by RomulusNR · · Score: 2, Funny

    A computer is like an employee who does tasks for you -- it's a good idea to keep from overburdening them.

    Don't I already pay this hunk of junk enough in electricity and bandwidth to keep it from slacking off? If it isn't willing to constantly pull more weight, for the greater success, what am I keeping it on for?

    --
    Terrorists can attack freedom, but only Congress can destroy it.
  21. Nice is Nasty by redelm · · Score: 3, Interesting
    Seriously, nice is not a good performance tuning tool in most cases. All it does is shorten the timeslice, inducing more cache misses. The work remains the same or goes up due to cache reloads.

    A good [Linux] scheduler already does process restart immediately upon unblocking to reduce latency.

    But an overloaded box is still overloaded. The question is how you want it to fail. In what direction? A little cron job watching load with a shedding/restart list probably does better.

  22. nice for the Mac geeks by Been+on+TV · · Score: 3, Informative

    For Mac OS X users trying out the commands in the article, you need to type the following to get the list of processes as shown in the article:

    ps -ax -o pid,state,nice,command | less -5

    Also, on a standard Mac OS X system, the updatedb command to update the locate database is run by cron from the 500.weekly script located in /etc/periodic/weekly/.

    --
    The future is in beta
  23. nice -5 apachectl start by Spazmania · · Score: 2, Interesting

    Its also very helpful to run Apache at nice level 5. That way when the CGI programs go nuts and the load shoots up to 200 the sshd process won't get starved for CPU time and you can still log in to fix the server.

    --
    Moderating "-1, Disagree" is simple censorship. Have the guts to post your opinion.