问题描述
我在 Ubuntu LTS 中使用 wget 程序每天从 Web 服务器下载一系列文件。最近,这个网络服务器已经不堪重负,负责维护它的组织 (NCEP) 似乎已经开始限制下载请求的数量和速度。
主要提示:在此之前,wget 能够在 15 分钟内完成所有文件的下载。这个过程现在需要几个小时。
服务器网址:ftp://ftp.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gfs.20210212/00/
文件:gfs.t00z.pgrb2.0p25.f${i}(我必须完整下载它们)
我的 wget 请求在 for 循环中相当简单,如下所示:
for i in {006..240..6}
do
wget -O /path/to/file/${ymd}/gfs.t${run}z.pgrb2.0p25.f$i ftp://ftp.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gfs.${ymd}/${run}/gfs.t${run}z.pgrb2.0p25.f$i
# Other Commands After wget Request Completed Here
done
我也尝试使用 aria2c 程序代替 wget,但发现完成时间几乎没有差异。我已经讨论过将所有这些文件包装在一个文本文件中并将这个列表传递给 wget,每 15 秒暂停我的下载,等等。
谢谢!
解决方法
一个选项是同时下载多个文件?我没有在您的服务器上对其进行测试,但假设您同时下载 5 个文件,速度大约是其 5 倍(假设您没有达到您或他们的最大互联网速度)。
一个实现可能如下所示:
for i in {006..240..6}; do
# Notice the & at the end of the next line. It's to start the wget process in a background thread. Our current thread just continues without waiting for wget
wget -O /path/to/file/${ymd}/gfs.t${run}z.pgrb2.0p25.f$i ftp://ftp.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gfs.${ymd}/${run}/gfs.t${run}z.pgrb2.0p25.f$i &
# Sleep until we have less than 5 running wget jobs at the same time
while [ $(jobs | wc -l) -ge 5 ]; do
sleep 1
done
done
for i in {006..240..6}; do
# We have all the files downloaded. Now do something with them.
echo Other Commands After wget Request Completed Here
done