<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Thu, Jun 14, 2018 at 10:19 PM Richard W.M. Jones <<a href="mailto:rjones@redhat.com" target="_blank">rjones@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Thu, Jun 14, 2018 at 09:16:01PM +0300, Nir Soffer wrote:<br>
> When sending request with small or no payload, it is simpler and<br>
> possibly more efficient to use the high level HTTPSConnection.request(),<br>
> instead of the lower level APIs.<br>
> <br>
> The only reason to use the lower level APIs is to avoid copying the<br>
> payload, or on python 2, to use a bigger buffer size when streaming a<br>
> file-like object.<br>
<br>
Change seems quite straightforward.  I'll have to test this out on my<br>
own oVirt system first before I can properly verify it.<br></blockquote><div><br></div></div><div dir="ltr"><div class="gmail_quote"><div>I tested the same change with imageio example upload script, and </div><div>it *doubled* the throughput.</div><div><br></div><div>See <a href="https://gerrit.ovirt.org/#/c/92275/">https://gerrit.ovirt.org/#/c/92275/</a></div><div><br></div></div></div><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks, Rich.<br>
<br>
>  v2v/rhv-upload-plugin.py | 35 ++++++++++++++++-------------------<br>
>  1 file changed, 16 insertions(+), 19 deletions(-)<br>
> <br>
> diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py<br>
> index ed99cc7a9..3fad865f6 100644<br>
> --- a/v2v/rhv-upload-plugin.py<br>
> +++ b/v2v/rhv-upload-plugin.py<br>
> @@ -263,12 +263,12 @@ def pread(h, count, offset):<br>
>      transfer = h['transfer']<br>
>      transfer_service = h['transfer_service']<br>
>  <br>
> -    http.putrequest("GET", h['path'])<br>
> +    headers = {"Range", "bytes=%d-%d" % (offset, offset+count-1)}<br>
>      # Authorization is only needed for old imageio.<br>
>      if h['needs_auth']:<br>
> -        http.putheader("Authorization", transfer.signed_ticket)<br>
> -    http.putheader("Range", "bytes=%d-%d" % (offset, offset+count-1))<br>
> -    http.endheaders()<br>
> +        headers["Authorization"] = transfer.signed_ticket<br>
> +<br>
> +    http.request("GET", h['path'], headers=headers)<br>
>  <br>
>      r = http.getresponse()<br>
>      # 206 = HTTP Partial Content.<br>
> @@ -319,11 +319,10 @@ def zero(h, count, offset, may_trim):<br>
>                        'size': count,<br>
>                        'flush': False}).encode()<br>
>  <br>
> -    http.putrequest("PATCH", h['path'])<br>
> -    http.putheader("Content-Type", "application/json")<br>
> -    http.putheader("Content-Length", len(buf))<br>
> -    http.endheaders()<br>
> -    http.send(buf)<br>
> +    headers = {"Content-Type": "application/json",<br>
> +               "Content-Length", str(len(buf))}<br>
> +<br>
> +    http.request("PATCH", h['path'], body=buf, headers=headers)<br>
>  <br>
>      r = http.getresponse()<br>
>      if r.status != 200:<br>
> @@ -368,11 +367,10 @@ def trim(h, count, offset):<br>
>                        'size': count,<br>
>                        'flush': False}).encode()<br>
>  <br>
> -    http.putrequest("PATCH", h['path'])<br>
> -    http.putheader("Content-Type", "application/json")<br>
> -    http.putheader("Content-Length", len(buf))<br>
> -    http.endheaders()<br>
> -    http.send(buf)<br>
> +    headers = {"Content-Type": "application/json",<br>
> +               "Content-Length", str(len(buf))}<br>
> +<br>
> +    http.request("PATCH", h['path'], body=buf, headers=headers)<br>
>  <br>
>      r = http.getresponse()<br>
>      if r.status != 200:<br>
> @@ -387,11 +385,10 @@ def flush(h):<br>
>      # Construct the JSON request for flushing.<br>
>      buf = json.dumps({'op': "flush"}).encode()<br>
>  <br>
> -    http.putrequest("PATCH", h['path'])<br>
> -    http.putheader("Content-Type", "application/json")<br>
> -    http.putheader("Content-Length", len(buf))<br>
> -    http.endheaders()<br>
> -    http.send(buf)<br>
> +    headers = {"Content-Type": "application/json",<br>
> +               "Content-Length", str(len(buf))}<br>
> +<br>
> +    http.request("PATCH", h['path'], body=buf, headers=headers)<br>
>  <br>
>      r = http.getresponse()<br>
>      if r.status != 200:<br>
> -- <br>
> 2.17.1<br>
<br>
-- <br>
Richard Jones, Virtualization Group, Red Hat <a href="http://people.redhat.com/~rjones" rel="noreferrer" target="_blank">http://people.redhat.com/~rjones</a><br>
Read my programming and virtualization blog: <a href="http://rwmj.wordpress.com" rel="noreferrer" target="_blank">http://rwmj.wordpress.com</a><br>
virt-top is 'top' for virtual machines.  Tiny program with many<br>
powerful monitoring features, net stats, disk stats, logging, etc.<br>
<a href="http://people.redhat.com/~rjones/virt-top" rel="noreferrer" target="_blank">http://people.redhat.com/~rjones/virt-top</a><br>
</blockquote></div></div></div>