Homebrew, open source, repurposed, hacked, software defined, open hardware

Saturday, 2 August 2014

Ubuntu apt xapian index update manager very slow on older machines and how to fix it

I found this fix in the ubuntu bug reporting forum.

The symptoms are older machines with slower processors or limited RAM will grind to a halt when the package updater launches in the background. The machine becomes basically unusable for minutes at a time.

The bug has not been definitively fixed yet across multiple releases of Ubuntu, but this fix sorts it out.

One fix I came across involves installing a dummy xapian indexing package in the hope that nothing breaks, but this fix is more elegant.

Credit goes to Bill Bennert, quoted from:

first of all
sudo apt-get install cpulimit

Then, you need to edit /etc/cron.weekly/apt-xapian-index to utilize the newly installed cpulimit.

Once the cron job has been modified, you wouldn't even know that  the index is being updated.

Here is the modified version of apt-xapian-index:


# ionice should not be called in a virtual environment
# (similar to man-db cronjobs)
egrep -q '(envID|VxID):.*[1-9]' /proc/self/status || IONICE=/usr/bin/ionice

# Check if we're on battery
if which on_ac_power >/dev/null 2>&1; then
    on_ac_power >/dev/null 2>&1

    # Here we use "-eq 1" instead of "-ne 0" because
    # on_ac_power could also return 255, which means
    # it can't tell whether we are on AC or not. In
    # that case, run update-a-x-i nevertheless.
    [ "$ON_BATTERY" -eq 1 ] && exit 0

# Rebuild the index
if [ -x "$CMD" ]
    if [ -x "$IONICE" ]
        # background process so we can limit it...
        nice -n 19 $IONICE -c 3 $CMD --quiet &
        nice -n 19 $CMD --quiet &
    # regulate the cpu for this process...
    # GETPID and PID could be put into one line, but...
    GETPID="ps -Alf | grep -v 'grep' | grep '$CMD' | awk '{print \$4}'"
    PID=$(eval $GETPID)
    if [ "$PID" != "" ]
        # -z to let script die after pid dies. -l to limit to 5%
        cpulimit -z -p $PID -l 5

No comments:

Post a Comment