SSHを介したrsyncは時々非常に遅いです。時には帯域幅を使用します。

SSHを介したrsyncは時々非常に遅いです。時には帯域幅を使用します。

コンピュータA(Mac OS X)には、cronjobを介して5分ごとに実行するように設定されたbashスクリプトがあります。スクリプトは、リモートコンピュータB(Gentoo Linux)で新しいファイルを確認し、すべての新しいファイルをコンピュータAに同期します。時々、この同期(ダウンロード)は接続速度を3MB / sに最大化しますが、他の場合はおそらく10%の場合は10〜50KB / sの非常に低い速度でダウンロードされます。私のインターネット接続が切断または切断されたためではないと100%確信しています。それでは、この問題の原因は何ですか?

奇妙なことは、遅いrsyncジョブが常に遅く実行されることです。つまり、1 GB ファイルを同期すると、1 GB が完全にダウンロードされるまで、作業の全期間にわたって非常に遅い速度(10-50 KB/秒)で同期/ダウンロードされます。これにより、CPUの負荷やネットワークとは関係がなく、むしろスクリプトや他のものと関連があると信じられます。

私のスクリプトは次のとおりです。

# !/bin/sh

# Check if rsync has been timestampped and exit if it has
echo "Checking for local timestamp..." >> /Users/localuser/log/rsync.log
if [ -e /Users/localuser/scripts/.timestamp ]
then
        echo "Local timestamp already exists, exiting..." >> /Users/localuser/log/rsync.log
        exit
fi

# Timestamp rsync
echo "Local timestamp not found, continuing..." >> /Users/localuser/log/rsync.log
touch /Users/localuser/scripts/.timestamp

# Timestamp remote computer B
echo "Timestampping remote computer B" >> /Users/localuser/log/rsync.log
ssh remoteuser@remotecomputerb touch /home/remoteuser/finished/.timestamp

# Run rsync
echo "Starting rsync at $(date)" >> /Users/localuser/log/rsync.log
rsync -avzPL -e ssh remoteuser@remotecomputerb:/home/remoteuser/finished /share --log-file /Users/localuser/log/rsync.log

# Change permissions
echo "Changing permissions" >> /Users/localuser/log/rsync.log
chmod -Rf 775 /share
/usr/sbin/chown -Rf localuser:staff /share

# Delete sym links that are older than the remote computer B timestamp
echo "Deleting sym links on remote computer B" >> /Users/localuser/log/rsync.log
ssh remoteuser@remotecomputerb find /home/remoteuser/finished \! -newer /home/remoteuser/finished/.timestamp -type -l -delete

# Delete the rsync script timestamp
echo "rsync finished at $(date)" >> /Users/localuser/log/rsync.log
rm /Users/localuser/scripts/.timestamp

exit 0

ベストアンサー1

これは、基本的にリンク輻輳からリモートシステムの高いCPU使用率まで、すべてのことです。この間、すべてのネットワーク機器に障害が発生する可能性があります。特にSSHポートを爆撃するとき。ただし、ネットワーク機器のバッファリングの問題も原因になる可能性があります。

しかし、1つ:次回はrsyncが2回実行されていることをもう一度確認してください。はい、これを防ぐためにスクリプトに回避策を作成しましたが、誰も知りません...フォルダが読み取り専用である可能性があり、ファイルシステムが奇妙に動作する可能性があります...

したがって、正しく回答できる情報が十分でないことを理解してください。

しかし、rsync、このユースケースの使用を中止することをお勧めします。これは非効率的であり、エラーが発生しやすい。必要なのはフォルダの継続的な同期なので、次を見てください。物事を同期。遅延なしで同じ開放性とセキュリティでうまく機能するはずです。 (rsyncは、ワンタイムバックアップと定期的なバックアップには適していますが、フォルダを常に同期させるのには適していません。)

おすすめ記事