diff options
author | Georgi Kodinov <Georgi.Kodinov@Oracle.com> | 2011-11-10 15:46:51 +0200 |
---|---|---|
committer | Georgi Kodinov <Georgi.Kodinov@Oracle.com> | 2011-11-10 15:46:51 +0200 |
commit | cc76953cde41e9795b92498fe674ee7eab998b00 (patch) | |
tree | 125587e6398e781543a076fe1d1099cc1a8b0297 /scripts/mysqld_safe.sh | |
parent | 4adc0476b793bf6a46b0c065d90f93edcdfeda07 (diff) | |
download | mariadb-git-cc76953cde41e9795b92498fe674ee7eab998b00.tar.gz |
Bug #11761530: 54035: MSYQLD_SAFE BEHAVIOUR CONSUMES TOO MUCH CPU IF IT IS UNABLE TO RESTART MY
Added a trottling mechanism to mysqld_safe.
On every 5 sub-second restarts it will wait for a second before attempting again.
Note that this requires 'sleep' and 'date' command line utilities.
The code would adjust and will do nothing if any of them is not present.
Diffstat (limited to 'scripts/mysqld_safe.sh')
-rw-r--r-- | scripts/mysqld_safe.sh | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/scripts/mysqld_safe.sh b/scripts/mysqld_safe.sh index 0d2045a65a6..37e0e351ccd 100644 --- a/scripts/mysqld_safe.sh +++ b/scripts/mysqld_safe.sh @@ -740,17 +740,55 @@ cmd="$cmd $args" test -n "$NOHUP_NICENESS" && cmd="$cmd < /dev/null" log_notice "Starting $MYSQLD daemon with databases from $DATADIR" + +# variable to track the current number of "fast" (a.k.a. subsecond) restarts +fast_restart=0 +# maximum number of restarts before trottling kicks in +max_fast_restarts=5 +# flag whether a usable sleep command exists +have_sleep=1 + while true do rm -f $safe_mysql_unix_port "$pid_file" # Some extra safety + start_time=`date +%M%S` + eval_log_error "$cmd" + end_time=`date +%M%S` + if test ! -f "$pid_file" # This is removed if normal shutdown then break fi + + # sanity check if time reading is sane and there's sleep + if test $end_time -gt 0 -a $have_sleep -gt 0 + then + # throttle down the fast restarts + if test $end_time -eq $start_time + then + fast_restart=`expr $fast_restart + 1` + if test $fast_restart -ge $max_fast_restarts + then + log_notice "The server is respawning too fast. Sleeping for 1 second." + sleep 1 + sleep_state=$? + if test $sleep_state -gt 0 + then + log_notice "The server is respawning too fast and no working sleep command. Turning off trottling." + have_sleep=0 + fi + + fast_restart=0 + fi + else + fast_restart=0 + fi + fi + if @TARGET_LINUX@ && test $KILL_MYSQLD -eq 1 then # Test if one process was hanging. |