Improve QuickSync and Bandwidth

This commit is contained in:
Taylor Helsper 2019-08-20 21:02:57 -05:00
parent 59bebe31bd
commit e9f4b03fc9
3 changed files with 54 additions and 50 deletions

View File

@ -5,55 +5,53 @@ set -x
source /usr/share/mynode/mynode_config.sh
BACKGROUND_DL_RATE=4000
if [ $IS_RASPI3 -eq 1 ]; then
BACKGROUND_DL_RATE=500
fi
# Let transmission startup
sleep 60s
# If marked as uploader, dont slow down
while [ -f $UPLOADER_FILE ]; do
echo "Marked as uploader, unlimited upload"
transmission-remote -U
sleep 1h
# Check transmission is started
until transmission-remote -l ; do
sleep 60s
done
# Upload slowly while downloading
# Default is download only until we determine state
transmission-remote -u 0
transmission-remote -D
# Wait until download is complete...
while [ ! -f "/mnt/hdd/mynode/quicksync/.quicksync_complete" ]; do
sleep 30s
done
# Wait until blockchain is synced...
while [ ! -f "/mnt/hdd/mynode/.mynode_bitcoind_synced" ]; do
sleep 30s
done
# Enable uploading
echo "QuickSync Complete! Enabling Uploading."
# Determine current state
while true; do
PERCENT=$(transmission-remote -t 1 -i | grep "Percent Done:")
if [ -f $UPLOADER_FILE ]; then
echo "Marked as uploader, unlimited upload"
echo "Marked as uploader, unlimited upload, unlimited download"
transmission-remote -U
transmission-remote -D
elif [ ! -f "/mnt/hdd/mynode/quicksync/.quicksync_complete" ]; then
echo "QuickSync not complete, stopping upload"
echo "QuickSync not complete, stopping upload, unlimited download"
transmission-remote -u 0
transmission-remote -D
elif [ ! -f "/mnt/hdd/mynode/.mynode_bitcoind_synced" ]; then
echo "Bitcoin not synced, stopping upload"
echo "Bitcoin not synced, stopping upload, stopping download"
transmission-remote -u 0
transmission-remote -d 0
elif [[ "$PERCENT" != *"100"* ]]; then
echo "QuickSync is downloading, stopping upload"
echo "QuickSync is downloading (but has completed once), stopping upload, limited download"
transmission-remote -u 0
transmission-remote -d $BACKGROUND_DL_RATE
elif [ -f $QUICKSYNC_BANDWIDTH_FILE ]; then
RATE=$(cat $QUICKSYNC_BANDWIDTH_FILE)
echo "Setting upload rate to $RATE kbps"
transmission-remote -u $RATE
transmission-remote -d $BACKGROUND_DL_RATE
else
echo "Setting upload rate to unlimited"
transmission-remote -U
transmission-remote -D
fi
sleep 1h
sleep 10m
done
# We should not exit

View File

@ -63,33 +63,39 @@ fi
if [ ! -f $QUICKSYNC_DIR/blockchain.torrent ]; then
cp $QUICKSYNC_DIR/blockchain_temp.torrent $QUICKSYNC_DIR/blockchain.torrent
else
# Run commands as long as torrents are different (last command updates torrent file)
COMPLETED=0
if [ -f $QUICKSYNC_DIR/.quicksync_complete ]; then
COMPLETED=1
fi
NEW_TORRENT=0
cmp --silent $QUICKSYNC_DIR/blockchain_temp.torrent $QUICKSYNC_DIR/blockchain.torrent || NEW_TORRENT=1
if [ $NEW_TORRENT -eq 1 ]; then
# Delete old QuickSync data+config and start new one
rm -f $QUICKSYNC_DIR/*
rm -rf $QUICKSYNC_CONFIG_DIR
mkdir -p $QUICKSYNC_CONFIG_DIR
cp -f /usr/share/quicksync/settings.json $QUICKSYNC_CONFIG_DIR/settings.json
cp $QUICKSYNC_DIR/blockchain_temp.torrent $QUICKSYNC_DIR/blockchain.torrent
sync
# If download had been completed
if [ $COMPLETED -eq 1 ]; then
touch $QUICKSYNC_DIR/.quicksync_download_complete
touch $QUICKSYNC_DIR/.quicksync_complete
if [ $IS_RASPI3 -eq 1 ] && [ ! -f $UPLOADER_FILE ]; then
# Don't help with uploads during normal operation.... too slow
sleep 1s
else
# Run commands as long as torrents are different (last command updates torrent file)
COMPLETED=0
if [ -f $QUICKSYNC_DIR/.quicksync_complete ]; then
COMPLETED=1
fi
NEW_TORRENT=0
cmp --silent $QUICKSYNC_DIR/blockchain_temp.torrent $QUICKSYNC_DIR/blockchain.torrent || NEW_TORRENT=1
if [ $NEW_TORRENT -eq 1 ]; then
# Delete old QuickSync data+config and start new one
rm -f $QUICKSYNC_DIR/*
rm -rf $QUICKSYNC_CONFIG_DIR
mkdir -p $QUICKSYNC_CONFIG_DIR
cp -f /usr/share/quicksync/settings.json $QUICKSYNC_CONFIG_DIR/settings.json
cp $QUICKSYNC_DIR/blockchain_temp.torrent $QUICKSYNC_DIR/blockchain.torrent
sync
# If download had been completed
if [ $COMPLETED -eq 1 ]; then
touch $QUICKSYNC_DIR/.quicksync_download_complete
touch $QUICKSYNC_DIR/.quicksync_complete
fi
sync
fi
sync
fi
fi
# If Quicksync has already completed, let's give BTC some time to start
# If Quicksync has already completed, let's give BTC some time to start before
# seeding or downloading a more recent copy
if [ -f $QUICKSYNC_DIR/.quicksync_complete ]; then
/usr/bin/wait_on_bitcoin.sh
sleep 5m

View File

@ -10,7 +10,7 @@
"bind-address-ipv6": "::",
"blocklist-enabled": false,
"blocklist-url": "http://www.example.com/blocklist",
"cache-size-mb": 4,
"cache-size-mb": 64,
"dht-enabled": true,
"download-dir": "/mnt/hdd/mynode/quicksync",
"download-queue-enabled": false,
@ -25,7 +25,7 @@
"peer-congestion-algorithm": "",
"peer-id-ttl-hours": 6,
"peer-limit-global": 200,
"peer-limit-per-torrent": 50,
"peer-limit-per-torrent": 5,
"peer-port": 56881,
"peer-port-random-high": 56899,
"peer-port-random-low": 56881,
@ -63,6 +63,6 @@
"start-added-torrents": true,
"trash-original-torrent-files": false,
"umask": 18,
"upload-slots-per-torrent": 5,
"upload-slots-per-torrent": 3,
"utp-enabled": false
}