「Pacman のパフォーマンスの向上」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(Kusakata がページ「Pacman パフォーマンスの向上」を「Pacman のパフォーマンスの向上」に移動しました)
1行目: 1行目:
  +
#redirect[[pacman ヒント#パフォーマンス]]
[[Category:パッケージ管理]]
 
[[de:Pacman beschleunigen]]
 
[[en:Improve Pacman Performance]]
 
[[es:Improve Pacman Performance]]
 
[[fr:Ameliorer Pacman]]
 
[[it:Improve Pacman Performance]]
 
[[ru:Improve Pacman Performance]]
 
[[tr:Pacman_verimini_arttırmak]]
 
[[zh-CN:Improve Pacman Performance]]
 
[[zh-TW:Improve Pacman Performance]]
 
== データベースのアクセス速度を向上させる ==
 
 
Pacman はパッケージの全ての情報を、パッケージごとの小さなファイルに保存しています。データベースのアクセス速度を向上させればデータベースを使う処理 (例: パッケージの検索・パッケージの依存関係の解決) にかかる時間が短くなります。一番安全で簡単な方法は root で次を実行することです:
 
 
# pacman-optimize
 
 
小さなファイルをハードディスクのひとつの (物理的な) 場所にまとめて置くことでパッケージにアクセスするときにハードディスクのヘッドがあまり動かなくてもいいようにします。この方法は安全ですが、フールプルーフではありません。ファイルシステムによっては、ディスク上の使用している領域と空の領域がフラグメンテーションを起こすことがあります。さらにアグレッシブな方法として、データベースを最適化する前にインストールされていないパッケージをキャッシュから削除し使われていないリポジトリを削除するという方法があります:
 
 
# pacman -Sc && pacman-optimize
 
 
== ダウンロード速度を向上させる ==
 
 
{{Note|ダウンロード速度が極端に遅い場合、使っている[[ミラー]]が ftp.archlinux.org ではないことを確認してください。[https://www.archlinux.org/news/302/ 2007年の3月からこのサーバーには速度制限がかかっています]。}}
 
 
Pacman に初めから入っているファイルダウンローダの代わりに、他のアプリケーションを使ってパッケージをダウンロードすることで Pacman のパッケージダウンロード速度を上げることができます。
 
 
どんな場合でも、修正を行う前に最新の Pacman を使っていることを確認してください。
 
 
# pacman -Syu
 
 
=== Powerpill を使う ===
 
 
Powerpill は Pacman の完全なラッパーで並行・分割ダウンロードを使うことによってダウンロード処理を高速化します。通常の Pacman は一度にひとつのパッケージしかダウンロードしないので、ダウンロードが完了するまで次のダウンロードが始まりません。Powerpill は異なるアプローチを取ります: 同時に可能な限り多くのパッケージをダウンロードしようとします。
 
 
[[Powerpill|Powerpill の wiki ページ]]に基本的な設定・使用方法と、パッケージと上流のリンクがあります。
 
 
=== powerpill-light を使う (deprecated) ===
 
 
[http://xyne.archlinux.ca/projects/pacman2aria2/ pacman2aria2] は "powerpill-light" という名前のスクリプトを提供しており、Perl で書かれたオリジナルの powerpill が失くなった後の埋め合わせとして作られました。[[Powerpill|Powerpill]] が再リリースされた現在、powerpill-light は廃止されています。
 
 
=== wget を使う ===
 
 
pacman に初めから入っている機能よりもパワフルな proxy 設定が必要な場合、wget はとても使い勝手がよいです。
 
 
{{ic|wget}} を使うには、まず {{ic|pacman -S wget}} で wget をインストールして、それから {{ic|/etc/pacman.conf}} を編集して次の行を {{ic|[options]}} セクションでアンコメントしてください:
 
 
XferCommand = /usr/bin/wget -c --passive-ftp -c %u
 
 
{{ic|/etc/pacman.conf}} に {{ic|wget}} パラメータを記述する代わりに、{{ic|wget}} の設定ファイルを直接修正することも可能です (システム全体のファイルは {{ic|/etc/wgetrc}}、ユーザー別のファイルは {{ic|$HOME/.wgetrc}})。
 
 
=== aria2 を使う ===
 
 
[[aria2]] はレジューム機能と分割 HTTP/HTTPS/FTP ダウンロードをサポートしている軽量なダウンロードユーティリティです。[http://aria2.sourceforge.net/ aria2] を使えば同時に複数の HTTP/HTTPS/FTP 接続を Arch ミラーにすることができ、ファイル・パッケージの取得の際のダウンロード速度が上昇します。
 
 
{{Note|Pacman の XferCommand で aria2c を使っても複数パッケージの同時ダウンロードは'''行われません'''。Pacman はひとつのパッケージごとに XferCommand を呼び出し、それが完了してから次を呼び出すからです。同時に複数のパッケージをダウンロードするには、上の [[#Powerpill を使う|powerpill]] のセクションを見て下さい。}}
 
 
==== インストール ====
 
 
{{Pkg|aria2}} とその依存パッケージをダウンロード・インストールしてください:
 
 
# pacman -S aria2
 
 
==== 設定 ====
 
 
{{ic|/etc/pacman.conf}} を編集して {{ic|[options]}} セクションに次の行を追加して下さい:
 
 
{{bc|1=XferCommand = /usr/bin/aria2c --allow-overwrite=true -c --file-allocation=none --log-level=error -m2 -x2 --max-file-not-found=5 -k5M --no-conf -Rtrue --summary-interval=60 -t5 -d / -o %o %u}}
 
 
==== オプションの説明 ====
 
 
; {{Ic|/usr/bin/aria2c}}: aria2 実行ファイルのフルパス。
 
; {{Ic|1=--allow-overwrite=true}}: 対応するコントロールファイルが存在しない場合にダウンロードを再実行する (デフォルト: false)。
 
; {{Ic|-c, --continue}}: 対応するコントロールファイルが存在する場合に部分的にダウンロードされているファイルのダウンロードを続行する。
 
; {{Ic|1=--file-allocation=none}}: ダウンロードが始まる前にファイルの領域を事前に準備しない (デフォルト: prealloc)。<b><sup>1</sup></b>
 
; {{Ic|1=--log-level=error}}: ログレベルをエラーだけを出力するように設定する (デフォルト: debug)。
 
; {{Ic|1=-m2, --max-tries=2}}: ミラー毎に指定したファイルのダウンロードを最大2回まで試行する (デフォルト: 5)。
 
; {{Ic|1=-x2, --max-connection-per-server=2}}: ファイルごとにミラーに最大2つまで接続を設定する (デフォルト: 1)。
 
; {{Ic|1=--max-file-not-found=5}}: 5回試行したときにシングルバイトも受け取れなかった場合ダウンロードを中止する (デフォルト: 0)。
 
; {{Ic|1=-k5M, --min-split-size=5M}}: サイズが 2倍、5MB = 10MB よりも大きい時だけファイルを分割する (デフォルト: 20M)。
 
; {{Ic|--no-conf}}: {{ic|aria2.conf}} ファイルが存在するときにロードを無効にする (デフォルト: {{ic|~/.aria2/aria2.conf}})。
 
; {{Ic|1=-Rtrue, --remote-time=true}}: リモートのファイルのタイムスタンプをローカルのファイルに適用する (デフォルト: false)。
 
; {{Ic|1=--summary-interval=60}}: 60秒ごとにダウンロードの進行状況を表示する (デフォルト: 60)。<b><sup>2</sup></b>
 
; {{Ic|1=-t5, --timeout=5}}: 接続が確立された後ミラー毎に5秒間のタイムアウトを設定する (デフォルト: 60)。
 
; {{Ic|-d, --dir}}: [[pacman|pacman]] によって指定されているファイルのダウンロード先のディレクトリ。
 
; {{Ic|-o, --out}}: ダウンロードするファイルのファイル名の出力。
 
; {{Ic|%o}}: pacman によって指定されているローカルのファイル名を表す変数。
 
; {{Ic|%u}}: pacman によって指定されているダウンロード URL を表す変数。
 
 
==== 追記 ====
 
 
; <sup>1</sup> {{Ic|1=--file-allocation=falloc}}: (エクステントをサポートしている) ext4, btrfs, xfs などの新しいファイルシステムはすぐに大きなファイル (GB) を割り振るのでこのオプションを使うことを推奨します。ext3 などの古いファイルシステムでは falloc は使わないで下さい。prealloc は通常のアロケーションとほぼ同じ時間を消費し aria2 はダウンロード処理を中断します。
 
 
; <sup>2</sup> {{Ic|1=--summary-interval=0}}: ダウンロードの進行状況の出力をおさえることで全体のパフォーマンスが向上するかもしれません。{{Ic|log-level}} オプションに設定された値によってログは出力され続けます。
 
 
; <sup>3</sup> {{Ic|1=<nowiki>XferCommand = /usr/bin/printf 'Downloading ' && echo %u | awk -F/ '{printf $NF}' && printf '...' && /usr/bin/aria2c -q --allow-overwrite=true -c --file-allocation=none --log-level=error -m2 --max-connection-per-server=2 --max-file-not-found=5 --min-split-size=5M --no-conf --remote-time=true --summary-interval=0 -t5 -d / -o %o %u && echo ' Complete!'</nowiki>}}: XferCommand の使用はあまり意味がありませんが、出力の可読性は向上します。
 
 
=== pacget (aria2) ミラースクリプト ===
 
 
このスクリプトはブロードバンドを使っているユーザーのダウンロード速度を格段に向上させます。aria2 でミラーとして {{ic|/etc/pacman.d/mirrorlist}} 内のサーバーを使います。aria2 が複数のサーバーから同時にひとつのパッケージをダウンロードするのでダウンロード速度が大幅に加速します。
 
 
{{Note|You have to put 'exec' before /usr/bin/pacget in the XferCommand. This is needed so that when you terminate pacget or aria2 (with process id used by pacget), pacman would also terminate. This would prevent inconvenience because Pacman would not persist downloading a file when you tell it not to.}}
 
 
{{Warning|You may experience some problems if the mirrors used are out-of-sync or are simply not up-to-date. Just use the [[Reflector]] script to generate a list of up-to-date and ''fast'' mirrors. Also, ftp.archlinux.org resolves to two IPs. You may want to choose only one of them and hard code ftp.archlinux.org and the chosen IP address to {{ic|/etc/hosts}}.}}
 
 
{{hc|/usr/bin/pacget|<nowiki>
 
#!/bin/bash
 
 
msg() {
 
echo ""
 
echo -e " \033[1;34m->\033[1;0m \033[1;1m${1}\033[1;0m" >&2
 
}
 
 
error() {
 
echo -e "\033[1;31m==> ERROR:\033[1;0m \033[1;1m$1\033[1;0m" >&2
 
}
 
 
CONF=/etc/pacget.conf
 
STATS=/etc/pacget.stats
 
ARIA2=$(which aria2c 2> /dev/null)
 
 
# ----- do some checks first -----
 
if [ ! -x "$ARIA2" ]; then
 
error "aria2c was not found or isn't executable."
 
exit 1
 
fi
 
 
if [ $# -ne 2 ]; then
 
error "Incorrect number of arguments"
 
exit 1
 
fi
 
 
filename=$(basename $1)
 
server=${1%/$filename}
 
arch=$(grep ^Architecture /etc/pacman.conf | cut -d '=' -f2 | sed 's/ //g')
 
if [[ $arch = "auto" ]]; then
 
arch=$(uname -m)
 
fi
 
# Determine which repo is being used
 
repo=$(awk -F'/' '$(NF-2)~/^(community|core|extra|testing|comunity-testing|multilib)$/{print $(NF-2)}' <<< $server)
 
[ -z $repo ] && repo="custom"
 
 
# For db files, or when using a custom repo (which most likely doesn't have any mirror),
 
# use only the URL passed by pacman; Otherwise, extract the list of servers (from the include file of the repo) to download from
 
url=$1
 
if ! [[ $filename = *.db || $repo = "custom" ]]; then
 
mirrorlist=$(awk -F' *= *' '$0~"^\\["r"\\]",/Include *= */{l=$2} END{print l}' r=$repo /etc/pacman.conf)
 
if [ -n mirrorlist ]; then
 
num_conn=$(grep ^split $CONF | cut -d'=' -f2)
 
url=$(sed -r '/^Server *= */!d; s/Server *= *//; s/\$repo'"/$repo/"'; s/\$arch'"/$arch/; s/$/\/$filename/" $mirrorlist | head -n $(($num_conn *2)) )
 
fi
 
fi
 
 
msg "Downloading $filename"
 
cd /var/cache/pacman/pkg/
 
 
touch $STATS
 
 
$ARIA2 --conf-path=$CONF --max-tries=1 --max-file-not-found=5 \
 
--uri-selector=adaptive --server-stat-if=$STATS --server-stat-of=$STATS \
 
--allow-overwrite=true --remote-time=true --log-level=error --summary-interval=0 \
 
$url --out=${filename}.pacget && [ ! -f ${filename}.pacget.aria2 ] && mv ${filename}.pacget $2 && chmod 644 $2
 
 
exit $?
 
</nowiki>}}
 
 
{{hc|/etc/pacget.conf|<nowiki>
 
# The log file
 
log=/var/log/pacget.log
 
# Number of servers to download from
 
split=5
 
# Minimum file size that justifies a split, i.e. concurrent download (default 20M)
 
min-split-size=1M
 
# Maximum download speed (0 = unrestricted)
 
max-download-limit=0
 
# Minimum download speed (0 = do not care)
 
lowest-speed-limit=0
 
# Server timeout period
 
timeout=5
 
# 'none' or 'falloc'
 
file-allocation=none
 
</nowiki>}}
 
 
このスクリプトを {{ic|/usr/bin/pacget}} として保存してください。
 
# chmod 755 /usr/bin/pacget
 
上のコマンドでスクリプトが実行可能になります。
 
 
{{ic|/etc/pacman.conf}} の [options] セクション内に、以下を追加する必要があります:
 
XferCommand = exec /usr/bin/pacget %u %o
 
 
{{Note|If you use ftp.archlinux.org as the first server listed in your include files (/etc/pacman.d/*), some problems may occur when the mirrors you are using have not yet synced. To make great use of this script, choose a mirror (that syncs in a timely manner) that is more appropriate for you, then put that on top of the server lists. This is to prevent downloading only from ftp.archlinux.org when the mirrors have not yet synced. The rankmirrors script can be useful in this case.}}
 
 
=== 他のアプリケーションを使う ===
 
 
Pacman で利用できるダウンロードアプリケーションは他にもあります:
 
 
* {{ic|snarf}}: {{ic|1=XferCommand = /usr/bin/snarf -N %u}}
 
* {{ic|lftp}}: {{ic|1=XferCommand = /usr/bin/lftp -c pget %u}}
 
* {{ic|axel}}: {{ic|1=XferCommand = /usr/bin/axel -n 2 -v -a -o %o %u}}
 
 
== 最速のミラーを選ぶ ==
 
パッケージをダウンロードする際 pacman は {{ic|/etc/pacman.d/mirrorlist}} に記述されている順番でミラーを使用します。リストの一番上のミラーがデフォルトで使われますが、最速ではない可能性があります。最速のミラーを選択する方法は、[[ミラー]]を参照してください。
 
 
== LAN 上でパッケージを共有する ==
 
 
LAN 上で複数の Arch を動かしている場合、パッケージを共有することでダウンロード時間を減らすことが可能です。問題が生じるので、異なるアーキテクチャ間 (つまり i686 と x86_64) で共有することはできません。
 
 
[[Pacman ヒント#pacman のキャッシュをネットワークで共有する]]を見て下さい。
 

2016年9月23日 (金) 01:27時点における版