From d0ac75bb9c711ee2805aaa976827ea9401592193 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Fri, 3 Jul 2020 12:30:00 +0200 Subject: [PATCH] virStream: Use larger buffer for sendAll/recvAll methods There are four methods which receive/send entire stream (sendAll(), recvAll(), sparseSendAll() and sparseRecvAll()). All these have an intermediary buffer which is either filled by incoming stream and passed to a user provided callback to handle the data, or the other way round - user fills it with data they want to send and the buffer is handed over to virStream. But the buffer is incredibly small which leads to smaller packets being sent and thus increased overhead. What we can do is to use the same buffer as their C counterparts do (e.g. virStreamSendAll()) - they all use VIR_NET_MESSAGE_LEGACY_PAYLOAD_MAX long buffer (which is the maximum size of a stream packet we send) - this is almost exactly 256KiB (it's 256KiB - 24B for the header). Signed-off-by: Michal Privoznik Reviewed-by: Pavel Hrdina --- generator.py | 6 ++++++ libvirt-override-virStream.py | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/generator.py b/generator.py index 426f007..f632eb9 100755 --- a/generator.py +++ b/generator.py @@ -1559,6 +1559,12 @@ def buildWrappers(module): pass else: classes.write("class %s(object):\n" % (classname)) + if classname is "virStorageVol": + classes.write(" # The size (in bytes) of buffer used in sendAll(),\n") + classes.write(" # recvAll(), sparseSendAll() and sparseRecvAll()\n") + classes.write(" # methods. This corresponds to the size of payload\n") + classes.write(" # of a stream packet.\n") + classes.write(" streamBufSize = 262120\n\n") if classname in [ "virDomain", "virNetwork", "virInterface", "virStoragePool", "virStorageVol", "virNodeDevice", "virSecret","virStream", "virNWFilter", "virNWFilterBinding" ]: diff --git a/libvirt-override-virStream.py b/libvirt-override-virStream.py index 901c2e6..bc42704 100644 --- a/libvirt-override-virStream.py +++ b/libvirt-override-virStream.py @@ -39,7 +39,7 @@ return os.write(fd, buf) """ while True: - got = self.recv(1024*64) + got = self.recv(virStorageVol.streamBufSize) if got == -2: raise libvirtError("cannot use recvAll with " "nonblocking stream") @@ -74,7 +74,7 @@ """ while True: try: - got = handler(self, 1024*64, opaque) + got = handler(self, virStorageVol.streamBufSize, opaque) except: e = sys.exc_info()[1] try: @@ -189,7 +189,7 @@ # actually allocate the hole """ while True: - want = 64 * 1024 + want = virStorageVol.streamBufSize got = self.recvFlags(want, VIR_STREAM_RECV_STOP_AT_HOLE) if got == -2: raise libvirtError("cannot use sparseRecvAll with " @@ -251,7 +251,7 @@ self.abort() continue - want = 64 * 1024 + want = virStorageVol.streamBufSize if (want > sectionLen): want = sectionLen