After upgrade to Trusty (14.04) from Saucy (13.10), all apt operations are very slow. Even those that do not include downloading anything, or connecting to any servers. For example, displaying the apt policy
# time apt-cache policy
[...]
real 0m8.951s
user 0m5.069s
sys 0m3.861s
takes almost ten seconds! Mostly a weird lag right after issuing the command. And it's the same even if I issue the same command again.
On another system it doesn't take a tenth of a second
real 0m0.096s
user 0m0.070s
sys 0m0.023s
The other system is a little beefier but there was no noticeable difference before the upgrade.
It's the same with apt-get, anything apt-related. How do I find out the source of this lag and fix it?
Additional info:
# cat /etc/nsswitch.conf
# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.
passwd: compat
group: compat
shadow: compat
hosts: files dns
networks: files
protocols: db files
services: db files
ethers: db files
rpc: db files
netgroup: nis
BTW is my understanding of how apt-cache works correct? It doesn't make any network connections when I run apt-cache policy
, right?
In case I'm wrong and it matters, here are my sources https://gist.github.com/anonymous/02920270ff68e23fc3ec
Open terminal and first install bleachbit
Then run bleachbit as sudo:
Then perform a cleanup and you will see that things start going much faster :)
This not attended to be a direct answer, but some tracing hints to help finding out what's going on.
Using
strace
there was noconnect
, ie. it didn't try connect any server (process didn't open any socket)Trace it, relative timing:
See which step took longer:
Just remember this is relative timing, meaning current call shows its starting time with respect to previous one. In other words, that's the raw time took by previous call. Then you have get back to
apt-cache.trace
to know which call was that. A simple way usinggrep
that gives 10 lines before match:However I think
strace
is an advanced tool, I suggest tryingioprofiler
that provide a GUI for IO performance.Install it
Trace apt-cache
Open results
In my experience the delay in apt operation is quite natural, if the number of packages known to apt is very high. To know the number of packages run
apt-cache stats
. Do it on both computer and show the output.Consider the following situation. After booting from live iso (located in HDD), apt operation such
apt-get install
takes less than a second. The number of packages known to apt is ~7k. After adding some software sources such as packages from universe,main the apt know ~50k packages. Now the commandapt-get install
takes ~9 seconds (building dependency tree etc). Now the cache size is ~60 MBI noticed that uninstalling the Software Centre and app-install-data speeds up the apt-cache quite a lot now that I use synaptic package manager...
According to my testing the reason this is so slow is because
apt-cache policy some-package
iterates over file descriptors until it hits a limit error.For example I see this sort of stuff when stracing the process:
I think this points to a bug in apt-cache. One hacky way to work around it would be to limit the number of open files but that could cause things to fail unnecessarily in some cases.