Skip to content

Commit

Permalink
v2v: rhv-upload: Disable Nagle algorithm
Browse files Browse the repository at this point in the history
When sending a PUT request, the http header may be sent in the first
packet when calling con.endheaders(). When we send the first chunk, the
kernel may delay the send because the header packet was not acked yet.

We have seen PUT requests delayed by 40 milliseconds on the server side
during virt-v2v upload to ovirt. Here is example log from current RHEL
virt-v2v version, uploading to RHV 4.2.3:

2018-06-12 17:04:01,750 INFO    (Thread-2) [images] Writing 52736 bytes
at offset 0 flush False to /path/to/image for ticket
374bec27-930d-4097-8e41-e4bc23324eb0

2018-06-12 17:04:01,790 INFO    (Thread-2) [directio] Operation stats:
<Clock(total=0.04, read=0.04, write=0.00)>

The server spent 40 milliseconds reading 52736 bytes form
rhv_upload_plugin running on the same host.

This issue was fixed in python 3.5 by using the TCP_NO_DELAY option
after connecting[1]. I backported this change from python 3.5.

I tested the same change using imageio example upload script. With this
change and with optimized PATCH requests, upload time of 4G sparse image
was reduced from 7 minutes to 1 minute.

See this ovirt patch for more details:
https://gerrit.ovirt.org/#/c/92276/

This change is needed only for python 2.

[1] https://bugs.python.org/issue23302
  • Loading branch information
nirs authored and rwmjones committed Jun 18, 2018
1 parent d38ea31 commit 5bee82d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion v2v/rhv-upload-plugin.py
Expand Up @@ -20,11 +20,12 @@
from __builtin__ import open as builtin_open
import json
import logging
import socket
import ssl
import sys
import time

from httplib import HTTPSConnection
from httplib import HTTPSConnection as _HTTPSConnection
from urlparse import urlparse

import ovirtsdk4 as sdk
Expand All @@ -50,6 +51,18 @@ def byteify(input):
return input
params = None

class HTTPSConnection(_HTTPSConnection):
def connect(self):
"""
Using TCP_NO_DELAY avoids delays when sending small payload, such as
ovirt PATCH requests.
This issue was fixed in python 3.5, see:
https://bugs.python.org/issue23302
"""
_HTTPSConnection.connect(self)
self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

def config(key, value):
global params

Expand Down

0 comments on commit 5bee82d

Please sign in to comment.