Enable multi-conn NBD [for discussion only]
cover Enable multi-conn NBD [for discussion only]
[ Patch series also available here, along with this cover letter and the
script used to generate test results:
https://gitlab.com/rwmjones/qemu/-/commits/2023-nbd-multi-conn-v1 ]
This patch series adds multi-conn support to the NBD block driver in qemu. It is only meant for discussion and testing because it has a number of obvious shortcomings (see "XXX" in commit messages and code). If we decided this was a good idea, we can work on a better patch.
The Network Block Driver (NBD) protocol allows servers to advertise that they are capable of multi-conn. This means they obey certain requirements around how data is cached, allowing multiple connections to be safely opened to the NBD server. For example, a flush or FUA operation on one connection is guaranteed to flush the cache on all connections.
Clients that use multi-conn can achieve better performance. This seems to be down to at least two factors:
- Avoids "head of line blocking" of large requests.
- With NBD over Unix domain sockets, more cores can be used.
qemu-nbd, nbdkit and libnbd have all supported multi-conn for ages, but qemu's built in NBD client does not, which is what this patch fixes.
Below I've produced a few benchmarks.
Note these are mostly concoted to try to test NBD performance and may not make sense in their own terms (eg. qemu's disk image layer has a curl client so you wouldn't need to run one separately). In the real world we use long pipelines of NBD operations where different tools are mixed together to achieve efficient downloads, conversions, disk modifications and sparsification, and they would exercise different aspects of this.
I've also included nbdcopy as a client for comparison in some tests.
All tests were run 4 times, the first result discarded, and the last 3 averaged. If any of the last 3 were > 10% away from the average then the test was stopped.
My summary:
- It works effectively for qemu client & nbdkit server, especially in cases where the server does large, heavyweight requests. This is important for us because virt-v2v uses an nbdkit Python plugin and various other heavyweight plugins (eg. plugins that access remote servers for each request).
- It seems to make little or no difference with qemu + qemu-nbd server. I speculate that's because qemu-nbd doesn't support system threads, so networking is bottlenecked through a single core. Even though there are coroutines handling different sockets, they must all wait in turn to issue send(3) or recv(3) calls on the same core.
- qemu-img unfortunately uses a single thread for all coroutines so it suffers from a similar problem to qemu-nbd. This change would be much more effective if we could distribute coroutines across threads.
- For tests which are highly bottlenecked on disk I/O (eg. the large local file test and null test) multi-conn doesn't make much difference.
- Multi-conn even with only 2 connections can make up for the overhead of range requests, exceeding the performance of wget.
- In the curlremote test, qemu-nbd is especially slow, for unknown reasons.
Integrity test (./multi-conn.pl integrity)
==========================================
nbdkit-sparse-random-plugin
| ^ | nbd+unix | nbd+unix v |
qemu-img convert
Reading from and writing the same data back to nbdkit sparse-random plugin checks that the data written is the same as the data read. This uses two Unix domain sockets, with or without multi-conn. This test is mainly here to check we don't crash or corrupt data with this patch.
server client multi-conn
---------------------------------------------------------------
nbdkit qemu-img [u/s] 9.07s
nbdkit qemu-img 1 9.05s
nbdkit qemu-img 2 9.02s
nbdkit qemu-img 4 8.98s [u/s] = upstream qemu 7.2.0
Curl local server test (./multi-conn.pl curlhttp)
=================================================
Localhost Apache serving a file over http
|
| http
v
nbdkit-curl-plugin or qemu-nbd
|
| nbd+unix
vqemu-img convert or nbdcopy
We download an image from a local web server through nbdkit-curl-plugin or qemu-nbd using the curl block driver, over NBD. The image is copied to /dev/null.
server client multi-conn
---------------------------------------------------------------
qemu-nbd nbdcopy 1 8.88s
qemu-nbd nbdcopy 2 8.64s
qemu-nbd nbdcopy 4 8.37s
qemu-nbd qemu-img [u/s] 6.47s
qemu-nbd qemu-img 1 6.56s
qemu-nbd qemu-img 2 6.63s
qemu-nbd qemu-img 4 6.50s
nbdkit nbdcopy 1 12.15s
nbdkit nbdcopy 2 7.05s (72.36% better)
nbdkit nbdcopy 4 3.54s (242.90% better)
nbdkit qemu-img [u/s] 6.90s
nbdkit qemu-img 1 7.00s
nbdkit qemu-img 2 3.85s (79.15% better)
nbdkit qemu-img 4 3.85s (79.15% better)Curl local file test (./multi-conn.pl curlfile)
===============================================
nbdkit-curl-plugin using file:/// URI
|
| nbd+unix
vqemu-img convert or nbdcopy
We download from a file:/// URI. This test is designed to exercise NBD and some curl internal paths without the overhead from an external server. qemu-nbd doesn't support file:/// URIs so we cannot duplicate the test for qemu as server.
server client multi-conn
---------------------------------------------------------------
nbdkit nbdcopy 1 31.32s
nbdkit nbdcopy 2 20.29s (54.38% better)
nbdkit nbdcopy 4 13.22s (136.91% better)
nbdkit qemu-img [u/s] 31.55s
nbdkit qemu-img 1 31.70s
nbdkit qemu-img 2 21.60s (46.07% better)
nbdkit qemu-img 4 13.88s (127.25% better)Curl remote server test (./multi-conn.pl curlremote)
====================================================
nbdkit-curl-plugin using http://remote/*.qcow2 URI
|
| nbd+unix
vqemu-img convert
We download from a remote qcow2 file to a local raw file, converting between formats during copying.
qemu-nbd using http://remote/*.qcow2 URI
|
| nbd+unix
vqemu-img convert
Similarly, replacing nbdkit with qemu-nbd (treating the remote file as if it is raw, so the conversion is still done by qemu-img).
Additionally we compare downloading the file with wget (note this doesn't include the time for conversion, but that should only be a few seconds).
server client multi-conn
---------------------------------------------------------------
- wget 1 58.19s
nbdkit qemu-img [u/s] 68.29s (17.36% worse)
nbdkit qemu-img 1 67.85s (16.60% worse)
nbdkit qemu-img 2 58.17s
nbdkit qemu-img 4 59.80s
nbdkit qemu-img 6 59.15s
nbdkit qemu-img 8 59.52s qemu-nbd qemu-img [u/s] 202.55s qemu-nbd qemu-img 1 204.61s qemu-nbd qemu-img 2 196.73s qemu-nbd qemu-img 4 179.53s (12.83% better) qemu-nbd qemu-img 6 181.70s (11.48% better) qemu-nbd qemu-img 8 181.05s (11.88% better)
Local file test (./multi-conn.pl file)
======================================
qemu-nbd or nbdkit serving a large local file
|
| nbd+unix
vqemu-img convert or nbdcopy
We download a local file over NBD. The image is copied to /dev/null.
server client multi-conn
---------------------------------------------------------------
qemu-nbd nbdcopy 1 15.50s
qemu-nbd nbdcopy 2 14.36s
qemu-nbd nbdcopy 4 14.32s
qemu-nbd qemu-img [u/s] 10.16s
qemu-nbd qemu-img 1 11.17s (10.01% worse)
qemu-nbd qemu-img 2 10.35s
qemu-nbd qemu-img 4 10.39s
nbdkit nbdcopy 1 9.10s
nbdkit nbdcopy 2 8.25s
nbdkit nbdcopy 4 8.60s
nbdkit qemu-img [u/s] 8.64s
nbdkit qemu-img 1 9.38s
nbdkit qemu-img 2 8.69s
nbdkit qemu-img 4 8.87s Null test (./multi-conn.pl null)
================================
qemu-nbd with null-co driver or nbdkit-null-plugin + noextents filter
|
| nbd+unix
vqemu-img convert or nbdcopy
This is like the local file test above, but without needing a file. Instead all zeroes (fully allocated) are downloaded over NBD.
server client multi-conn
---------------------------------------------------------------
qemu-nbd nbdcopy 1 14.86s
qemu-nbd nbdcopy 2 17.08s (14.90% worse)
qemu-nbd nbdcopy 4 17.89s (20.37% worse)
qemu-nbd qemu-img [u/s] 13.29s
qemu-nbd qemu-img 1 13.31s
qemu-nbd qemu-img 2 13.00s
qemu-nbd qemu-img 4 12.62s
nbdkit nbdcopy 1 15.06s
nbdkit nbdcopy 2 12.21s (23.32% better)
nbdkit nbdcopy 4 11.67s (29.10% better)
nbdkit qemu-img [u/s] 17.13s
nbdkit qemu-img 1 17.11s
nbdkit qemu-img 2 16.82s
nbdkit qemu-img 4 18.81s PATCH 1/4 nbd: Add multi-conn option
Add multi-conn option to the NBD client. This commit just adds the option, it is not functional.
Setting this to a value > 1 permits multiple connections to the NBD server; a typical value might be 4. The default is 1, meaning only a single connection is made. If the NBD server does not advertise that it is safe for multi-conn then this setting is forced to 1.
--- block/nbd.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
block/nbd.c +24 -0
@@ -49,6 +49,7 @@#define EN_OPTSTR ":exportname="#define MAX_NBD_REQUESTS 16 +#define MAX_MULTI_CONN 16#define HANDLE_TO_INDEX (bs, handle) ((handle) ^ (uint64_t)(intptr_t)(bs))#define INDEX_TO_HANDLE (bs, index) ((index) ^ (uint64_t)(intptr_t)(bs))
@@ -98,6 +99,7 @@ typedef struct BDRVNBDState {/* Connection parameters */ uint32_t reconnect_delay;uint32_t open_timeout; +uint32_t multi_conn;SocketAddress *saddr;char *export;char *tlscredsid;
@@ -1803,6 +1805,15 @@ static QemuOptsList nbd_runtime_opts = {"attempts until successful or until @open-timeout seconds " "have elapsed. Default 0", }, + { + .name = "multi-conn", + .type = QEMU_OPT_NUMBER, + .help ="If > 1 permit up to this number of connections to the " +"server. The server must also advertise multi-conn " +"support. If <= 1, only a single connection is made " +"to the server even if the server advertises multi-conn. " + "Default 1", + }, { /* end of list */ } }, };
@@ -1858,6 +1869,10 @@ static int nbd_process_options(BlockDriverState *bs, QDict *options, s->reconnect_delay =qemu_opt_get_number (opts,"reconnect-delay" ,0 ); s->open_timeout =qemu_opt_get_number (opts,"open-timeout" ,0 ); + s->multi_conn =qemu_opt_get_number (opts,"multi-conn" ,1 ); +if (s->multi_conn >MAX_MULTI_CONN ) { + s->multi_conn =MAX_MULTI_CONN ; + } ret =0 ;
@@ -1912,6 +1927,15 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,nbd_client_connection_enable_retry (s->conn); +/* +* We set s->multi_conn in nbd_process_options above, but now that +* we have connected if the server doesn't advertise that it is +* safe for multi-conn, force it to 1. +*/ +if (!(s->info.flags &NBD_FLAG_CAN_MULTI_CONN )) { + s->multi_conn =1 ; + } +return 0 ; fail:
Signature · 1 line
2.39.2
Re: [PATCH nbd 1/4] nbd: Add multi-conn option
Quoted 2 lines · Richard W.M. Jones
Add multi-conn option to the NBD client. This commit just adds the option, it is not functional.
Maybe add the phrase "until later in this patch series" ?
Quoted 48 lines
Setting this to a value > 1 permits multiple connections to the NBD server; a typical value might be 4. The default is 1, meaning only a single connection is made. If the NBD server does not advertise that it is safe for multi-conn then this setting is forced to 1.
Signed-off-by Richard W.M. Jones <[email protected]>--- block/nbd.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)block/nbd.c +11
-0@@ -49,6 +49,7 @@#define EN_OPTSTR ":exportname="#define MAX_NBD_REQUESTS 16 +#define MAX_MULTI_CONN 16#define HANDLE_TO_INDEX (bs, handle) ((handle) ^ (uint64_t)(intptr_t)(bs))#define INDEX_TO_HANDLE (bs, index) ((index) ^ (uint64_t)(intptr_t)(bs))@@ -98,6 +99,7 @@ typedef struct BDRVNBDState {/* Connection parameters */ uint32_t reconnect_delay;uint32_t open_timeout; +uint32_t multi_conn;SocketAddress *saddr;char *export;char *tlscredsid;@@ -1803,6 +1805,15 @@ static QemuOptsList nbd_runtime_opts = {"attempts until successful or until @open-timeout seconds " "have elapsed. Default 0", }, + { + .name = "multi-conn", + .type = QEMU_OPT_NUMBER, + .help ="If > 1 permit up to this number of connections to the " +"server. The server must also advertise multi-conn " +"support. If <= 1, only a single connection is made " +"to the server even if the server advertises multi-conn. " + "Default 1", + }, { /* end of list */ } }, };
block/nbd.c static int nbd_process_options(BlockDriverState *bs, QDict *options, · line 1875
Quoted 7 lines
block/nbd.c +4
-0@@ -1858,6 +1869,10 @@ static int nbd_process_options(BlockDriverState *bs, QDict *options, s->reconnect_delay =qemu_opt_get_number (opts,"reconnect-delay" ,0 ); s->open_timeout =qemu_opt_get_number (opts,"open-timeout" ,0 ); + s->multi_conn =qemu_opt_get_number (opts,"multi-conn" ,1 ); +if (s->multi_conn >MAX_MULTI_CONN ) { + s->multi_conn =MAX_MULTI_CONN ; + }
This silently ignores out-of-range values (negative, greater than 16) and treats 0 as a synonym for 1. The latter I'm okay with, the former I wonder if we should instead raise an error that the user is requesting something we can't honor, instead of silently bounding it.
block/nbd.c static int nbd_open(BlockDriverState *bs, QDict *options, int flags, · line 1932
Quoted 10 lines
block/nbd.c +3
-0ret =0 ;@@ -1912,6 +1927,15 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,nbd_client_connection_enable_retry (s->conn); +/* +* We set s->multi_conn in nbd_process_options above, but now that +* we have connected if the server doesn't advertise that it is
s/connected/connected,/
block/nbd.c static int nbd_open(BlockDriverState *bs, QDict *options, int flags, · line 1939
Quoted 7 lines
block/nbd.c +6
-0+* safe for multi-conn, force it to 1. +*/ +if (!(s->info.flags &NBD_FLAG_CAN_MULTI_CONN )) { + s->multi_conn =1 ; + } +return 0 ;
Is there an intended QAPI counterpart for this command? We'll need that if it is to be set during the command line of qemu-storage-daemon.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [PATCH nbd 1/4] nbd: Add multi-conn option
Quoted 9 lines · Eric Blake
block/nbd.c static int nbd_open(BlockDriverState *bs, QDict *options, int flags, · line 1939
Quoted 7 lines · Richard W.M. Jones
block/nbd.c +6
-0+* safe for multi-conn, force it to 1. +*/ +if (!(s->info.flags &NBD_FLAG_CAN_MULTI_CONN )) { + s->multi_conn =1 ; + } +return 0 ;
Quoted 3 lines
Is there an intended QAPI counterpart for this command? We'll need that if it is to be set during the command line of qemu-storage-daemon.
Does it just need to be added to qapi/block-core.json?
It's a shame we can't add the API in one place and have everything generated from there. Like some kind of 'generator' ...
Rich.
Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
PATCH 2/4 nbd: Split out block device state from underlying NBD connections
In reply to Richard W.M. JonesTo implement multi-conn, we will put multiple underlying NBD connections (ie. NBDClientConnection) inside the NBD block device handle (BDRVNBDState). This requires first breaking the one-to-one relationship between NBDClientConnection and BDRVNBDState.
To do this a new structure (NBDConnState) is implemented. NBDConnState takes all the per-connection state out of the block driver struct. BDRVNBDState now contains a conns[] array of pointers to NBDConnState, one for each underlying multi-conn connection.
After this change there is still a one-to-one relationship because we only ever use the zeroth slot in the conns[] array. Thus this does not implement multi-conn yet.
--- block/coroutines.h | 5 +- block/nbd.c | 674 ++++++++++++++++++++++++--------------------- 2 files changed, 358 insertions(+), 321 deletions(-)
block/coroutines.h +3 -2
@@ -62,7 +62,7 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); int coroutine_fn -nbd_co_do_establish_connection (BlockDriverState *bs,bool blocking, +nbd_co_do_establish_connection (BlockDriverState *bs,void *cs,bool blocking,Error **errp);
@@ -86,6 +86,7 @@ bdrv_common_block_status_above(BlockDriverState *bs, BlockDriverState **file, int *depth); int co_wrapper_mixed -nbd_do_establish_connection (BlockDriverState *bs,bool blocking,Error **errp); +nbd_do_establish_connection (BlockDriverState *bs,void *cs,bool blocking, +Error **errp);#endif /* BLOCK_COROUTINES_H */
block/nbd.c +355 -319
1,471 lines not on this page · raw message
Signature · 1 line
2.39.2
Re: [PATCH nbd 2/4] nbd: Split out block device state from underlying NBD connections
Quoted 25 lines · Richard W.M. Jones
To implement multi-conn, we will put multiple underlying NBD connections (ie. NBDClientConnection) inside the NBD block device handle (BDRVNBDState). This requires first breaking the one-to-one relationship between NBDClientConnection and BDRVNBDState.
To do this a new structure (NBDConnState) is implemented. NBDConnState takes all the per-connection state out of the block driver struct. BDRVNBDState now contains a conns[] array of pointers to NBDConnState, one for each underlying multi-conn connection.
After this change there is still a one-to-one relationship because we only ever use the zeroth slot in the conns[] array. Thus this does not implement multi-conn yet.
Signed-off-by Richard W.M. Jones <[email protected]>--- block/coroutines.h | 5 +- block/nbd.c | 674 ++++++++++++++++++++++++--------------------- 2 files changed, 358 insertions(+), 321 deletions(-)block/coroutines.h +0
-0
block/coroutines.h int coroutine_fn GRAPH_RDLOCK · line 66
Quoted 6 lines
block/coroutines.h +1
-1@@ -62,7 +62,7 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); int coroutine_fn -nbd_co_do_establish_connection (BlockDriverState *bs,bool blocking, +nbd_co_do_establish_connection (BlockDriverState *bs,void *cs,bool blocking,Error **errp);
I guess the void* here is because you couldn't find a way to expose the new type through the coroutine wrapper generator?
block/coroutines.h bdrv_common_block_status_above(BlockDriverState *bs, · line 91
Quoted 10 lines
block/coroutines.h +2
-1@@ -86,6 +86,7 @@ bdrv_common_block_status_above(BlockDriverState *bs, BlockDriverState **file, int *depth); int co_wrapper_mixed -nbd_do_establish_connection (BlockDriverState *bs,bool blocking,Error **errp); +nbd_do_establish_connection (BlockDriverState *bs,void *cs,bool blocking, +Error **errp);
same here
block/nbd.c line 55
Quoted 13 lines
block/coroutines.h +0
-0#endif /* BLOCK_COROUTINES_H */ block/nbd.c +2
-2@@ -51,8 +51,8 @@#define MAX_NBD_REQUESTS 16#define MAX_MULTI_CONN 16 -#define HANDLE_TO_INDEX (bs, handle) ((handle) ^ (uint64_t)(intptr_t)(bs)) -#define INDEX_TO_HANDLE (bs, index) ((index) ^ (uint64_t)(intptr_t)(bs)) +#define HANDLE_TO_INDEX (cs, handle) ((handle) ^ (uint64_t)(intptr_t)(cs)) +#define INDEX_TO_HANDLE (cs, index) ((index) ^ (uint64_t)(intptr_t)(cs))
Independently of your patches, these macros are odd. I think we could just as easily define
#define HANDLE_TO_INDEX(XX, handle) ((handle) - 1) #define INDEX_TO_HANDLE(XX, index) ((index) + 1)
and then refactor to drop the unused parameter, since we never really depend on it (I audited the code when you first asked me about it on IRC, and we do a bounds check that whatever the server returns lies within our expected index of 0-15 before dereferencing any memory with it, so we are NOT relying on the server passing us a pointer that we depend on).
Overall, your patch is mostly mechanical and looks nice to me.
block/nbd.c static bool coroutine_fn nbd_recv_coroutine_wake_one(NBDClientRequest *req) · line 294
Quoted 13 lines
block/nbd.c +0
-0/* * Update @bs with information learned during a completed negotiation process. * Return failure if the server's advertised options are incompatible with the * client's needs.
+ *
+ * Note that we are only called for the first connection (s->conns[0])
+ * because multi-conn assumes that all other connections are alike.
+ * We don't check that assumption but probably should (XXX). */block/nbd.c +2
-1-static int nbd_handle_updated_info (BlockDriverState *bs,Error **errp) +static int nbd_handle_updated_info (BlockDriverState *bs, +NBDConnState *cs,Error **errp)
But as you pointed out in your cover letter, we'll probably want to address the XXX comments like this one prior to actually committing the series. We really should be making sure that the secondary clients see the same server parameters as the first one, regardless of whether they are open in parallel (once multi-conn is enabled) or in series after a reopen (which is what we currently try to support).
block/nbd.c static int nbd_handle_updated_info(BlockDriverState *bs, Error **errp) · line 339
Quoted 9 lines
block/nbd.c +2
-0@@ -318,129 +332,132 @@ static int nbd_handle_updated_info(BlockDriverState *bs, Error **errp) } int coroutine_fn nbd_co_do_establish_connection(BlockDriverState *bs, +void *csvp,bool blocking,Error **errp) {BDRVNBDState *s = (BDRVNBDState *)bs->opaque; +NBDConnState *cs = csvp;
Is there a way to get the new type passed through the coroutine generator without the use of void*?
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
PATCH 3/4 nbd: Open multiple NBD connections if multi-conn is set
In reply to Richard W.M. JonesIf the user opts in to multi-conn and the server advertises it, open multiple NBD connections. They are opened with the same parameters as the initial connection. Similarly on the close path the connections are closed.
However only the zeroth connection is used, so this commit does not actually enable multi-conn capabilities.
(XXX) The strategy here is very naive. Firstly if you were going to open them, you'd probably want to open them in parallel. Secondly it would make sense to delay opening until multiple parallel requests are seen (perhaps above some threshold), so that simple or shortlived NBD operations do not require multiple connections to be made.
--- block/nbd.c | 128 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 90 insertions(+), 38 deletions(-)
block/nbd.c +90 -38
@@ -124,18 +124,23 @@ static void nbd_yank(void *opaque);static void nbd_clear_bdrvstate (BlockDriverState *bs) {BDRVNBDState *s = (BDRVNBDState *)bs->opaque; +size_t i; -nbd_client_connection_release (s->conns[0 ]->conn); - s->conns[0 ]->conn =NULL ; +for (i =0 ; i <MAX_MULTI_CONN ; ++i) { +if (s->conns[i]) { +nbd_client_connection_release (s->conns[i]->conn); + s->conns[i]->conn =NULL ; + +/* Must not leave timers behind that would access freed data */ +assert (!s->conns[i]->reconnect_delay_timer); +assert (!s->conns[i]->open_timer); + +g_free (s->conns[i]); + } + }yank_unregister_instance (BLOCKDEV_YANK_INSTANCE (bs->node_name)); -/* Must not leave timers behind that would access freed data */ -assert (!s->conns[0 ]->reconnect_delay_timer); -assert (!s->conns[0 ]->open_timer); - -g_free (s->conns[0 ]); -object_unref (OBJECT (s->tlscreds));qapi_free_SocketAddress (s->saddr); s->saddr =NULL ;
@@ -1905,43 +1910,39 @@ static int nbd_process_options(BlockDriverState *bs, QDict *options,return ret; } -static int nbd_open (BlockDriverState *bs,QDict *options,int flags, -Error **errp) +static NBDConnState *init_conn_state (BDRVNBDState *s) { +NBDConnState *cs; + + cs =g_new0 (NBDConnState,1 ); + cs->s = s; +qemu_mutex_init (&cs->requests_lock); +qemu_co_queue_init (&cs->free_sema); +qemu_co_mutex_init (&cs->send_mutex); +qemu_co_mutex_init (&cs->receive_mutex); + +return cs; +} + +static int conn_state_connect (BlockDriverState *bs,NBDConnState *cs, +Error **errp) +{ +BDRVNBDState *s = cs->s;int ret; -BDRVNBDState *s = (BDRVNBDState *)bs->opaque; - s->bs = bs; - - s->conns[0 ] =g_new0 (NBDConnState,1 ); - s->conns[0 ]->s = s; -qemu_mutex_init (&s->conns[0 ]->requests_lock); -qemu_co_queue_init (&s->conns[0 ]->free_sema); -qemu_co_mutex_init (&s->conns[0 ]->send_mutex); -qemu_co_mutex_init (&s->conns[0 ]->receive_mutex); - -if (!yank_register_instance (BLOCKDEV_YANK_INSTANCE (bs->node_name), errp)) { -return -EEXIST ; - } - - ret =nbd_process_options (bs, options, errp); -if (ret <0 ) { - goto fail; - } - - s->conns[0 ]->conn = + cs->conn =nbd_client_connection_new (s->saddr, true, s->export, s->x_dirty_bitmap, s->tlscreds, s->tlshostname);if (s->open_timeout) { -nbd_client_connection_enable_retry (s->conns[0 ]->conn); -open_timer_init (s->conns[0 ],qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) + +nbd_client_connection_enable_retry (cs->conn); +open_timer_init (cs,qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) + s->open_timeout *NANOSECONDS_PER_SECOND ); } - s->conns[0 ]->state =NBD_CLIENT_CONNECTING_WAIT ; - ret =nbd_do_establish_connection (bs, s->conns[0 ], true, errp); + cs->state =NBD_CLIENT_CONNECTING_WAIT ; + ret =nbd_do_establish_connection (bs, cs, true, errp);if (ret <0 ) { goto fail; }
@@ -1951,9 +1952,44 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,* Delete it, because we do not want it to be around when this node * is drained or closed. */ -open_timer_del (s->conns[0 ]); +open_timer_del (cs); -nbd_client_connection_enable_retry (s->conns[0 ]->conn); +nbd_client_connection_enable_retry (cs->conn); + +return 0 ; + +fail: +open_timer_del (cs); +return ret; +} + +static int nbd_open (BlockDriverState *bs,QDict *options,int flags, +Error **errp) +{ +int ret; +BDRVNBDState *s = (BDRVNBDState *)bs->opaque; +size_t i; + + s->bs = bs; + +if (!yank_register_instance (BLOCKDEV_YANK_INSTANCE (bs->node_name), errp)) { +return -EEXIST ; + } + + ret =nbd_process_options (bs, options, errp); +if (ret <0 ) { + goto fail; + } + +/* +* Open the first NBD connection. +*/ + s->conns[0 ] =init_conn_state (s); + + ret =conn_state_connect (bs, s->conns[0 ], errp); +if (ret <0 ) { + goto fail; + }/* * We set s->multi_conn in nbd_process_options above, but now that
@@ -1964,10 +2000,21 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags, s->multi_conn =1 ; } +/* +* Open remaining multi-conn NBD connections (if any). +*/ +for (i =1 ; i < s->multi_conn; ++i) { + s->conns[i] =init_conn_state (s); + + ret =conn_state_connect (bs, s->conns[i], errp); +if (ret <0 ) { + goto fail; + } + } +return 0 ; fail: -open_timer_del (s->conns[0 ]);nbd_clear_bdrvstate (bs);return ret; }
@@ -2015,8 +2062,13 @@ static void nbd_refresh_limits(BlockDriverState *bs, Error **errp)static void nbd_close (BlockDriverState *bs) {BDRVNBDState *s = (BDRVNBDState *)bs->opaque; +size_t i; -nbd_client_close (s->conns[0 ]); +for (i =0 ; i <MAX_MULTI_CONN ; ++i) { +if (s->conns[i]) { +nbd_client_close (s->conns[i]); + } + }nbd_clear_bdrvstate (bs); }
Signature · 1 line
2.39.2
PATCH 4/4 nbd: Enable multi-conn using round-robin
In reply to Richard W.M. JonesEnable NBD multi-conn by spreading operations across multiple connections.
(XXX) This uses a naive round-robin approach which could be improved. For example we could look at how many requests are in flight and assign operations to the connections with fewest. Or we could try to estimate (based on size of requests outstanding) the load on each connection. But this implementation doesn't do any of that.
--- block/nbd.c | 67 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 18 deletions(-)
block/nbd.c +49 -18
@@ -1232,6 +1232,26 @@ static int coroutine_fn nbd_co_request(NBDConnState *cs, NBDRequest *request,return ret ? ret : request_ret; } +/* +* If multi-conn, choose a connection for this operation. +*/ +static NBDConnState *choose_connection (BDRVNBDState *s) +{ +static size_t next; +size_t i; + +if (s->multi_conn <=1 ) { +return s->conns[0 ]; + } + +/* XXX Stupid simple round robin. */ + i =qatomic_fetch_inc (&next); + i %= s->multi_conn; + +assert (s->conns[i] !=NULL ); +return s->conns[i]; +} + static int coroutine_fn nbd_client_co_preadv(BlockDriverState *bs, int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags)
@@ -1244,7 +1264,7 @@ static int coroutine_fn nbd_client_co_preadv(BlockDriverState *bs, int64_t offse .from = offset, .len = bytes, }; -NBDConnState *const cs = s->conns[0 ]; +NBDConnState *const cs =choose_connection (s);assert (bytes <=NBD_MAX_BUFFER_SIZE );
@@ -1301,7 +1321,7 @@ static int coroutine_fn nbd_client_co_pwritev(BlockDriverState *bs, int64_t offs .from = offset, .len = bytes, }; -NBDConnState *const cs = s->conns[0 ]; +NBDConnState *const cs =choose_connection (s);assert (!(cs->info.flags &NBD_FLAG_READ_ONLY ));if (flags &BDRV_REQ_FUA ) {
@@ -1326,7 +1346,7 @@ static int coroutine_fn nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_ .from = offset, .len = bytes, /* .len is uint32_t actually */ }; -NBDConnState *const cs = s->conns[0 ]; +NBDConnState *const cs =choose_connection (s);assert (bytes <=UINT32_MAX );/* rely on max_pwrite_zeroes */
@@ -1357,7 +1377,13 @@ static int coroutine_fn nbd_client_co_flush(BlockDriverState *bs) {BDRVNBDState *s = (BDRVNBDState *)bs->opaque;NBDRequest request = { .type =NBD_CMD_FLUSH }; -NBDConnState *const cs = s->conns[0 ]; + +/* +* Multi-conn (if used) guarantees that flushing on any connection +* flushes caches on all connections, so we can perform this +* operation on any. +*/ +NBDConnState *const cs =choose_connection (s);if (!(cs->info.flags &NBD_FLAG_SEND_FLUSH )) {return 0 ;
@@ -1378,7 +1404,7 @@ static int coroutine_fn nbd_client_co_pdiscard(BlockDriverState *bs, int64_t off .from = offset, .len = bytes, /* len is uint32_t */ }; -NBDConnState *const cs = s->conns[0 ]; +NBDConnState *const cs =choose_connection (s);assert (bytes <=UINT32_MAX );/* rely on max_pdiscard */
@@ -1398,7 +1424,7 @@ static int coroutine_fn nbd_client_co_block_status(NBDExtent extent = {0 };BDRVNBDState *s = (BDRVNBDState *)bs->opaque;Error *local_err =NULL ; -NBDConnState *const cs = s->conns[0 ]; +NBDConnState *const cs =choose_connection (s);NBDRequest request = { .type =NBD_CMD_BLOCK_STATUS ,
@@ -2027,7 +2053,7 @@ static int coroutine_fn nbd_co_flush(BlockDriverState *bs)static void nbd_refresh_limits (BlockDriverState *bs,Error **errp) {BDRVNBDState *s = (BDRVNBDState *)bs->opaque; -NBDConnState *const cs = s->conns[0 ]; +NBDConnState *const cs =choose_connection (s);uint32_t min = cs->info.min_block;uint32_t max =MIN_NON_ZERO (NBD_MAX_BUFFER_SIZE , cs->info.max_block);
@@ -2085,7 +2111,7 @@ static int coroutine_fn nbd_co_truncate(BlockDriverState *bs, int64_t offset, BdrvRequestFlags flags, Error **errp) { BDRVNBDState *s = bs->opaque; -NBDConnState *const cs = s->conns[0 ]; +NBDConnState *const cs =choose_connection (s);if (offset != cs->info.size && exact) {error_setg (errp,"Cannot resize NBD nodes" );
@@ -2168,24 +2194,29 @@ static const char *const nbd_strong_runtime_opts[] = {static void nbd_cancel_in_flight (BlockDriverState *bs) {BDRVNBDState *s = (BDRVNBDState *)bs->opaque; -NBDConnState *const cs = s->conns[0 ]; +size_t i; +NBDConnState *cs; -reconnect_delay_timer_del (cs); +for (i =0 ; i <MAX_MULTI_CONN ; ++i) { + cs = s->conns[i]; -qemu_mutex_lock (&cs->requests_lock); -if (cs->state ==NBD_CLIENT_CONNECTING_WAIT ) { - cs->state =NBD_CLIENT_CONNECTING_NOWAIT ; +reconnect_delay_timer_del (cs); + +qemu_mutex_lock (&cs->requests_lock); +if (cs->state ==NBD_CLIENT_CONNECTING_WAIT ) { + cs->state =NBD_CLIENT_CONNECTING_NOWAIT ; + } +qemu_mutex_unlock (&cs->requests_lock); + +nbd_co_establish_connection_cancel (cs->conn); } -qemu_mutex_unlock (&cs->requests_lock); - -nbd_co_establish_connection_cancel (cs->conn); }static void nbd_attach_aio_context (BlockDriverState *bs,AioContext *new_context) {BDRVNBDState *s = bs->opaque; -NBDConnState *const cs = s->conns[0 ]; +NBDConnState *const cs =choose_connection (s);/* The open_timer is used only during nbd_open() */ assert (!cs->open_timer);
@@ -2209,7 +2240,7 @@ static void nbd_attach_aio_context(BlockDriverState *bs,static void nbd_detach_aio_context (BlockDriverState *bs) {BDRVNBDState *s = bs->opaque; -NBDConnState *const cs = s->conns[0 ]; +NBDConnState *const cs =choose_connection (s);assert (!cs->open_timer);assert (!cs->reconnect_delay_timer);
Signature · 1 line
2.39.2
Quoted 9 lines · Richard W.M. Jones
[ Patch series also available here, along with this cover letter and the
script used to generate test results:https://gitlab.com/rwmjones/qemu/-/commits/2023-nbd-multi-conn-v1 ]This patch series adds multi-conn support to the NBD block driver in qemu. It is only meant for discussion and testing because it has a number of obvious shortcomings (see "XXX" in commit messages and code). If we decided this was a good idea, we can work on a better patch.
I looked through the results and the code, and I think that's of course a good idea!
We still need smarter integration with reconnect logic.
At least, we shouldn't make several open_timer instances..
Currently, on open() we have open-timeout. That's just a limit for the whole nbd_open() - we can do several connection attempts during this time.
Seems we should proceed with success, if we succeeded with at least one connection. Postponing additional connections to be established after open() seems good too[*].
Next, we have reconnect-delay. When connection is lost nbd-client tries to reconnect with no limit in attempts, but after reconnect-delay seconds of reconnection all in-flight requests that are waiting for connection are just failed.
When we have several connections, and one is broken, I think we shouldn't wait, but instead retry the requests on other working connections. This way we don't need several reconnect_delay_timer objects: we need only one, when all connections are lost.
Reestablishing additional connections better to do in background, not blocking in-flight requests. And that's the same as postponing additional connections after open() should work ([*]).
Signature · 2 lines
Best regards, Vladimir
Quoted 9 lines · Richard W.M. Jones
[ Patch series also available here, along with this cover letter and the
script used to generate test results:
https://gitlab.com/rwmjones/qemu/-/commits/2023-nbd-multi-conn-v1 ]This patch series adds multi-conn support to the NBD block driver in qemu. It is only meant for discussion and testing because it has a number of obvious shortcomings (see "XXX" in commit messages and code). If we decided this was a good idea, we can work on a better patch.
Overall, I'm in favor of this. A longer term project might be to have qemu's NBD client code call into libnbd instead of reimplementing things itself, at which point having libnbd manage multi-conn under the hood would be awesome, but as that's a much bigger effort, a shorter-term task of having qemu itself handle parallel sockets seems worthwhile.
Quoted 7 lines
- It works effectively for qemu client & nbdkit server, especially in cases where the server does large, heavyweight requests. This is important for us because virt-v2v uses an nbdkit Python plugin and various other heavyweight plugins (eg. plugins that access remote servers for each request).
Quoted 6 lines
- It seems to make little or no difference with qemu + qemu-nbd server. I speculate that's because qemu-nbd doesn't support system threads, so networking is bottlenecked through a single core. Even though there are coroutines handling different sockets, they must all wait in turn to issue send(3) or recv(3) calls on the same core.
Is the current work to teach qemu to do multi-queue (that is, spread the I/O load for a single block device across multiple cores) going to help here? I haven't been following the multi-queue efforts closely enough to know if the approach used in this series will play nicely, or need even further overhaul.
Quoted 5 lines
- qemu-img unfortunately uses a single thread for all coroutines so it suffers from a similar problem to qemu-nbd. This change would be much more effective if we could distribute coroutines across threads.
qemu-img uses the same client code as qemu-nbd; any multi-queue improvements that can spread the send()/recv() load of multiple sockets across multiple cores will benefit both programs simultaneously.
Quoted 4 lines
- For tests which are highly bottlenecked on disk I/O (eg. the large local file test and null test) multi-conn doesn't make much difference.
As long as it isn't adding to much penalty, that's okay. If the saturation is truly at the point of how fast disk requests can be served, it doesn't matter if we can queue up more of those requests in parallel across multiple NBD sockets.
Quoted 3 lines
- Multi-conn even with only 2 connections can make up for the overhead of range requests, exceeding the performance of wget.
That alone is a rather cool result, and an argument in favor of further developing this.
Quoted 20 lines
- In the curlremote test, qemu-nbd is especially slow, for unknown reasons.
Integrity test (./multi-conn.pl integrity)
==========================================nbdkit-sparse-random-plugin
| ^ | nbd+unix | nbd+unix v |qemu-img convert
Reading from and writing the same data back to nbdkit sparse-random plugin checks that the data written is the same as the data read. This uses two Unix domain sockets, with or without multi-conn. This test is mainly here to check we don't crash or corrupt data with this patch.
Quoted 8 lines
server client multi-conn
---------------------------------------------------------------nbdkit qemu-img [u/s] 9.07s nbdkit qemu-img 1 9.05s nbdkit qemu-img 2 9.02s nbdkit qemu-img 4 8.98s[u/s] = upstream qemu 7.2.0
How many of these timing numbers can be repeated with TLS in the mix?
Quoted 19 lines
Curl local server test (./multi-conn.pl curlhttp)
=================================================Localhost Apache serving a file over http
| | http v nbdkit-curl-plugin or qemu-nbd | | nbd+unix vqemu-img convert or nbdcopy
We download an image from a local web server through nbdkit-curl-plugin or qemu-nbd using the curl block driver, over NBD. The image is copied to
/dev/null.
Quoted 6 lines
server client multi-conn
---------------------------------------------------------------qemu-nbd nbdcopy 1 8.88s qemu-nbd nbdcopy 2 8.64s qemu-nbd nbdcopy 4 8.37sqemu-nbd qemu-img [u/s] 6.47s
Do we have any good feel for why qemu-img is faster than nbdcopy in the baseline? But improving that is orthogonal to this series.
Quoted 4 lines
qemu-nbd qemu-img 1 6.56s
qemu-nbd qemu-img 2 6.63s
qemu-nbd qemu-img 4 6.50s
nbdkit nbdcopy 1 12.15s I'm assuming this is nbdkit with your recent in-progress patches to have the curl plugin serve parallel requests. But another place where we can investigate why nbdkit is not as performant as qemu-nbd at utilizing curl.
Quoted 2 lines
nbdkit nbdcopy 2 7.05s (72.36% better)
nbdkit nbdcopy 4 3.54s (242.90% better)That one is impressive!
Quoted 2 lines
nbdkit qemu-img [u/s] 6.90s
nbdkit qemu-img 1 7.00s Minimal penalty for adding the code but not utilizing it...
Quoted 2 lines
nbdkit qemu-img 2 3.85s (79.15% better)
nbdkit qemu-img 4 3.85s (79.15% better)...and definitely shows its worth.
Quoted 16 lines
Curl local file test (./multi-conn.pl curlfile)
===============================================nbdkit-curl-plugin using file:/// URI
| | nbd+unix vqemu-img convert or nbdcopy
We download from a file:/// URI. This test is designed to exercise NBD and some curl internal paths without the overhead from an external server. qemu-nbd doesn't support file:/// URIs so we cannot duplicate the test for qemu as server.
Quoted 6 lines
server client multi-conn
---------------------------------------------------------------nbdkit nbdcopy 1 31.32s nbdkit nbdcopy 2 20.29s (54.38% better) nbdkit nbdcopy 4 13.22s (136.91% better) nbdkit qemu-img [u/s] 31.55s
Here, the baseline is already comparable; both nbdcopy and qemu-img are parsing the image off nbdkit in about the same amount of time.
Quoted 1 line
nbdkit qemu-img 1 31.70s
And again, minimal penalty for having the new code in place but not exploiting it.
Quoted 2 lines
nbdkit qemu-img 2 21.60s (46.07% better)
nbdkit qemu-img 4 13.88s (127.25% better)Plus an obvious benefit when the parallel sockets matter.
Quoted 27 lines
Curl remote server test (./multi-conn.pl curlremote)
====================================================nbdkit-curl-plugin using http://remote/*.qcow2 URI
| | nbd+unix vqemu-img convert
We download from a remote qcow2 file to a local raw file, converting between formats during copying.
qemu-nbd using http://remote/*.qcow2 URI
| | nbd+unix vqemu-img convert
Similarly, replacing nbdkit with qemu-nbd (treating the remote file as if it is raw, so the conversion is still done by qemu-img).
Additionally we compare downloading the file with wget (note this doesn't include the time for conversion, but that should only be a few seconds).
Quoted 6 lines
server client multi-conn
---------------------------------------------------------------- wget 1 58.19s nbdkit qemu-img [u/s] 68.29s (17.36% worse) nbdkit qemu-img 1 67.85s (16.60% worse) nbdkit qemu-img 2 58.17s
Comparable to wget on paper, but a win in practice (since the wget step also has to add a post-download qemu-img local conversion step).
Quoted 11 lines
nbdkit qemu-img 4 59.80s nbdkit qemu-img 6 59.15s nbdkit qemu-img 8 59.52sqemu-nbd qemu-img [u/s] 202.55s qemu-nbd qemu-img 1 204.61s qemu-nbd qemu-img 2 196.73s qemu-nbd qemu-img 4 179.53s (12.83% better) qemu-nbd qemu-img 6 181.70s (11.48% better) qemu-nbd qemu-img 8 181.05s (11.88% better)
Less dramatic results here, but still nothing horrible.
Quoted 10 lines
Local file test (./multi-conn.pl file)
======================================qemu-nbd or nbdkit serving a large local file
| | nbd+unix vqemu-img convert or nbdcopy
Quoted 8 lines
We download a local file over NBD. The image is copied to
/dev/null.server client multi-conn
---------------------------------------------------------------qemu-nbd nbdcopy 1 15.50s qemu-nbd nbdcopy 2 14.36s qemu-nbd nbdcopy 4 14.32sqemu-nbd qemu-img [u/s] 10.16s
Once again, we're seeing qemu-img baseline faster than nbdcopy as client. But throwing more sockets at either client does improve performance, except for...
Quoted 1 line
qemu-nbd qemu-img 1 11.17s (10.01% worse)
...this one looks bad. Is it a case of this series adding more mutex work (qemu-img is making parallel requests; each request then contends for the mutex only to learn that it will be using the same NBD connection)? And your comments about smarter round-robin schemes mean there may still be room to avoid this much of a penalty.
Quoted 3 lines
qemu-nbd qemu-img 2 10.35s
qemu-nbd qemu-img 4 10.39snbdkit nbdcopy 1 9.10s
This one in interesting: nbdkit as server performs better than qemu-nbd.
Quoted 11 lines
nbdkit nbdcopy 2 8.25s nbdkit nbdcopy 4 8.60s nbdkit qemu-img [u/s] 8.64s nbdkit qemu-img 1 9.38s nbdkit qemu-img 2 8.69s nbdkit qemu-img 4 8.87sNull test (./multi-conn.pl null)
================================
Quoted 8 lines
qemu-nbd with null-co driver or nbdkit-null-plugin + noextents filter
| | nbd+unix vqemu-img convert or nbdcopy
This is like the local file test above, but without needing a file. Instead all zeroes (fully allocated) are downloaded over NBD.
And I'm sure that if you allowed block status to show the holes, the performance would be a lot faster, but that would be testing something completely differently ;)
Quoted 6 lines
server client multi-conn
---------------------------------------------------------------qemu-nbd nbdcopy 1 14.86s qemu-nbd nbdcopy 2 17.08s (14.90% worse) qemu-nbd nbdcopy 4 17.89s (20.37% worse)
Oh, that's weird. I wonder if qemu's null-co driver has some poor mutex behavior when being hit by parallel I/O. Seems like investigating that can be separate from this series, though.
Quoted 1 line
qemu-nbd qemu-img [u/s] 13.29s
And another point where qemu-img is faster than nbdcopy as a single-client baseline.
Quoted 10 lines
qemu-nbd qemu-img 1 13.31s
qemu-nbd qemu-img 2 13.00s
qemu-nbd qemu-img 4 12.62s
nbdkit nbdcopy 1 15.06s
nbdkit nbdcopy 2 12.21s (23.32% better)
nbdkit nbdcopy 4 11.67s (29.10% better)
nbdkit qemu-img [u/s] 17.13s
nbdkit qemu-img 1 17.11s
nbdkit qemu-img 2 16.82s
nbdkit qemu-img 4 18.81s Overall, I'm looking forward to seeing this go in (8.1 material; we're too close to 8.0)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Quoted 1 line · Eric Blake
How many of these timing numbers can be repeated with TLS in the mix?
While I have been playing with TLS and kTLS recently, it's not something that is especially important to v2v since all NBD traffic goes over Unix domain sockets only (ie. it's used as kind of interprocess communication).
I could certainly provide benchmarks, although as I'm going on holiday shortly it may be a little while.
Quoted 24 lines
Quoted 17 lines
Curl local server test (./multi-conn.pl curlhttp)
=================================================Localhost Apache serving a file over http
| | http v nbdkit-curl-plugin or qemu-nbd | | nbd+unix vqemu-img convert or nbdcopy
We download an image from a local web server through nbdkit-curl-plugin or qemu-nbd using the curl block driver, over NBD. The image is copied to
/dev/null.Quoted 6 lines
server client multi-conn
---------------------------------------------------------------qemu-nbd nbdcopy 1 8.88s qemu-nbd nbdcopy 2 8.64s qemu-nbd nbdcopy 4 8.37sqemu-nbd qemu-img [u/s] 6.47s
Quoted 2 lines
Do we have any good feel for why qemu-img is faster than nbdcopy in the baseline? But improving that is orthogonal to this series.
I do not, but we have in the past found that results can be very sensitive to request size. By default (and also in all of these tests) nbdcopy is using a request size of 256K, and qemu-img is using a request size of 2M.
Quoted 13 lines
Quoted 4 lines
qemu-nbd qemu-img 1 6.56s qemu-nbd qemu-img 2 6.63s qemu-nbd qemu-img 4 6.50s nbdkit nbdcopy 1 12.15sI'm assuming this is nbdkit with your recent in-progress patches to have the curl plugin serve parallel requests. But another place where we can investigate why nbdkit is not as performant as qemu-nbd at utilizing curl.
Quoted 2 lines
nbdkit nbdcopy 2 7.05s (72.36% better) nbdkit nbdcopy 4 3.54s (242.90% better)
Quoted 6 lines
That one is impressive!
Quoted 2 lines
nbdkit qemu-img [u/s] 6.90s nbdkit qemu-img 1 7.00sMinimal penalty for adding the code but not utilizing it...
[u/s] and qemu-img with multi-conn:1 ought to be identical actually. After all, the only difference should be the restructuring of the code to add the intermediate NBDConnState struct In this case it's probably just measurement error.
Quoted 75 lines
Quoted 2 lines
nbdkit qemu-img 2 3.85s (79.15% better) nbdkit qemu-img 4 3.85s (79.15% better)...and definitely shows its worth.
Quoted 16 lines
Curl local file test (./multi-conn.pl curlfile)
===============================================nbdkit-curl-plugin using file:/// URI
| | nbd+unix vqemu-img convert or nbdcopy
We download from a file:/// URI. This test is designed to exercise NBD and some curl internal paths without the overhead from an external server. qemu-nbd doesn't support file:/// URIs so we cannot duplicate the test for qemu as server.
Quoted 6 lines
server client multi-conn
---------------------------------------------------------------nbdkit nbdcopy 1 31.32s nbdkit nbdcopy 2 20.29s (54.38% better) nbdkit nbdcopy 4 13.22s (136.91% better) nbdkit qemu-img [u/s] 31.55sHere, the baseline is already comparable; both nbdcopy and qemu-img are parsing the image off nbdkit in about the same amount of time.
Quoted 1 line
nbdkit qemu-img 1 31.70sAnd again, minimal penalty for having the new code in place but not exploiting it.
Quoted 2 lines
nbdkit qemu-img 2 21.60s (46.07% better) nbdkit qemu-img 4 13.88s (127.25% better)Plus an obvious benefit when the parallel sockets matter.
Quoted 27 lines
Curl remote server test (./multi-conn.pl curlremote)
====================================================nbdkit-curl-plugin using http://remote/*.qcow2 URI
| | nbd+unix vqemu-img convert
We download from a remote qcow2 file to a local raw file, converting between formats during copying.
qemu-nbd using http://remote/*.qcow2 URI
| | nbd+unix vqemu-img convert
Similarly, replacing nbdkit with qemu-nbd (treating the remote file as if it is raw, so the conversion is still done by qemu-img).
Additionally we compare downloading the file with wget (note this doesn't include the time for conversion, but that should only be a few seconds).
Quoted 6 lines
server client multi-conn
---------------------------------------------------------------- wget 1 58.19s nbdkit qemu-img [u/s] 68.29s (17.36% worse) nbdkit qemu-img 1 67.85s (16.60% worse) nbdkit qemu-img 2 58.17s
Quoted 2 lines
Comparable to wget on paper, but a win in practice (since the wget step also has to add a post-download qemu-img local conversion step).
Yes, correct. Best case that would be another ~ 2-3 seconds on this machine.
Quoted 37 lines
Quoted 11 lines
nbdkit qemu-img 4 59.80s nbdkit qemu-img 6 59.15s nbdkit qemu-img 8 59.52sqemu-nbd qemu-img [u/s] 202.55s qemu-nbd qemu-img 1 204.61s qemu-nbd qemu-img 2 196.73s qemu-nbd qemu-img 4 179.53s (12.83% better) qemu-nbd qemu-img 6 181.70s (11.48% better) qemu-nbd qemu-img 8 181.05s (11.88% better)Less dramatic results here, but still nothing horrible.
Quoted 10 lines
Local file test (./multi-conn.pl file)
======================================qemu-nbd or nbdkit serving a large local file
| | nbd+unix vqemu-img convert or nbdcopy
Quoted 8 lines
We download a local file over NBD. The image is copied to
/dev/null.server client multi-conn
---------------------------------------------------------------qemu-nbd nbdcopy 1 15.50s qemu-nbd nbdcopy 2 14.36s qemu-nbd nbdcopy 4 14.32sqemu-nbd qemu-img [u/s] 10.16s
Once again, we're seeing qemu-img baseline faster than nbdcopy as client. But throwing more sockets at either client does improve performance, except for...
Quoted 7 lines
Quoted 1 line
qemu-nbd qemu-img 1 11.17s (10.01% worse)
...this one looks bad. Is it a case of this series adding more mutex work (qemu-img is making parallel requests; each request then contends for the mutex only to learn that it will be using the same NBD connection)? And your comments about smarter round-robin schemes mean there may still be room to avoid this much of a penalty.
This was reproducible and I don't have a good explanation for it. As far as I know just adding the NBDConnState struct should not add any overhead. The only locking is the call to choose_connection, and that's just the access to an atomic variable which I can't imagine could cause such a difference.
Quoted 38 lines
Quoted 3 lines
qemu-nbd qemu-img 2 10.35s
qemu-nbd qemu-img 4 10.39snbdkit nbdcopy 1 9.10sThis one in interesting: nbdkit as server performs better than qemu-nbd.
Quoted 11 lines
nbdkit nbdcopy 2 8.25s nbdkit nbdcopy 4 8.60s nbdkit qemu-img [u/s] 8.64s nbdkit qemu-img 1 9.38s nbdkit qemu-img 2 8.69s nbdkit qemu-img 4 8.87sNull test (./multi-conn.pl null)
================================Quoted 8 lines
qemu-nbd with null-co driver or nbdkit-null-plugin + noextents filter
| | nbd+unix vqemu-img convert or nbdcopy
This is like the local file test above, but without needing a file. Instead all zeroes (fully allocated) are downloaded over NBD.
And I'm sure that if you allowed block status to show the holes, the performance would be a lot faster, but that would be testing something completely differently ;)
Quoted 6 lines
server client multi-conn
---------------------------------------------------------------qemu-nbd nbdcopy 1 14.86s qemu-nbd nbdcopy 2 17.08s (14.90% worse) qemu-nbd nbdcopy 4 17.89s (20.37% worse)
Quoted 3 lines
Oh, that's weird. I wonder if qemu's null-co driver has some poor mutex behavior when being hit by parallel I/O. Seems like investigating that can be separate from this series, though.
Yes, I noticed in other tests that null-co has some odd behaviour, but I couldn't understand it from looking at the code which seems very simple. It does a memset, maybe that is expensive because it uses newly allocated buffers every time or something like that?
Quoted 16 lines
Quoted 1 line
qemu-nbd qemu-img [u/s] 13.29s
And another point where qemu-img is faster than nbdcopy as a single-client baseline.
Quoted 10 lines
qemu-nbd qemu-img 1 13.31s qemu-nbd qemu-img 2 13.00s qemu-nbd qemu-img 4 12.62s nbdkit nbdcopy 1 15.06s nbdkit nbdcopy 2 12.21s (23.32% better) nbdkit nbdcopy 4 11.67s (29.10% better) nbdkit qemu-img [u/s] 17.13s nbdkit qemu-img 1 17.11s nbdkit qemu-img 2 16.82s nbdkit qemu-img 4 18.81s
Quoted 2 lines
Overall, I'm looking forward to seeing this go in (8.1 material; we're too close to 8.0)
Rich.
Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org