High CPU Usage on Ubuntu By update-apt-xapi Process



update-apt-xapian-index is truncated and shown as update-apt-xapi in top tool. This process is responsible for maintaining an index of packages to speed up search on Synaptic and is scheduled as a cron job (/etc/cron.weekly).

This is the cron job, triggering the process:

#!/bin/sh

CMD=/usr/sbin/update-apt-xapian-index

IONICE=/usr/bin/ionice

# Rebuild the index
if [ -x $CMD ]
then
if [ -x $IONICE ]
then
nice $IONICE -c3 $CMD --quiet
else
nice $CMD --quiet
fi
fi

Edit the lines to show the following:


#!/bin/sh

CMD=/usr/sbin/update-apt-xapian-index

IONICE=/usr/bin/ionice

# Rebuild the index

if [ -x $CMD ]
then
if [ -x $IONICE ]
then
nice -n 19 $IONICE -c 3 $CMD --update --quiet
else
nice -n 19 $CMD --update --quiet
fi
fi

The modification will help reduce CPU usage. -n 19 option gives least favorable scheduling priority. --update option causes the process to update the index instead of rebuilding it every time.

12 comments:

  1. Many thanks for this - my machine crawls whilst this job runs.

    Thanks also for including in the text the
    "top" report string as google food. "update-apt-xapi" is a bit misleading to say the least if one doesn't know about xapian-index.

    ReplyDelete
  2. Glad to know that you find this useful.

    ReplyDelete
  3. Thank you very much. This information was usefull for me.

    Best regards.
    Guillermo from Argentina.

    ReplyDelete
  4. Thank you; I was running into the same high CPU usage issue with Mint. It already had changed the nice values to 19, but I added the --update flags. I hope to see positive results from that change.

    ReplyDelete
  5. Thank for sharing. I also hope to see positive result.

    ReplyDelete
  6. UPDATE: Looks like Ubuntu is including these changes in by default now. You need not worry about it if you are updating!

    ReplyDelete
  7. @Sap Nwnewbie: as a user of Ubuntu 11.10 and 12.04 I can tell the problem is not solved yet.
    They added the "-n 19" part of the correction, but not the "--update"...

    ReplyDelete
  8. LAST MINUTE: you may also need to add --update option to update-apt-xapian-index in /etc/cron.daily/apt

    nice ionice -c 3 update-apt-xapian-index --update -q $xapian_extra_args

    This explain why update-apt-xapian-index is not only having high CPU usage on Sunday as it should with cron.weekly

    ReplyDelete
  9. @Alain. Thanks for the additional input.

    ReplyDelete

Thanks for reading the post. Hope it was useful.
Please let us know if we could have done a better job or if you have applied the ideas to a real life problem.
If you want us to post on something that has been bugging you, ask away!