Difference between revisions of "Faster Pacman Downloads"

From ArchWiki
Jump to navigation Jump to search
(merged with : Improve Pacman Performance)
Line 1: Line 1:
[[Category:Package management (English)]]
+
#REDIRECT [[Improve Pacman Performance]]
[[Category:Customizing (English)]]
 
[[Category:Tutorials (English)]]
 
 
 
= Introduction =
 
 
 
A common method of enabling faster pacman downlods is to use ''wget'' as the XferAgent. Although this is a good solution, there is another alternative to wget, ''aria2''.
 
 
 
'''Note:''' This will not make your mirror perform better. If you are getting very slow downloads from your Arch mirror, [[Mirrors]] might be able to help you find a faster one.
 
 
 
== Aria2 ==
 
 
 
According to the aria2 [http://aria2.sourceforge.net website], aria2 is "a download utility with resuming and segmented downloading. Supports HTTP/HTTPS/FTP/BitTorrent/Metalink."
 
 
 
What this means is, it allows you to make several http/ftp connections to an Arch mirror at the same time, which should result in twice the download speed for all packages.
 
 
 
= Setting It Up =
 
 
 
The first thing we will need to do is install aria2, which is available in the Extra repository.
 
 
 
pacman -S aria2
 
 
 
Next, we need to configure pacman to use aria2 instead of it's internal downloader. This is done by editing ''/etc/pacman.conf''. Pop open your favorite editor and load it.
 
 
 
Look for the following line:
 
 
 
#XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u
 
 
 
This is almost exactly what we want, except that it's for wget, not aria2, and it's commented out, so it's not even in use. Let's change it look like this:
 
 
 
XferCommand = /usr/bin/aria2c -s 2 -m 2 -o %o %u
 
 
 
Let's run over the options here:
 
* ''/usr/bin/aria2c'' - the location of the aria2 application
 
* ''-s 2'' - use 2 concurrent connections (you can set this higher if you want, but it's not going to do a whole lot)
 
* ''-m 2'' - make 2 attempts to download the package per mirror
 
* ''-o %o'' - output to the file pacman specifies
 
* ''%u'' - download the file pacman specifies
 
 
 
= Aria2 Mirror Script =
 
 
 
This script will greatly improve the download speed for broadband users. It takes the download url from pacman, then looks up the mirror list in /etc/pacman.d/<repo> and adds them all as mirrors to aria2. What ends up happening is aria2 connects to 10-20 servers downloading from all of them at the same time, which should give anyone on broadband a huge boost in download speed.  This should max out the download speed for most people.
 
 
 
<pre>
 
#!/bin/bash
 
#pacget script
 
 
rm -f *.aria2
 
cachedir=/var/cache/pacman/pkg
 
file=`echo $1|awk -F '/' '{ print $NF }'`
 
echo Downloading: $file|sed 's,/,,'
 
repo=`echo $1|awk -F '/' '{x=NF-3 } { print  $x }'`
 
echo repo: $repo
 
if [[ $2 = *.db.tar.gz.part || $repo = "testing" ]]; then
 
        echo "(using one mirror)"
 
        mirrors=$1
 
else
 
        if [ -f /etc/pacman.d/$repo ]; then
 
        mirrors=`sed -n 's/^Server = //; s,$,/'"$file"', ; /^ftp/p; /^http/p' /etc/pacman.d/$repo`
 
        fi
 
fi
 
 
aria2c -t20 -m2 -l /var/log/pacget.log $mirrors -o $file.pacget
 
if [ -f $cachedir/$file.pacget.aria2 ]; then
 
      rm $cachedir/$file.pacget $cachedir/$file.pacget.aria2
 
      exit 0
 
fi
 
 
mv $file.pacget $2
 
exit 0
 
</pre>
 
 
 
Save this script as /usr/bin/pacget.
 
chmod 755 /usr/bin/pacget
 
This makes the script an executable
 
 
 
In /etc/pacman.conf the following needs to be added:
 
XferCommand = /usr/bin/pacget %u %o
 
 
 
Enjoy your optimized pacman.
 
 
 
PS: If the script doesn't work try to make sure that the official archlinux.org mirror is the first one in your /etc/pacman.d/<repo> list.
 
ie.
 
/etc/pacman.d/
 
[current]
 
# North America
 
Server = ftp://ftp.archlinux.org/current/os/i686
 
...
 
 
 
Don't forget to drop by, and give your feedback, or report any bugs here: http://bbs.archlinux.org/viewtopic.php?p=205427
 
 
 
= Conclusion =
 
 
 
That's it! pacman will now use aria2 to download all packages, and it should be noticably faster.
 
 
 
[[User:Shadowhand|Shadowhand]]
 

Revision as of 22:31, 31 January 2007