Setting nice levels on users.

Setting nice levels on users.

Post by gregg han » Tue, 01 Oct 1991 13:02:35



--

Is there a way for the sysadmin to set an account to change
that user's nice default from zero to some other number?

My problem is that certain users run CPU intensive background
jobs and forget to nice them so they don't interfere with
interactive processes.  Every time I come in I find myself
doing a ps -glxa and then renicing their processes for them.
I'm tired of doing it and would like to just renice their
accounts once and for all.

                                         gregg hanna

 
 
 

Setting nice levels on users.

Post by Neil Ricke » Tue, 01 Oct 1991 13:50:07



>My problem is that certain users run CPU intensive background
>jobs and forget to nice them so they don't interfere with
>interactive processes.  Every time I come in I find myself
>doing a ps -glxa and then renicing their processes for them.

  If you get into the habit of renicing them with "kill -9", I bet
your user will soon get into the habit of renicing himself.

--
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

  Northern Illinois Univ.
  DeKalb, IL 60115                                   +1-815-753-6940

 
 
 

Setting nice levels on users.

Post by Michael Rego » Wed, 02 Oct 1991 00:03:56




>>My problem is that certain users run CPU intensive background
>>jobs and forget to nice them so they don't interfere with
>>interactive processes.  Every time I come in I find myself
>>doing a ps -glxa and then renicing their processes for them.
>  If you get into the habit of renicing them with "kill -9", I bet
>your user will soon get into the habit of renicing himself.

Oh, how nice.  The Kamikazee school of Blow Torch System
Administration.  I love it.

--

michael regoli


..{ames, rutgers}!iuvax!cica!mr

 
 
 

Setting nice levels on users.

Post by Chuck Kari » Tue, 01 Oct 1991 21:33:35



(Neil Rickert) writes:

>>My problem is that certain users run CPU intensive background
>>jobs and forget to nice them so they don't interfere with
>>interactive processes.  Every time I come in I find myself
>>doing a ps -glxa and then renicing their processes for them.

>  If you get into the habit of renicing them with "kill -9", I bet
>your user will soon get into the habit of renicing himself.

This penalizes interactive users as well, when long-running
jobs have to be re-run.

I once installed an 'autonice' program that a friend had
written.  It did a 'ps' every few minutes to look for
jobs with more than 10 minutes of CPU usage at low 'nice'
levels.  Such programs were reniced to 10 and a message
written to a log file that this had been done.

Two problems:

    - Since the idea is to balance priorities between interactive
      users and batch users, wall clock time would have been a
      better metric than CPU time.  Multiple background jobs
      could bog down a machine for a long time before hitting
      the 10 minute threshold.

    - The program didn't have an adequate means to detect
      interactive programs, and would occasionally renice an
      editor session.

      ps sometimes assigned the run times of all active
      background processes to the foreground process with the
      same controlling terminal.  It's easy enough to recognize
      interactive shells and avoid renicing them.

It ran without provoking serious complaints for years.


        Mindcraft, Inc.         (415) 323-9000

 
 
 

Setting nice levels on users.

Post by Rudolf Bauma » Wed, 02 Oct 1991 19:56:11



>--
>Is there a way for the sysadmin to set an account to change
>that user's nice default from zero to some other number?
>My problem is that certain users run CPU intensive background
>jobs and forget to nice them so they don't interfere with
>interactive processes.  Every time I come in I find myself
>doing a ps -glxa and then renicing their processes for them.
>I'm tired of doing it and would like to just renice their
>accounts once and for all.
>                                         gregg hanna


I had the same problem here until I stumpled over the following program,
which is now running on all servers and works great. It allows users to
run shorttime jobs at normal nice value but longtime jobs are gradually
reniced up to nice level 19. I did not write the program, I am hoping
that you also can use it
        Ruedi

/*
** Nice CPU 'hogs'.
** Runs under SunOS 4.0 (ie. requires kvm routines).
**

*/

#include <stdio.h>
#include <kvm.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/user.h>
#include <sys/proc.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/timeb.h>

/* Some defines for debuging
#define DEBUG           1
#define DONT_DO_IT      1
*/

#define SLEEPTIME       120       /* in seconds */
#define WHEREIS_RENICE  "/usr/etc/renice"

/* When process cpu usage exceeds limit (indexed by priority) then
   we increment priority by one */

int limit[19] = {       /* Note that all times are in seconds */
       3 * 60,      5 * 60,      7 * 60,     12 * 60,     16 * 60,
      32 * 60,     64 * 60,    128 * 60,    256 * 60,    512 * 60,
    1024 * 60,   2048 * 60,   4096 * 60,   8192 * 60,  16384 * 60,
   32768 * 60,  65536 * 60, 131072 * 60, 262144 * 60};

char *pn = "reallynice";

void burychild();       /* This is for burying dead childs */

main()
{
  char nice_str[4], pid_str[6];
  int cpu_usage, tt;
  kvm_t *kd;
  struct proc *proc;
  struct user *u;
  time_t tloc;

/* Make this program daemon */

  if(fork())
    exit();                             /* Make an own process */
  if((tt = open("/dev/tty", O_RDWR)) != -1) {
    ioctl(tt, TIOCNOTTY, 0);            /* Disconnect from tty */
    close(tt);
  }

/* Set signal SIGCHLD to routine which takes care of zobies by
   calling wait */

  signal(SIGCHLD, burychild);

/* Open descriptor for Kernel VM routines (begining with kvm_) */

  if(!(kd = kvm_open(NULL, NULL, NULL, O_RDONLY, pn)))
    exit(1);

  while(1) {

/* Rewind the process list, so we could go all process through again */

    if(kvm_setproc(kd) == -1) {
      kvm_close(kd);
      exit(1);
    }

/* Get process one by one */

    while(proc = kvm_nextproc(kd)) {

/* We aren't inrested system processes (uid under 10),
   processes with negative priority or already with the lowest priority */

      if(proc->p_uid < 10 || proc->p_nice < 20 || proc->p_nice == 20 + 19)
        continue;

/* Get u-area for cpu usage calculations */

      if(!(u = kvm_getu(kd, proc)))
        continue;       /* Read failed for some reason */

/* Calculate cpu usage by adding user time usage to system time usage */

      cpu_usage = u->u_ru.ru_utime.tv_sec + u->u_ru.ru_stime.tv_sec;

#ifdef DEBUG
      printf("pid %d uid %d nice %d cpu usage %d\n",
             proc->p_pid, proc->p_uid, proc->p_nice - 20, cpu_usage);
#endif

/* Check if should lower this processes priority by one */

      if(cpu_usage < limit[proc->p_nice - 20])
        continue;       /* Not yet */

/* We caught something, hopefully big fish. Now we renice this process.
   Let's put first time and little other information to stderr
   then we have more informative output */

      time(&tloc);
      fprintf(stderr, "%.24s uid %d pid %d cpu usage %d\n",
              ctime(&tloc), proc->p_uid, proc->p_pid, cpu_usage);
      fflush(stderr);

      sprintf(nice_str, "+%d", proc->p_nice - 20 + 1);
      sprintf(pid_str, "%d", proc->p_pid);

#if (DEBUG || DONT_DO_IT)
      fprintf(stderr, "renice %s %s\n", nice_str, pid_str);
#else
      if(!fork())
        execl(WHEREIS_RENICE, "renice", nice_str, pid_str, 0);
#endif
    }
    sleep(SLEEPTIME);
  }

/* We shouldn't reach here in any case so this is commented out,
   otherwise compiler gives a warning

  kvm_close(kd); */

Quote:}

/* This is called whenever child is killed. By calling this we
   could prevent leaving any zombies wondering around. */

void burychild()
{
  while(wait(0) != -1);

Quote:}

--


ETH Hoenggerberg (HPM G6)                            Tel. ++41 1 377 33 97
CH-8093 Zuerich/Switzerland                          Fax  ++41 1 371 48 73
 
 
 

Setting nice levels on users.

Post by Pierre Assel » Wed, 02 Oct 1991 12:21:57




: >>doing a ps -glxa and then renicing their processes for them.
:
: >  If you get into the habit of renicing them with "kill -9", I bet
: >your user will soon get into the habit of renicing himself.
:
: Oh, how nice.  The Kamikazee school of Blow Torch System
: Administration.  I love it.

Michael's right.  Renice them to 19 instead.  Hold kill -9 in reserve
for when paging space gets low.

CPU hogs do cause damage.  The interactive response goes south for
everyone, and good guys who did renice their jobs get no cycles at all.
Renicing the entire account isn't a solution, because that would affect
interactive programs.

Back in school, the BSD kernel would renice anything to 4 that had
accumulated 5 minutes of cpu time or so.  That was just fine, except
that -8 or -10 would have been more appropriate.  I asked the admins if
they could change it;  "Not without a lot of work", was the answer.  Too
bad.  It should be possible to write a daemon to do that.  Make sure the
daemon leaves X servers alone.
--

--Pierre Asselin, Santa Barbara, California

 
 
 

Setting nice levels on users.

Post by Brett McC » Thu, 03 Oct 1991 03:48:09



