Bug #627 [patch] New mysqld_safe option "nice" for nice(1)
Submitted: 10 Jun 2003 16:42 Modified: 12 Jun 2003 6:03
Reporter: Christian Hammers (Silver Quality Contributor) (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S4 (Feature request)
Version:4.0.13 OS:All Unix / Linux
Assigned to: Lenz Grimmer
Triage: D5 (Feature request)

[10 Jun 2003 16:42] Christian Hammers
Description:
Inspirated by Debian Bug #192087 I added the option "nice" to mysqld_safe to
let the admin set the nicelevel of the database.
It was tested under Debian GNU/Linux.

How to repeat:
/etc/mysql/my.cnf:
...
[mysqld_safe]
nice            = -4                           <-----
err-log         = /var/log/mysql/mysql.err
socket          = /var/run/mysqld/mysqld.sock
...

Suggested fix:
--- /usr/bin/mysqld_safe        2003-05-21 21:25:46.000000000 +0200
+++ mysqld_safe 2003-06-11 01:32:45.000000000 +0200
@@ -70,6 +70,7 @@
          MYSQLD="mysqld"
        fi
        ;;
+      --nice=*) niceness=`echo "$arg" | sed -e "s;--nice=;;"` ;;
       *)
         if test -n "$pick_args"
         then
@@ -110,6 +111,7 @@
 MYSQL_UNIX_PORT=${MYSQL_UNIX_PORT:-/var/run/mysqld/mysqld.sock}
 MYSQL_TCP_PORT=${MYSQL_TCP_PORT:-3306}
 user=mysql
+niceness=0
 
 # Use the mysqld-max binary by default if the user doesn't specify a binary
 if test -x $ledir/mysqld-max
@@ -167,7 +169,7 @@
 export MYSQL_TCP_PORT
 
 
-NOHUP_NICENESS="nohup"
+NOHUP_NICENESS="nohup nice -$niceness"
 
 # Using nice with no args to get the niceness level is GNU-specific.
 # This check could be extended for other operating systems (e.g.,
@@ -198,8 +200,10 @@
             nice --$nice_value_diff echo testing > /dev/null 2>&1
         then
             # nohup increases the priority (bad), and we are permitted
-            # to lower the priority
-            NOHUP_NICENESS="nice --$nice_value_diff nohup"
+            # to lower the priority with respect to the value the user
+           # might has been given
+           niceness=`expr $niceness - $nice_value_diff`
+            NOHUP_NICENESS="nice -$niceness nohup"
         fi
     fi
 else
[11 Jun 2003 0:57] Lenz Grimmer
Thanks Christian - I will take a look at that.
[12 Jun 2003 6:03] Lenz Grimmer
Thanks a lot for your contribution - applied and pushed (should appear starting with MySQL 4.0.14)