daemon: Buffer data sent to clients by the 'export-path' RPC.

Before that we'd have STDERR_WRITE round trips for very small amounts of
data, ranging from a few bytes for the metadata of nars to the size of
one file being exported.

With this change, something like:

  guix archive --export /gnu/store/5rrsbaghh5ix1vjcicsl60gsxilhjnf2-coreutils-8.25 | dd of=/dev/null

reports a throughput of 35 MB/s instead of 25 MB/s before.

* nix/nix-daemon/nix-daemon.cc (TunnelSink): Inherit from 'BufferedSink'
rather than 'Sink'.  Rename 'operator ()' to 'write'.
(performOp) <wopExportPath>: Add 'sink.flush' call.
This commit is contained in:
Ludovic Courtès 2016-12-01 22:53:37 +01:00
parent 0b72475301
commit 9a8f9f84cc
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 4 additions and 3 deletions

View File

@ -203,11 +203,11 @@ static void stopWork(bool success = true, const string & msg = "", unsigned int
} }
struct TunnelSink : Sink struct TunnelSink : BufferedSink
{ {
Sink & to; Sink & to;
TunnelSink(Sink & to) : to(to) { } TunnelSink(Sink & to) : BufferedSink(64 * 1024), to(to) { }
virtual void operator () (const unsigned char * data, size_t len) virtual void write(const unsigned char * data, size_t len)
{ {
writeInt(STDERR_WRITE, to); writeInt(STDERR_WRITE, to);
writeString(data, len, to); writeString(data, len, to);
@ -433,6 +433,7 @@ static void performOp(bool trusted, unsigned int clientVersion,
startWork(); startWork();
TunnelSink sink(to); TunnelSink sink(to);
store->exportPath(path, sign, sink); store->exportPath(path, sign, sink);
sink.flush();
stopWork(); stopWork();
writeInt(1, to); writeInt(1, to);
break; break;