> I once installed an 'autonice' program that a friend had
> written.  It did a 'ps' every few minutes to look for
> jobs with more than 10 minutes of CPU usage at low 'nice'
> levels.  Such programs were reniced to 10 and a message
> written to a log file that this had been done.
> Two problems:
>     - Since the idea is to balance priorities between interactive
>       users and batch users, wall clock time would have been a
>       better metric than CPU time.  Multiple background jobs
>       could bog down a machine for a long time before hitting
>       the 10 minute threshold.
>     - The program didn't have an adequate means to detect
>       interactive programs, and would occasionally renice an
>       editor session.
>       ps sometimes assigned the run times of all active
>       background processes to the foreground process with the
>       same controlling terminal.  It's easy enough to recognize
>       interactive shells and avoid renicing them.

I've written a program that watches for processes which are
hogging the CPU and nices them.  To determine if a process is
a CPU hog it compares the percentage CPU usage of the process
against a number scaled by the load average of the machine.
If the % is greater than the threshold then it gets niced
by 2, if it less than another threshold then it gets unniced
by 2 down to a minimum of the original starting point.  This
process is done every 30 seconds so a CPU bound job gets niced
to 19 after about 8 minutes.

The result of all this is that it isn't dependent on how much
time a program has accumulated but on how busy it is right now.
A process that has been running for weeks, but only using 1 or
2 percent of the CPU doesn't get niced.  Same goes for editors
and interactive shells.

It was sort of amazing how many people complained how we were
such facists by auto nicing people's programs, yet after a
couple months anytime the renicing daemon would fail or
crash everyone would complain how large jobs weren't getting
niced.  No one is ever satisfied it seems.

--
Brett McCoy                     Computing and Network Services

"The use of COBOL cripples the mind; its teaching should, therefore, be
regarded as a criminal offence." E.W.Dijkstra, 18th June 1975.

 
 
 

Setting nice levels on users.

Post by Charles H. Buchhol » Thu, 03 Oct 1991 21:47:31



>I once installed an 'autonice' program that a friend had
>written.  It did a 'ps' every few minutes to look for
>jobs with more than 10 minutes of CPU usage at low 'nice'
>levels.  Such programs were reniced to 10 and a message
>written to a log file that this had been done.

>Two problems:

[Problems deleted]

I started running a similar but more sophisticated program about two
years ago, and was very happy with the results.  There were a few
situations where it didn't "do the right thing", however.

This summer I redesigned it based upon my experience with the
prototype, and we rewrote it from scratch.  It's been in Alpha test on
three of our systems for about three weeks, and everyone is very happy
with it.  I'm going to spend a week or two cleaning it up and
packaging it, and then make it available for Beta test.  Eventually I
will make it available via anonymous FTP.

For more information, or to request a Beta copy, please send mail.


Systems Programmer                             (215) 898-2491
School of Engineering and Applied Science      200 S. 33rd St, rm 154
University of Pennsylvania                     Philadelphia, PA 19104

 
 
 

Setting nice levels on users.

Post by Shawn Koppenhoef » Fri, 04 Oct 1991 18:22:22


Rudolf> I had the same problem here until I stumpled over the following progr
Rudolf> which is now running on all servers and works great. It allows users to
Rudolf> run shorttime jobs at normal nice value but longtime jobs are gradually
Rudolf> reniced up to nice level 19. I did not write the program, I am hoping
Rudolf> that you also can use it

program> /*
program> ** Nice CPU 'hogs'.
program> ** Runs under SunOS 4.0 (ie. requires kvm routines).
                .
                .
                . [ great program here ]
                .
program>   kvm_close(kd); */
program> }

I've got this program too. It works great!
I've added the following little bit after the time(&tloc)
line. It prints the renice info to syslog along with the user name.

program>       time(&tloc);
program>       fprintf(stderr, "%.24s uid %d pid %d cpu usage %d\n",
program>           ctime(&tloc), proc->p_uid, proc->p_pid, cpu_usage);
program>       fflush(stderr);
program>       sprintf(nice_str, "+%d", proc->p_nice - 20 + 1);
program>       sprintf(pid_str, "%d", proc->p_pid);

here is the code i have added just after that time(&tloc) there.

{ /*-------------------------------------------*/
   char tempstring[100];
   int  result;

   Password_info = getpwuid( proc->p_uid );
   sprintf( tempstring, "NICED: %.24s uid %d (%s) pid %d () cpu usage %d\n",
        ctime(&tloc), proc->p_uid, Password_info->pw_name, proc->p_pid,
                   cpu_usage);
   syslog(LOG_INFO, tempstring );
   } /*-------------------------------------------*/

you also need the line:   #include <syslog.h>
at the top of the program.

QUESTION: does anyone know how to use the command:

        int kvm_getcmd(kd, proc, u, arg, env)

I want to use this to get the string to tell me WHAT command was
reniced. In the same way that I found out WHO the user was that
was reniced.