Improve incremental send speed
This commit is contained in:
parent
7fac7a62cf
commit
5f7aa0b2d6
|
@ -3467,7 +3467,7 @@ def vm_worker_send_snapshot(
|
||||||
if incremental_parent is not None:
|
if incremental_parent is not None:
|
||||||
# Diff between incremental_parent and snapshot
|
# Diff between incremental_parent and snapshot
|
||||||
celery_message = (
|
celery_message = (
|
||||||
f"Sending diff {incremental_parent}>{snapshot_name} for {rbd_name}"
|
f"Sending diff {incremental_parent} -> {snapshot_name} for {rbd_name}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# Full image transfer
|
# Full image transfer
|
||||||
|
@ -3488,6 +3488,10 @@ def vm_worker_send_snapshot(
|
||||||
}
|
}
|
||||||
|
|
||||||
if incremental_parent is not None:
|
if incremental_parent is not None:
|
||||||
|
# Createa single session to reuse connections
|
||||||
|
session = requests.Session()
|
||||||
|
executor = ThreadPoolExecutor(max_workers=8)
|
||||||
|
|
||||||
send_params = {
|
send_params = {
|
||||||
"pool": pool,
|
"pool": pool,
|
||||||
"volume": volume,
|
"volume": volume,
|
||||||
|
@ -3495,14 +3499,17 @@ def vm_worker_send_snapshot(
|
||||||
"source_snapshot": incremental_parent,
|
"source_snapshot": incremental_parent,
|
||||||
}
|
}
|
||||||
|
|
||||||
last_chunk_time = time.time()
|
total_chunks = 0
|
||||||
|
|
||||||
def diff_cb_send(offset, length, exists):
|
def diff_cb_count(offset, length, exists):
|
||||||
nonlocal last_chunk_time
|
nonlocal total_chunks
|
||||||
if exists:
|
if exists:
|
||||||
data = image.read(offset, length)
|
total_chunks += 1
|
||||||
block = offset.to_bytes(8, "big") + length.to_bytes(8, "big") + data
|
|
||||||
response = requests.put(
|
current_chunk = 0
|
||||||
|
|
||||||
|
def send_block(block):
|
||||||
|
response = session.put(
|
||||||
f"{destination_api_uri}/vm/{vm_name}/snapshot/receive/block",
|
f"{destination_api_uri}/vm/{vm_name}/snapshot/receive/block",
|
||||||
timeout=destination_api_timeout,
|
timeout=destination_api_timeout,
|
||||||
headers=send_headers,
|
headers=send_headers,
|
||||||
|
@ -3512,19 +3519,27 @@ def vm_worker_send_snapshot(
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
current_chunk_time = time.time()
|
def diff_cb_send(offset, length, exists):
|
||||||
chunk_time = current_chunk_time - last_chunk_time
|
nonlocal current_chunk
|
||||||
last_chunk_time = current_chunk_time
|
if exists:
|
||||||
chunk_speed = round(4 / chunk_time, 1)
|
data = image.read(offset, length)
|
||||||
|
block = offset.to_bytes(8, "big") + length.to_bytes(8, "big") + data
|
||||||
|
|
||||||
|
executor.submit(send_block, block)
|
||||||
|
current_chunk += 1
|
||||||
|
|
||||||
update(
|
update(
|
||||||
celery,
|
celery,
|
||||||
celery_message + f" ({chunk_speed} MB/s)",
|
celery_message + f" ({current_chunk}/{total_chunks} objects)",
|
||||||
current=current_stage,
|
current=current_stage,
|
||||||
total=total_stages,
|
total=total_stages,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
image.set_snap(snapshot_name)
|
image.set_snap(snapshot_name)
|
||||||
|
image.diff_iterate(
|
||||||
|
0, size, incremental_parent, diff_cb_count, whole_object=True
|
||||||
|
)
|
||||||
image.diff_iterate(
|
image.diff_iterate(
|
||||||
0, size, incremental_parent, diff_cb_send, whole_object=True
|
0, size, incremental_parent, diff_cb_send, whole_object=True
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue