Add a trivial read buffer to flexnbd-proxy.

Since the vast majority (something like 94% on boot) are sequential small
reads, and since network latency is a major factor in determining how fast the
exposed device appears to the client, it makes sense for us to try to minimise
the number of network requests where we safely can.

This patch implements the simplest possible read cache in flexnbd-proxy.  When
it receives a read request, if it's a small request then flexnbd-proxy will
double the length of data requested.  On receiving the data from the upstream
server, flexnbd-proxy will return the first half to the downstream as normal,
and stash the second half in a buffer.  If the very next request is a read, and
the offset and length match those of what we have stored, that second request
will be satisfied from the buffer without going out over the network.

The cache is invalidated by any non-read request, or by a disconnection.
This commit is contained in:
Alex Young
2013-04-29 14:50:42 +01:00
parent 33ee19dc5a
commit 574d44f17f
4 changed files with 141 additions and 16 deletions

View File

@@ -9,6 +9,10 @@
#include "nbdtypes.h"
#include "self_pipe.h"
#ifdef PREFETCH
#include "prefetch.h"
#endif
struct proxier {
/* The flexnbd wrapper this proxier is attached to */
struct flexnbd* flexnbd;
@@ -56,6 +60,10 @@ struct proxier {
/* We transform the raw reply header into here */
struct nbd_reply rsp_hdr;
#ifdef PREFETCH
struct prefetch *prefetch;
#endif
};
struct proxier* proxy_create(