Commit d9aafb6f by Máhonfai Bálint

Work around slow upload speed caused by httplib hardcoded small blocksize

parent 27f4364e
......@@ -323,23 +323,34 @@ class Disk(object):
subprocess.check_output(cmdline)
size = os.path.getsize(exported_path)
percent = [0]
def update_state(monitor):
percent = monitor.bytes_read * 100 / size
new_percent = monitor.bytes_read * 100 / size
if task.is_aborted():
raise AbortException()
task.update_state(
task_id=parent_id,
state=task.AsyncResult(parent_id).state,
meta={'percent': percent}
)
if new_percent > percent[0]:
percent[0] = new_percent
task.update_state(
task_id=parent_id,
state=task.AsyncResult(parent_id).state,
meta={'percent': percent[0]}
)
with open(exported_path, 'rb') as exported_disk:
try:
e = MultipartEncoder(
{'data': (exported_name + '.' + disk_format,
exported_disk)}
exported_disk,
'application/octet-stream')}
)
m = MultipartEncoderMonitor(e, update_state)
# Force the read function to read more than 8192 bytes,
# which is a hardcoded value in httplib. This increases
# the upload speed. See:
# https://github.com/requests/toolbelt/issues/75
m._read = m.read
m.read = lambda _: m._read(1024 * 1024)
response = requests.post(
upload_link,
data=m,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment