序言
为了验证使用 Mountpoint for Amazon S3 挂载路径时,是否可以通过常见的下载命令(wget
、curl
、aria2
)直接下载文件,我进行了一些测试。
测试架构
在 EC2 实例上,我们将 Amazon S3 存储桶通过 Mountpoint for Amazon S3 挂载,并尝试使用 wget
、curl
和 aria2
三种工具下载文件,测试其可行性和性能表现。
测试结果与分析
测试发现,wget
和 curl
可以 直接下载文件到 S3 挂载点,而 aria2
失败。不过,与直接下载到 EBS 相比,下载到 S3 挂载点的速度不到 一半,并且所有命令均无法正常恢复下载(断点续传不可用)。
命令 | 下载到 EBS | 直接下载到 S3 | 恢复下载 |
---|---|---|---|
wget | ✅ 468MB/s | ❌ 103MB/s | ❌ 不允许操作 |
curl | ✅ 535MB/s | ❌ 198MB/s | ❌ 写入接收数据失败 |
aria2 | ✅ 734MB/s | ❌ I/O 错误 | - |
验证背景
由于 Mountpoint for Amazon S3 并不完全支持 POSIX,因此我们尝试验证它是否可以作为文件下载目标,特别是针对以下几点进行确认:
- 是否可以直接将文件下载到 S3 挂载点
- 下载速度比较(EBS vs S3)
- 恢复(Resumable)功能的运行情况
验证环境
执行环境
项目 | 规格 |
---|---|
OS | Amazon Linux 2023 |
内核 | 6.1.128-136.201.amzn2023.x86_64 |
AMI 名称 | al2023-ami-2023.6.20250218.2-kernel-6.1-x86_64 |
AMI ID | ami-072298436ce5cb0c4 |
区域 | ap-northeast-1 |
实例类型 | m7a.large |
使用的命令
命令 | 版本 |
---|---|
wget | 1.21.3 |
curl | 8.5.0 |
aria2 | 1.37.0 |
下载对象
下载源服务器信息
本次测试选择了 中国官方 Ubuntu 镜像站点,以提供 高速网络,并尽量减少网络带宽限制对速度的影响。
项目 | 内容 |
---|---|
镜像站名称 | 中国官方 Ubuntu 镜像站 |
状态 | Official Ubuntu Mirror |
网络速度 | 100 Gbps |
所在地 | 中国 |
URL | https://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/ |
测试对象文件
项目 | 内容 | 备注 |
---|---|---|
文件名 | ubuntu-24.04.2-live-server-amd64.iso | Ubuntu Server 24.04.2 ISO |
文件大小 | 约 3 GB | |
下载目标(EBS) | /tmp | 本地磁盘 |
下载目标(S3) | /mnt/s3 | S3 挂载点 |
文件下载测试:使用不同命令对比
在本次测试中,我们通过不同命令对大约 3GB 的 ISO 文件进行下载,测试了从 EBS 和 S3 挂载点 下载的性能。以下是 wget
的测试结果。
wget 的测试结果
项 目 | 结 果 | 速 度 | 备 注 |
---|---|---|---|
EBS 下载 | ✅ 成功 | 468MB/s | — |
直接下载到 S3 | ✅ 成功 | 103MB/s | utime 错误 |
恢复功能 | ❌ 失败 | — | Operation not permitted |
EBS 下载
从 EBS 下载没有遇到任何问题,速度非常理想,达到 468MB/s,与其他存储系统相比,这一速度非常快。
$ time wget -P /tmp https://ftp.udx.icscoe.jp/Linux/ubuntu-releases/24.04.2/ubuntu-24.04.2-live-server-amd64.iso
ubuntu-24.04.2-live-se 100%[==========================>] 2.99G 468MB/s in 6.6s
real 0m6.730s
下载到 S3 挂载点
虽然出现了 utime
错误,但文件本身已成功下载。这个问题可能是在更新下载文件的时间戳时发生了失败。
$ time wget -P /mnt/s3 https://ftp.udx.icscoe.jp/Linux/ubuntu-releases/24.04.2/ubuntu-24.04.2-live-server-amd64.iso
ubuntu-24.04.2-live-se 100%[==========================>] 2.99G 116MB/s in 30s
utime(/mnt/s3/ubuntu-24.04.2-live-server-amd64.iso): Operation not permitted
2025-02-23 22:32:17 (103 MB/s) - '/mnt/s3/ubuntu-24.04.2-live-server-amd64.iso' saved [3213064192/3213064192]
real 0m30.646s
通过添加不更改文件时间戳的选项(--no-use-server-timestamps
),错误得以解决。
$ time wget --no-use-server-timestamps -P /mnt/s3 https://ftp.udx.icscoe.jp/Linux/ubuntu-releases/24.04.2/ubuntu-24.04.2-live-server-amd64.iso
ubuntu-24.04.2-live-se 100%[==========================>] 2.99G 116MB/s in 27s
real 0m27.595s
恢复功能的验证
在下载过程中中断(Ctrl+C)后,尝试使用 -c 选项恢复,但因“操作不允许”错误而失败。这是因为在 S3 的挂载点不允许进行文件追加操作。
$ time wget -P /mnt/s3 -c https://ftp.udx.icscoe.jp/Linux/ubuntu-releases/24.04.2/ubuntu-24.04.2-live-server-amd64.iso
4.04.2-live-server-amd 14%[==> ] 433.18M 116MB/s eta 24s ^C
$ time wget -P /mnt/s3 -c https://ftp.udx.icscoe.jp/Linux/ubuntu-releases/24.04.2/ubuntu-24.04.2-live-server-amd64.iso
Cannot write to '/mnt/s3/ubuntu-24.04.2-live-server-amd64.iso' (Operation not permitted).
curl 下载测试结果
项目 | 结果 | 速度 | 备注 |
---|---|---|---|
EBS 下载 | ✅ 成功 | 535MB/s | — |
直接下载到 S3 | ✅ 成功 | 198MB/s | — |
恢复功能 | ❌ 失败 | — | Failed writing received data |
EBS 下载
从 EBS 下载顺利完成,速度为 535MB/s,非常快速。
$ time curl -o /tmp/ubuntu.iso https://ftp.udx.icscoe.jp/Linux/ubuntu-releases/24.04.2/ubuntu-24.04.2-live-server-amd64.iso
100 3064M 100 3064M 0 0 535M 0 0:00:05 0:00:05 --:--:-- 536M
real 0m5.733s
下载到 S3 挂载点
成功下载到 S3 挂载点,记录了 198MB/s 的传输速度。与 wget 相比,速度虽然有所下降,但没有出现错误,顺利完成。
$ time curl -o /mnt/s3/ubuntu.iso https://ftp.udx.icscoe.jp/Linux/ubuntu-releases/24.04.2/ubuntu-24.04.2-live-server-amd64.iso
100 3064M 100 3064M 0 0 198M 0 0:00:15 0:00:15 --:--:-- 266M
real 0m16.115s
恢复功能的验证
使用 -C 选项尝试恢复,但因“写入接收数据失败”错误而失败。这也是因为 S3 的挂载点不支持对现有文件的追加操作。
# 下载中断
$ time curl -C - -o /mnt/s3/ubuntu.iso https://ftp.udx.icscoe.jp/Linux/ubuntu-releases/24.04.2/ubuntu-24.04.2-live-server-amd64.iso
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
17 3064M 17 543M 0 0 91.1M 0 0:00:33 0:00:05 0:00:28 109M^C
# 下载再开
$ time curl -C - -o /mnt/s3/ubuntu.iso https://ftp.udx.icscoe.jp/Linux/ubuntu-releases/24.04.2/ubuntu-24.04.2-live-server-amd64.iso
curl: Can't open '/mnt/s3/ubuntu.iso'
curl: (23) Failed writing received data to disk/application
aria2 下载测试结果
项目 | 结果 | 速度 | 备注 |
---|---|---|---|
EBS 下载 | ✅ 成功 | 734MB/s | — |
直接下载到 S3 | ❌ 失败 | — | I/O Error |
恢复功能 | — | — | 由于无法进行直接下载,未进行验证 |
EBS 下载
使用 aria2 通过 多连接(-x16
参数)进行并行下载,成功以 734MB/s 的速度完成,达到了非常高的传输速度。
$ time aria2c -x16 -d /tmp https://ftp.udx.icscoe.jp/Linux/ubuntu-releases/24.04.2/ubuntu-24.04.2-live-server-amd64.iso
Download Results:
gid |stat|avg speed |path/URI
======+====+===========+=======================================================
a01a1e|OK | 734MiB/s|/tmp/ubuntu-24.04.2-live-server-amd64.iso
real 0m6.756s
下载到 S3 挂载点
发生了 I/O 错误。可能是因为 aria2 的高级文件操作在 S3 的挂载点上不受支持。
$ time aria2c -d /mnt/s3/ https://ftp.udx.icscoe.jp/Linux/ubuntu-releases/24.04.2/ubuntu-24.04.2-live-server-amd64.iso
Exception: [AbstractDiskWriter.cc:459] errNum=5 errorCode=17 Failed to write into the file /mnt/s3//ubuntu-24.04.2-live-server-amd64.iso, cause: Input/output error
总结
基本事项
- 可以使用 wget 和 curl 从挂载的 S3 路径直接下载文件。
- 但是,下载速度与 EBS 相比,降低了 40%-50%。
功能限制
- 恢复功能:在所有命令中均不可用。
使用建议
- 对于小规模文件:建议使用 wget 或 curl 从挂载的 S3 路径直接下载。
- 对于大文件下载:根据需求选择不同工具或方法,建议先通过 EBS 或其他存储系统下载。
- 如果需要更高的下载速度,可以先从 EBS 等存储系统下载,再转移到 S3。
- 对于不能直接下载的情况,建议使用 EBS 或类似存储系统,或者使用其他工具来优化传输。
Amazon S3 的挂载点是一个方便的工具,但由于它并不完全兼容 POSIX,因此需要根据使用场景进行适当的区分。
结束
我试着用 wget 和 curl 下载文件后,想着 aria2 应该也能行,于是尝试了一下。但如果不指定并行下载(即未使用 -x 参数),结果就不行。这方面看来还是取决于工具或应用程序如何处理文件,无法确定,只能通过实际尝试来了解。