diff --git a/src/hydra-queue-runner/build-remote.cc b/src/hydra-queue-runner/build-remote.cc index 4fa9da0c..f9a0483a 100644 --- a/src/hydra-queue-runner/build-remote.cc +++ b/src/hydra-queue-runner/build-remote.cc @@ -71,7 +71,7 @@ static void openConnection(const string & sshName, const string & sshKey, static void copyClosureTo(std::shared_ptr store, FdSource & from, FdSink & to, const PathSet & paths, - TokenServer & copyClosureTokenServer, + TokenServer & copyClosureTokenServer, counter & bytesSent, bool useSubstitutes = false) { PathSet closure; @@ -115,6 +115,9 @@ static void copyClosureTo(std::shared_ptr store, printMsg(lvlDebug, format("sending %1% missing paths") % missing.size()); + for (auto & p : missing) + bytesSent += store->queryPathInfo(p).narSize; + writeInt(cmdImportPaths, to); exportPaths(*store, missing, false, to); to.flush(); @@ -125,13 +128,16 @@ static void copyClosureTo(std::shared_ptr store, static void copyClosureFrom(std::shared_ptr store, - FdSource & from, FdSink & to, const PathSet & paths) + FdSource & from, FdSink & to, const PathSet & paths, counter & bytesReceived) { writeInt(cmdExportPaths, to); writeInt(0, to); // == don't sign writeStrings(paths, to); to.flush(); store->importPaths(false, from); + + for (auto & p : paths) + bytesReceived += store->queryPathInfo(p).narSize; } @@ -140,7 +146,8 @@ void buildRemote(std::shared_ptr store, const Path & drvPath, const Derivation & drv, const nix::Path & logDir, unsigned int maxSilentTime, unsigned int buildTimeout, TokenServer & copyClosureTokenServer, RemoteResult & result, - counter & nrStepsBuilding, counter & nrStepsCopyingTo, counter & nrStepsCopyingFrom) + counter & nrStepsBuilding, counter & nrStepsCopyingTo, counter & nrStepsCopyingFrom, + counter & bytesSent, counter & bytesReceived) { string base = baseNameOf(drvPath); result.logFile = logDir + "/" + string(base, 0, 2) + "/" + string(base, 2); @@ -188,10 +195,10 @@ void buildRemote(std::shared_ptr store, } /* Copy the input closure. */ - printMsg(lvlDebug, format("sending closure of ‘%1%’ to ‘%2%’") % drvPath % sshName); - { + if (sshName != "localhost") { + printMsg(lvlDebug, format("sending closure of ‘%1%’ to ‘%2%’") % drvPath % sshName); MaintainCount mc(nrStepsCopyingTo); - copyClosureTo(store, from, to, inputs, copyClosureTokenServer); + copyClosureTo(store, from, to, inputs, copyClosureTokenServer, bytesSent); } autoDelete.cancel(); @@ -220,13 +227,13 @@ void buildRemote(std::shared_ptr store, } /* Copy the output paths. */ - printMsg(lvlDebug, format("copying outputs of ‘%1%’ from ‘%2%’") % drvPath % sshName); - PathSet outputs; - for (auto & output : drv.outputs) - outputs.insert(output.second.path); - { + if (sshName != "localhost") { + printMsg(lvlDebug, format("copying outputs of ‘%1%’ from ‘%2%’") % drvPath % sshName); + PathSet outputs; + for (auto & output : drv.outputs) + outputs.insert(output.second.path); MaintainCount mc(nrStepsCopyingFrom); - copyClosureFrom(store, from, to, outputs); + copyClosureFrom(store, from, to, outputs, bytesReceived); } /* Shut down the connection. */ diff --git a/src/hydra-queue-runner/build-remote.hh b/src/hydra-queue-runner/build-remote.hh index 19625b19..3aa2d919 100644 --- a/src/hydra-queue-runner/build-remote.hh +++ b/src/hydra-queue-runner/build-remote.hh @@ -24,4 +24,5 @@ void buildRemote(std::shared_ptr store, const nix::Path & drvPath, const nix::Derivation & drv, const nix::Path & logDir, unsigned int maxSilentTime, unsigned int buildTimeout, TokenServer & copyClosureTokenServer, RemoteResult & result, - counter & nrStepsBuilding, counter & nrStepsCopyingTo, counter & nrStepsCopyingFrom); + counter & nrStepsBuilding, counter & nrStepsCopyingTo, counter & nrStepsCopyingFrom, + counter & bytesSent, counter & bytesReceived); diff --git a/src/hydra-queue-runner/counter.hh b/src/hydra-queue-runner/counter.hh index 4d6b4163..912cb499 100644 --- a/src/hydra-queue-runner/counter.hh +++ b/src/hydra-queue-runner/counter.hh @@ -2,7 +2,7 @@ #include -typedef std::atomic counter; +typedef std::atomic counter; struct MaintainCount { diff --git a/src/hydra-queue-runner/hydra-queue-runner.cc b/src/hydra-queue-runner/hydra-queue-runner.cc index 9037ee10..79ef3a04 100644 --- a/src/hydra-queue-runner/hydra-queue-runner.cc +++ b/src/hydra-queue-runner/hydra-queue-runner.cc @@ -256,6 +256,8 @@ private: counter totalStepBuildTime{0}; // total build time for steps counter nrQueueWakeups{0}; counter nrDispatcherWakeups{0}; + counter bytesSent{0}; + counter bytesReceived{0}; /* Log compressor work queue. */ Sync> logCompressorQueue; @@ -1158,7 +1160,8 @@ bool State::doBuildStep(std::shared_ptr store, Step::ptr step, /* FIXME: referring builds may have conflicting timeouts. */ buildRemote(store, machine->sshName, machine->sshKey, step->drvPath, step->drv, logDir, build->maxSilentTime, build->buildTimeout, copyClosureTokenServer, - result, nrStepsBuilding, nrStepsCopyingTo, nrStepsCopyingFrom); + result, nrStepsBuilding, nrStepsCopyingTo, nrStepsCopyingFrom, + bytesSent, bytesReceived); } catch (Error & e) { result.status = RemoteResult::rrMiscFailure; result.errorMsg = e.msg(); @@ -1592,6 +1595,8 @@ void State::dumpStatus(Connection & conn, bool log) root.attr("nrStepsBuilding", nrStepsBuilding); root.attr("nrStepsCopyingTo", nrStepsCopyingTo); root.attr("nrStepsCopyingFrom", nrStepsCopyingFrom); + root.attr("bytesSent", bytesSent); + root.attr("bytesReceived", bytesReceived); root.attr("nrBuildsRead", nrBuildsRead); root.attr("nrBuildsDone", nrBuildsDone); root.attr("nrStepsDone", nrStepsDone); diff --git a/src/script/hydra-send-stats b/src/script/hydra-send-stats index b3e28968..9ef2dce1 100755 --- a/src/script/hydra-send-stats +++ b/src/script/hydra-send-stats @@ -44,6 +44,9 @@ sub sendQueueRunnerStats { gauge("hydra.queue.builds.finished", $json->{nrBuildsDone}); gauge("hydra.queue.checks", $json->{nrQueueWakeups}); + + gauge("hydra.queue.bytes_sent", $json->{bytesSent}); + gauge("hydra.queue.bytes_received", $json->{bytesReceived}); } while (1) {