I'm trying to replicate the features of the qemu curl plugin in
nbdkit's curl plugin, in order that we can use nbdkit in virt-v2v to
access VMware servers. I've implemented everything else so far [not
posted yet] except for readahead.
To my surprise actually, qemu's curl driver implements readahead
itself. I thought it was a curl feature. I'm not completely clear
_how_ it works in qemu, but it seems like it's maintaining an array of
outstanding AIO requests, searching those first to see if one contains
the read data, and extending the length of other read requests so
there is a higher chance they will prefetch data:
https://github.com/qemu/qemu/blob/230ce19814ecc6bff8edac3b5b86e7c82f422c6...
https://github.com/qemu/qemu/blob/230ce19814ecc6bff8edac3b5b86e7c82f422c6...
Oh and BTW in my testing we found that readahead was very important
for performance of virt-v2v! This is because vCenter is really slow
and we issue requests to vCenter serially, so avoiding long round
trips is vital. (Of course vCenter performance sucks and anyone with
any sense uses ‘virt-v2v -it ssh|vddk’, but vCenter unfortunately
remains the only zero-config way to convert guests with a pure free
software solution.)
So how could we implement something like this in nbdkit? I don't
particularly like the idea of extending the curl plugin so it's doing
caching as well (essentially what qemu does IIUC).
We already have a cache filter so I have two ideas:
(1) Modify nbdkit-cache-filter to add a readahead parameter.
This would work something like as follows: If the cache does not map
any data following a pread request (up to the size of the readahead),
then the pread request to the underlying plugin is extended, and the
data added to the cache (but not returned upwards). Prefetched data
is read from cache as usual.
Unfortunately this could slow down all pread requests, since there's
no easy way in a filter to return early with the requested data.
Background threads? We've avoided this in filters so far. One
problem is that they don't have access to the handle or "nextops"
structure.
(2) Add a new readahead filter which extents all pread requests
(unconditionally) but throws away the prefetched data.
You would need to use this in conjunction with a cache filter or other
caching layer. As Eric points out there is no way to enforce correct
layering here, we'd just have to trust the user.
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/