首先我们需要准备自己的测试环境,为了简便创建和减少创建中的错误,我们这里使用 AWS CloudFormation 来一键创建我们需要的测试资源栈。
https://s3.amazonaws.com/code.wzlinux.com/wzlinux_storage_performance.yaml
然后查看创建过程,直到资源创建完毕。
Wzlinux_Storage_Performance
。隔一段时间之后,会话会自动断开,到时候关闭窗口重新连接即可。
这里我们会用到一个 IO 测试工具 fio,工具已经使用 CloudFormation 安装好了,我们使用这个工具把 EC2 上面的 GP2 硬盘的 burst credits 消耗完,这样可以去测试真实的 EBS 性能。
ps -ef| grep fio
sudo screen -r
lsblk
sudo umount /ebsperftest
sudo resize2fs /dev/nvme1n1
sudo mount /ebsperftest
df -h
在本节中,我们将通过对大型对象拆分为更小的块并增加用于传输对象的线程数来演示大型对象的并行化传输。
aws configure
aws configure set default.s3.max_concurrent_requests 1
aws configure set default.s3.multipart_threshold 64MB
aws configure set default.s3.multipart_chunksize 16MB
cat ~/.aws/config
dd if=/dev/urandom of=5GB.file bs=1 count=0 seek=5G
# 配置环境变量
bucket=storageperformanceworkshop-bucket01-z66if6h9nuco
time aws s3 cp 5GB.file s3://${bucket}/upload1.test
aws configure set default.s3.max_concurrent_requests 2
time aws s3 cp 5GB.file s3://${bucket}/upload2.test
aws configure set default.s3.max_concurrent_requests 10
time aws s3 cp 5GB.file s3://${bucket}/upload3.test
aws configure set default.s3.max_concurrent_requests 20
time aws s3 cp 5GB.file s3://${bucket}/upload4.test
我们看到,在 10 个线程提升到 20 个线程后,传输速度并没有成倍提升。在某种程度上, AWS CLI 会限制所能达到的性能。这是一个 CLI 的限制,如果我们使用其他的传输软件将线程数增加到 100 个,可以继续提高传输的性能。
dd if=/dev/urandom of=1GB.file bs=1 count=0 seek=1G
数据也可以被拆分成多个部分,下一步讲演示如何使用多个源文件传输 5 GB 的数据。
time seq 1 5 | parallel --will-cite -j 5 aws s3 cp 1GB.file s3://${bucket}/parallel/object{}.test
这个小节,我们将使用 aws s3 sync 命令传输 2 GB 的数据,共计 2000 个文件。
aws configure set default.s3.max_concurrent_requests 1
time aws s3 sync /ebs/tutorial/data-1m/ s3://${bucket}/sync1/
aws configure set default.s3.max_concurrent_requests 10
time aws s3 sync /ebs/tutorial/data-1m/ s3://${bucket}/sync2/
这个练习将演示如何在移动小对象时增加每秒事务量(TPS)。
seq 1 500 > object_ids
cat object_ids
dd if=/dev/urandom of=1KB.file bs=1 count=0 seek=1K
time parallel --will-cite -a object_ids -j 1 aws s3 cp 1KB.file s3://${bucket}/run1/{}
time parallel --will-cite -a object_ids -j 10 aws s3 cp 1KB.file s3://${bucket}/run2/{}
time parallel --will-cite -a object_ids -j 50 aws s3 cp 1KB.file s3://${bucket}/run3/{}
time parallel --will-cite -a object_ids -j 100 aws s3 cp 1KB.file s3://${bucket}/run4/{}
从 50 个线程增加到 100 个线程可能不会带来更高的性能。为了便于演示,我们使用 AWS CLI 的多个实例来显示一个概念。在现实世界中,开发人员将创建比我们的演示方法更有效的线程池。可以合理地假设,添加的线程应该继续增加性能,直到出现类似 CPU 耗尽的另一个瓶颈。
在本练习中,我们将演示如何更有效地将文件从 S3中的一个位置复制到另一个位置。
time (aws s3 cp s3://$bucket/upload1.test 5GB.file; aws s3 cp 5GB.file s3://$bucket/copy/5GB.file)
time aws s3api copy-object --copy-source $bucket/upload1.test --bucket $bucket --key copy/5GB-2.file
time aws s3 cp s3://$bucket/upload1.test s3://$bucket/copy/5GB-3.file
在这个练习中,我们将演示创建1024 个文件的不同方法,并比较每个方法的性能。
directory=$(echo $(uuidgen)| grep -o ".\\{6\\}$")
mkdir -p /efs/tutorial/touch/${directory}
time for i in {1..1024}; do
touch /efs/tutorial/touch/${directory}/test-1.3-$i;
done;
directory=$(echo $(uuidgen)| grep -o ".\\{6\\}$")
mkdir -p /efs/tutorial/touch/${directory}
time seq 1 1024 | parallel --will-cite -j 128 touch /efs/tutorial/touch/${directory}/test-1.4-{}
directory=$(echo $(uuidgen)| grep -o ".\\{6\\}$")
mkdir -p /efs/tutorial/touch/${directory}/{1..32}
time seq 1 32 | parallel --will-cite -j 32 touch /efs/tutorial/touch/${directory}/{}/test1.5{1..32}
利用 Amazon EFS 的分布式数据存储设计的最佳方法是并行使用多个线程和 inodes。
在这个练习中,我们将演示不同的 I/O 大小和同步频率如何影响 EFS 的吞吐量。
time dd if=/dev/zero of=/efs/tutorial/dd/2G-dd-$(date +%Y%m%d%H%M%S.%3N) bs=1M count=2048 status=progress conv=fsync
time dd if=/dev/zero of=/efs/tutorial/dd/2G-dd-$(date +%Y%m%d%H%M%S.%3N) bs=16M count=128 status=progress conv=fsync
time dd if=/dev/zero of=/efs/tutorial/dd/2G-dd-$(date +%Y%m%d%H%M%S.%3N) bs=1M count=2048 status=progress oflag=sync
time dd if=/dev/zero of=/efs/tutorial/dd/2G-dd-$(date +%Y%m%d%H%M%S.%3N) bs=16M count=128 status=progress oflag=sync
本练习将演示多线程访问如何提高吞吐量和 IOPS。
time seq 0 3 | parallel --will-cite -j 4 dd if=/dev/zero of=/efs/tutorial/dd/2G-dd-$(date +%Y%m%d%H%M%S.%3N)-{} bs=1M count=512 oflag=sync
time seq 0 15 | parallel --will-cite -j 16 dd if=/dev/zero of=/efs/tutorial/dd/2G-dd-$(date +%Y%m%d%H%M%S.%3N)-{} bs=1M count=128 oflag=sync
在本节中,我们将比较不同的文件传输实用程序和 EFS 的性能。
du -csh /ebs/tutorial/data-1m/
find /ebs/tutorial/data-1m/. -type f | wc -l
sudo su
sync && echo 3 > /proc/sys/vm/drop_caches
exit
time rsync -r /ebs/tutorial/data-1m/ /efs/tutorial/rsync/
sudo su
sync && echo 3 > /proc/sys/vm/drop_caches
exit
time cp -r /ebs/tutorial/data-1m/* /efs/tutorial/cp/
threads=$(($(nproc --all) * 4))
echo $threads
sudo su
sync && echo 3 > /proc/sys/vm/drop_caches
exit
time fpsync -n ${threads} -v /ebs/tutorial/data-1m/ /efs/tutorial/fpsync/
sudo su
sync && echo 3 > /proc/sys/vm/drop_caches
exit
time find /ebs/tutorial/data-1m/. -type f | parallel --will-cite -j ${threads} cp {} /efs/tutorial/parallelcp
aws configure set default.s3.max_concurrent_requests 20
aws s3 rm s3://${bucket} --recursive
【AWS征文】用什么方法来挖掘提升 EBS、S3 和 EFS 的潜在性能
原文:https://blog.51cto.com/14902472/2523185