Skip to content

Conversation

@Kelly123456789
Copy link

add functions to ali_sync.py: configurable number of synchronization threads and limit the rate of synchronization data, and modify the corresponding configuration file

…threads and limit the rate of synchronization data, and modify the corresponding configuration file
FORCE_OVERRIDE: false

# 设置同步的并发线程数
THREADS_NUM_FOR_SYNC: 3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没看到在哪使用了这个配置

src/ali_sync.py Outdated
verb = 'PUT'
headers = {
'Content-Length': resp_object.content_length,
'Host': cnf['BAISHAN_ENDPOINT'][7:]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7 代表什么意思
用split或者其他字符串操作函数去掉http://或者https://

src/ali_sync.py Outdated
act_time = end_time - start_time
time_diff = expect_time - act_time
if time_diff > 0:
time.sleep(time_diff)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里统计的是 读时间+写时间, 这样算出来的时间计算speed会比实际配置的要小
只统计读或者写时间就好

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个限速要放在while循环内, 在每次读1MB数据都需要统计限制下速度

src/ali_sync.py Outdated
time.sleep(time_diff)

cli.read_response()
cli.status == 200
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是啥意思

Suggested change
cli.status == 200
cli.status == 200

src/ali_sync.py Outdated
return True


def upload_file(resp_object, result):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在哪里调用了upload_file 这个函数

src/ali_sync.py Outdated
start_time = time.time()
buf = resp_object.read(1024 * 1024)
end_time = time.time()
expect_time = send_size / cnf['SYNC_SPEED']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SYNC_SPEED是一个可选的配置项, 需要判断下是否设置

src/ali_sync.py Outdated

send_size = 0
while True:
start_time = time.time()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start_time设置为读取整个body的开始时间

src/ali_sync.py Outdated
cli.send_body(buf)
send_size += 1024 * 1024

if buf == '':
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

放在while循环最开始

src/ali_sync.py Outdated
th_status['pipe_progress'] = (done_bytes, total_bytes)

file_object = result['file_object']
upload_file(file_object, result)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要替换的是418行的代码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants