Apr 22, 2009

จำกัดความเร็วของ apt-get ด้วย trickle

การติดตั้งซอฟต์แวร์ในเดเบียนทางอินเทอร์เน็ตโดย apt-get นั้นต้องใช้การดาวน์โหลดโดยใช้ ftp หรือ http ซึ่ง apt-get มีตัวดาวน์โหลดของมันเองคือ

/usr/lib/apt/methods/ftp

และ

/usr/lib/apt/methods/http

แต่มีข้อเสียคือมันบริโภคแบนวิดท์จนเกือบหมด ทำให้ทำอย่างอื่นแทบไม่ได้ เรามีวิธีแก้ไขได้หลายวิธี เช่น ทำ proxy ที่มีการจำกัดความเร็ว แล้วสั่งให้ apt-get ใช้ proxy ตัวนั้นทาง /etc/apt/apt.conf.d หรือกำหนดผ่านตัวแปรระบบชื่อ http_proxy และ ftp_proxy สำหรับวิธีที่ง่ายกว่านั้นคือ ใช้โปรแกรมที่ชื่อ trickle ครับ เริ่มด้วยติดตั้ง

$ sudo apt-get install trickle

การใช้งานก็ง่ายๆ เช่น

$ trickle -s -d 10 apt-get --download-only upgrade && apt-get upgrade

อธิบาย -d 10 คือจำกัดความเร็วที่ 10 KB/s

ถ้าไม่อยากสั่ง trickle ทุกครั้งก็อาจแก้ไขตัว ftp และ http ของ apt-get โดย

$ dpkg-divert --local --rename /usr/lib/apt/methods/http
$ cat > /usr/lib/apt/methods/http <<EOF
#!/bin/sh
/usr/bin/trickle -s -d 10 /usr/lib/apt/methods/http.distrib
EOF

$ chmod 755 /usr/lib/apt/methods/http

$ dpkg-divert --local --rename /usr/lib/apt/methods/ftp
$ cat > /usr/lib/apt/methods/ftp <<EOF
#!/bin/sh
/usr/bin/trickle -s -d 10 /usr/lib/apt/methods/ftp.distrib
EOF

$ chmod 755 /usr/lib/apt/methods/ftp

จากนั้นก็ใช้งาน apt-get ตามปกติโดยไม่ต้องเรียก trickle เอง


หมายเหตุ:

เราสามารถประยุกต์ใช้วิธีนี้กับโปรแกรมอื่นๆ ที่มีการเชื่อมต่อกับ intenet ได้


0 ความคิดเห็น: