
最近我感覺 apt-get update 在某些伺服器上運行得比其他伺服器慢得多。
xxx@xxx:/usr/lib/php5/20121212$ sudo apt-get update
Ign http://downloads-distro.mongodb.org dist InRelease
某些伺服器執行apt-get update
後不到半秒就會顯示上面的第二行。而其他伺服器大約需要 5 秒鐘才能顯示第二行。
我sudo strace apt-get update
發現慢速伺服器會在下面停止幾秒鐘
open("/etc/apt/sources.list", O_RDONLY) = 4
read(4, "# \n\n# deb cdrom:[Ubuntu-Server 1"..., 8191) = 3488
pipe([5, 6]) = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f0ab30f3a50) = 30800
close(6) = 0
fcntl(5, F_GETFL) = 0 (flags O_RDONLY)
fstat(5, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f0ab2f68000
lseek(5, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek)
read(5, "i386\n <----------------- here
幾秒鐘後,它繼續如下
, 4096) = 5
read(5, "", 4096) = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=30800, si_status=0, si_utime=307, si_stime=167} ---
close(5) = 0
munmap(0x7f0ab2f68000, 4096)
所有伺服器的輸出幾乎相同。
如何解決問題?
答案1
最後,我的朋友發現了問題所在。
這是由開啟檔案限制引起的,我們為系統使用者將其設置得非常大。這是ubuntu的一個bug。
我們設定了一個更小的開啟檔案限制 apt-get 更新變得更快。