Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Making mysqld be 'nice'...

Posted on 2004-11-10
4
Medium Priority
?
951 Views
Last Modified: 2012-08-14
I'm running a big computational job taking input from mysql 4.1. Unfortunately, when I run it takes up something like 95% of the CPU. Is there someway of running mysqld in some sort of relatively low priority mode such that I can actually work on the machine running mysqld while it runs,i.e., something like the 'nice' command?
0
Comment
Question by:antoniogm
  • 3
4 Comments
 
LVL 9

Expert Comment

by:e-tsik
ID: 12552183
Hi :-)

The way to go about it is to edit the init file:
/etc/init.d/mysql

Look for a line the looks something like that:
$bindir/mysqld_safe --datadir=$datadir --pid-file=$pid_file &

Put the nice command in front:
nice -n 5 $bindir/mysqld_safe --datadir=$datadir --pid-file=$pid_file &

Restart MySQL

Enjoy!
0
 

Author Comment

by:antoniogm
ID: 12554881
There is nothing quite like that in my init.d directory. My startup script is safe_myqld, and the pertinent parts are reprinted below. It's clear that some sort of niceness is invoked, or at least considered, during the definition of the nohup_niceness variable, but my ignorance of unix scripts impedes unfortunately....input welcome.



NOHUP_NICENESS="nohup"
if test -w /
then
  NOHUP_NICENESS=`nohup nice 2>&1`
  if test $? -eq 0 && test x"$NOHUP_NICENESS" != x0 && nice --1 echo foo > /dev/null 2>&1
  then
    if test $NOHUP_NICENESS -gt 0
    then
      NOHUP_NICENESS="nice --$NOHUP_NICENESS nohup"
    else
      NOHUP_NICENESS="nice -$NOHUP_NICENESS nohup"
    fi
  else
    NOHUP_NICENESS="nohup"
  fi
fi

USER_OPTION=""
if test -w /
then
  if test "$user" != "root" -o $SET_USER = 1
  then
    USER_OPTION="--user=$user"
  fi
  # If we are root, change the err log to the right user.
  touch $err_log; chown $user $err_log
  if test -n "$open_files"
  then
    ulimit -n $open_files
  fi
  if test -n "$core_file_size"
  then
    ulimit -c $core_file_size
  fi
fi

#
# If there exists an old pid file, check if the daemon is already running
# Note: The switches to 'ps' may depend on your operating system
if test -f $pid_file
then
  PID=`cat $pid_file`
  if /usr/bin/kill -0 $PID > /dev/null 2> /dev/null
  then
    if /bin/ps p $PID | grep mysqld > /dev/null
    then    # The pid contains a mysqld process
      echo "A mysqld process already exists"
      echo "A mysqld process already exists at " `date` >> $err_log
      exit 1
    fi
  fi
  rm -f $pid_file
  if test -f $pid_file
  then
    echo "Fatal error: Can't remove the pid file: $pid_file"
    echo "Fatal error: Can't remove the pid file: $pid_file at " `date` >> $err_log
    echo "Please remove it manually and start $0 again"
    echo "mysqld daemon not started"
    exit 1
  fi
fi

#
# Uncomment the following lines if you want all tables to be automaticly
# checked and repaired at start
#
# echo "Checking tables in $DATADIR"
# $MY_BASEDIR_VERSION/bin/myisamchk --silent --force --fast --medium-check -O key_buffer=64M -O sort_buffer=64M $DATADIR/*/*.MYI
# $MY_BASEDIR_VERSION/bin/isamchk --silent --force -O sort_buffer=64M $DATADIR/*/*.ISM

echo "Starting $MYSQLD daemon with databases from $DATADIR"

# Does this work on all systems?
#if type ulimit | grep "shell builtin" > /dev/null
#then
#  ulimit -n 256 > /dev/null 2>&1            # Fix for BSD and FreeBSD systems
#fi

echo "`date +'%y%m%d %H:%M:%S  mysqld started'`" >> $err_log
while true
do
  rm -f $MYSQL_UNIX_PORT $pid_file      # Some extra safety
  if test -z "$args"
  then
    $NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file --skip-locking >> $err_log 2>&1
  else
    eval "$NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file --skip-locking $args >> $err_log 2>&1"
  fi
0
 
LVL 9

Accepted Solution

by:
e-tsik earned 2000 total points
ID: 12562754
I would put after this block:
NOHUP_NICENESS="nohup"
if test -w /
then
  NOHUP_NICENESS=`nohup nice 2>&1`
  if test $? -eq 0 && test x"$NOHUP_NICENESS" != x0 && nice --1 echo foo > /dev/null 2>&1
  then
    if test $NOHUP_NICENESS -gt 0
    then
      NOHUP_NICENESS="nice --$NOHUP_NICENESS nohup"
    else
      NOHUP_NICENESS="nice -$NOHUP_NICENESS nohup"
    fi
  else
    NOHUP_NICENESS="nohup"
  fi
fi

The following:
NOHUP_NICENESS="nice -n 5 nohup"
0
 
LVL 9

Expert Comment

by:e-tsik
ID: 12565693
Thanks!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month21 days, 7 hours left to enroll

804 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question