pojntfx / go-nbd

Pure Go NBD server and client library.
Apache License 2.0
353 stars 18 forks source link

Add support for NBD_FLAG_CAN_MULTI_CONN to the server #4

Closed pPanda-beta closed 1 year ago

pPanda-beta commented 1 year ago

At this point the current nbd-server supports only 1 connection per client. For sequential reads kernel wont be able to create multiple connections and read in parallel.

It would be best if we support this at least for readonly servers, for the sake of performance.

Doubt: World is moving into a single socket based model and multiplexing, e.g. HTTP2, why can't we follow that?

Because NBD protocol do not have any alternative multiplexing mechanism. Some underlying storage layers only perform well when consumed in parallel. e.g. GCS, S3 or any blobstorage. For a large sequential IO, best performance can only be achieved if we start reading in parallel.

pojntfx commented 1 year ago

That would be very interesting! From an implementation perspective, I def. see this as being possible, and its a minimal enough extension for it to keep being close to the baseline implementation while offering performance improvements IMHO. Currently, we just read messages from a single connection, switch on their option, forward them to the backend and stop when the client sends the disconnect, so switching to this could probably be done by finding a way to track a client and then just spawning this loop for each new connection I suppose.

pPanda-beta commented 1 year ago

I tried experimenting by just making one line change here and it worked.

-                   TransmissionFlags: 0,
+                   TransmissionFlags: 0b1000_0001_0000_0000,

First high bit represents NBD_FLAG_HAS_FLAGS and 8th one represents NBD_FLAG_CAN_MULTI_CONN

We can define those constants and make the flag part of Options struct.

pojntfx commented 1 year ago

That's neat, I'll def. take a look. Having parallelism could def. speed things up - and the backends already need to handle locking themselves since its possible to connect more than one client, so this should be possible in a backwards-compatible way, too.

pojntfx commented 1 year ago

Released in https://github.com/pojntfx/go-nbd/releases/tag/v0.3.0