连续同步本地文件到/来自S3
pys3sync的Python项目详细描述
s3sync公司
- Overview
- Features
- Requirements
- Installation
- Usage 在
- Configuration 在
- Performance Tests for aws sync command
概述
s3同步.py是一个实用程序,用于将文件作为连续运行的进程与S3同步,而不必手动管理同步。它在内部使用aws s3 sync
命令来执行同步,并使用python模块watchdog来监听被监视路径上的文件系统事件并将更改推送到S3。对于pull,没有实现侦听器,它执行简单的基于间隔的pull。因此,对于pull,建议使用s3fs-只需在文件系统上安装s3存储桶。在
特点
- 使用pythontocken-bucket模块进行速率限制。您可以在配置yaml中设置
max_syncs_per_minute
,文件系统观察器触发的推送将根据该限制进行限制。在 - 使用pyformance模块可选地报告同步操作的运行时统计信息
- 能够按
include_patterns
和exclude_patterns
或完全exclude_directories
,或使过滤器case_sensitive
- 自动设置awscli配置,方法是为实用程序创建一个单独的named profile,该实用程序可以通过设置
max_concurrent_requests
、max_queue_size
等来优化性能 - Setuptools集成,基于pythonclick的命令行界面
要求
需要安装AWS CLI version 2,并在路径中可用
安装
pip install pys3sync
用法
s3sync --help
Usage: s3sync.py [OPTIONS] COMMAND [ARGS]... A utility created to sync files to/from S3 as a continuously running process, without having to manually take care of managing the sync. It internally uses the aws s3 sync command to do the sync and uses python's watchdog listener to get notified of any changes to the watched folder. Options: --config PATH Path to the config.yaml file containing configuration params for this utility [required] -v, --verbosity LVL Either CRITICAL, ERROR, WARNING, INFO or DEBUG --help Show this message and exit. Commands: init Initial setup. pull One-way continuous sync from s3 path to local path (based on polling... push One-way continuous sync from localpath to s3 path (uses a file...
s3sync --config config.yaml push --help
s3sync --config config.yaml push --help
Usage: s3sync.py pull [OPTIONS] One-way continuous sync from s3 path to local path (based on polling on an interval) Options: --s3path PATH Full s3 path to sync to/from [required] --localpath PATH Local directory path which you want to sync [required] --interval INTEGER S3 polling interval in seconds [required] --help Show this message and exit.
首次运行/设置
s3sync --config-yaml config.yaml init
此实用程序为您的AWS CLI创建一个named profile,以便该实用程序的s3cli所需的参数与常规awscli概要文件隔离开来。第一次需要运行init
命令,该命令将在本地aws配置(~/.aws/config
)中创建命名的配置文件s3sync
,参数在config.yaml
中配置,凭据从默认的aws凭据文件复制。在
按下
对于要连续同步的localpath<;>s3path组合,可以运行此实用程序的一个实例
s3sync --config config.yaml -v DEBUG push --s3path s3://<bucket>/<path> --localpath ./
拉动
s3sync --config config.yaml -v DEBUG pull --s3path s3://<bucket>/<path> --localpath ./sync --interval 2
动作速率限制
配置
global:max_syncs_per_minute:10report_stats:Falsewatcher:include_patterns:exclude_patterns:["*.git/*"]exclude_directories:Falsecase_sensitive:Falses3:max_concurrent_requests:20max_queue_size:2000multipart_threshold:8MBmultipart_chunksize:8MBmax_bandwidth:use_accelerate_endpoint:"false"region:ap-south-1
包括/排除图案
Include/excluse模式是使用pathtools.match_any_path实现的,它最终支持unixglob模式语法。您可以使用提供的脚本patternhelper.py
测试您的模式。这些模式被传递给看门狗和awscli,后者也使用same syntax。这两个属性都接受模式列表。在
高级配置
请仔细更改这些值。它们取决于你的机器和你的互联网连接。阅读有关提高s3同步传输速度的更多信息here
最大并发请求数
通过aws configure set default.s3.max_concurrent_requests
命令传递到~/.aws/config
。阅读参数here
最大队列大小
通过aws configure set default.s3.max_queue_size
命令传递到~/.aws/config
。阅读参数here
多部分阈值
通过aws configure set default.s3.multipart_threshold
命令传递给~/.aws/config
。阅读参数here
多部分chunksize
通过aws configure set default.s3.multipart_chunksize
命令传递到~/.aws/config
。阅读参数here
最大带宽
通过aws configure set default.s3.max_bandwidth
命令传递给~/.aws/config
。阅读参数here
使用加速终点
通过aws configure set default.s3.use_accelerate_endpoint
命令传递到~/.aws/config
。阅读参数here
aws sync命令的性能测试
环境
Network: home/BLR (Airtel 1 Gbps Xtreme Fiber)
WiFi: 5 GHZ, RSS: -38 dbM, Tx rate: 1300 Mbps (802.11 ac)
Upload speed to s3: 18 MB/s
Download speed from s3: 15 MB/s
Number of threads for s3 sync command: 10 (default)
从本地同步到S3(上载)
测试工件1:https://github.com/apache/storm
尺寸:224M
文件数:3571
测试1(完全同步):
^{pR5}$测试2(添加39个文件,168k):
cp -rf ../intSDK .
time aws s3 sync --storage-class REDUCED_REDUNDANCY ./ s3://psm-poc-dmp-temp/codesync
real 0m3.141s
user 0m1.887s
sys 0m0.405s
测试3(删除398个文件,2.1M):
rm -rf examples/
time aws s3 sync --storage-class REDUCED_REDUNDANCY --delete ./ s3://psm-poc-dmp-temp/codesync
real 0m3.436s
user 0m2.276s
sys 0m0.406s
测试4(更改单个文件的时间戳):
touch README.markdown
time aws s3 sync --storage-class REDUCED_REDUNDANCY --delete --exact-timestamps ./ s3://psm-poc-dmp-temp/codesync
real 0m2.602s
user 0m1.492s
sys 0m0.296s
测试5(无变化):
time aws s3 sync --storage-class REDUCED_REDUNDANCY --delete --exact-timestamps ./ s3://psm-poc-dmp-temp/codesync
real 0m2.442s
user 0m1.469s
sys 0m0.294s
测试工件2:一堆png
尺寸:400米
文件数:577
测试1(完全同步)
time aws s3 sync --storage-class REDUCED_REDUNDANCY --delete --exact-timestamps ./ s3://psm-poc-dmp-temp/codesync
real 0m22.015s
user 0m5.972s
sys 0m2.516s
从S3同步到本地(下载)
测试工件1:https://github.com/apache/storm
尺寸:224M
文件数:3571
测试1(完全同步)
time aws s3 sync --storage-class REDUCED_REDUNDANCY --delete --exact-timestamps s3://psm-poc-dmp-temp/codesync ./
real 0m26.448s
user 0m14.544s
sys 0m3.794s
测试工件2:一堆png
尺寸:400米
文件数:577
测试1(完全同步)
time aws s3 sync --storage-class REDUCED_REDUNDANCY --delete --exact-timestamps s3://psm-poc-dmp-temp/codesync ./
real 0m29.268s
user 0m6.131s
sys 0m2.855s
- 项目
标签: