<div dir="ltr"><div dir="ltr">On Fri, Jan 22, 2021 at 5:42 PM Richard W.M. Jones <<a href="mailto:rjones@redhat.com">rjones@redhat.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Fri, Jan 22, 2021 at 05:11:46PM +0200, Nir Soffer wrote:<br>
> Based on the tests I did with the imageio plugin this should<br>
> give significant performance improvement.<br>
> <a href="https://github.com/libguestfs/nbdkit/commit/" rel="noreferrer" target="_blank">https://github.com/libguestfs/nbdkit/commit/</a><br>
> 78bbe95f754dd404fcbabac57940b1c0e4e49c4d<br>
> <br>
> I think the changes are basically:<br>
> <br>
> api version: 2<br>
> thread model: parallel<br>
> <br>
> open:<br>
> - Create a connection pool instead of a single connection. <br>
> - Based on experience wit imageio client, 4 connections are a good default<br>
> <br>
> pwrite/zero/pread:<br>
> - Get connection from the pool, blocking for available instance<br>
> - Return the connection to the pool when done or after failure<br>
> <br>
> flush:<br>
> - send a flush request for all connections in the pool<br>
>    (each http connection have a separate nbd connection inside imageio)<br>
> <br>
> close:<br>
> - close all connections in pool<br>
> <br>
> What do you think?<br>
<br>
Yes.<br>
<br>
The tricky thing will be getting locking right.  With the PARALLEL<br>
model you can have multiple parallel calls into the plugin even with<br>
the same handle.  The Python GIL is still active, so Python code<br>
fragments won't be running at the same time, but it's still possible<br>
for one thread to block in the middle of a plugin method (eg.<br>
HTTPConnection blocking on a read), releasing the GIL, allowing<br>
another plugin method call to start with the same handle.<br></blockquote><div><br></div><div>The handle is a dict, which is thread safe, and we never modify </div><div>the handle during a transfer.</div><div><br></div><div>The only change we do is set h["failed"] to True, which is thread</div><div>safe and idempotent.</div><div><br></div><div>To get a connection from the handle, we will use a queue which is</div><div>thread safe. Connection are removed from the queue during use,</div><div>so only one thread can access a connection. Returning connection</div><div>to the queue is also thread safe.</div><div><br></div><div>So I think no extra locking is needed.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Rich.<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>
libguestfs lets you edit virtual machines.  Supports shell scripting,<br>
bindings from many languages.  <a href="http://libguestfs.org" rel="noreferrer" target="_blank">http://libguestfs.org</a><br>
<br>
</blockquote></div></div>