diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2020-12-02 22:49:39 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2020-12-08 22:30:08 +0100 |
| commit | 5ff521452b9ec2aae9ed8e4bb7bdc250a581f203 (patch) | |
| tree | 550eb2cc894c1c76d565328b75c14d986dcf760e /nix | |
| parent | 711df9ef3c04a0e0d7e844bed4c6b260ea1f65c1 (diff) | |
substitute: Cache and reuse connections while substituting.
That way, when fetching a series of substitutes from the same server(s),
the connection is reused instead of being closed/opened for each
substitutes, which saves on network round trips and TLS handshakes.
* guix/http-client.scm (http-fetch): Add #:keep-alive? and honor it.
* guix/progress.scm (progress-report-port): Add #:close? parameter and
honor it.
* guix/scripts/substitute.scm (at-most): Return the tail as a second
value.
(fetch): Add #:port and #:keep-alive? and honor them.
(%max-cached-connections): New variable.
(open-connection-for-uri/cached, call-with-cached-connection): New
procedures.
(with-cached-connection): New macro.
(process-substitution): Wrap 'fetch' call in 'with-cached-connection'.
Pass #:close? to 'progress-report-port'.
Diffstat (limited to 'nix')
| -rw-r--r-- | nix/libstore/build.cc | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc index 50d300253db..6cfe7aba7e6 100644 --- a/nix/libstore/build.cc +++ b/nix/libstore/build.cc | |||
| @@ -3114,17 +3114,24 @@ void SubstitutionGoal::handleChildOutput(int fd, const string & data) | |||
| 3114 | } | 3114 | } |
| 3115 | 3115 | ||
| 3116 | if (fd == substituter->fromAgent.readSide) { | 3116 | if (fd == substituter->fromAgent.readSide) { |
| 3117 | /* Trim whitespace to the right. */ | 3117 | /* DATA may consist of several lines. Process them one by one. */ |
| 3118 | size_t end = data.find_last_not_of(" \t\n"); | 3118 | string input = data; |
| 3119 | string trimmed = (end != string::npos) ? data.substr(0, end + 1) : data; | 3119 | while (!input.empty()) { |
| 3120 | 3120 | /* Process up to the first newline. */ | |
| 3121 | if (expectedHashStr == "") { | 3121 | size_t end = input.find_first_of("\n"); |
| 3122 | expectedHashStr = trimmed; | 3122 | string trimmed = (end != string::npos) ? input.substr(0, end) : input; |
| 3123 | } else if (status == "") { | 3123 | |
| 3124 | status = trimmed; | 3124 | /* Update the goal's state accordingly. */ |
| 3125 | worker.wakeUp(shared_from_this()); | 3125 | if (expectedHashStr == "") { |
| 3126 | } else { | 3126 | expectedHashStr = trimmed; |
| 3127 | printMsg(lvlError, format("unexpected substituter message '%1%'") % data); | 3127 | } else if (status == "") { |
| 3128 | status = trimmed; | ||
| 3129 | worker.wakeUp(shared_from_this()); | ||
| 3130 | } else { | ||
| 3131 | printMsg(lvlError, format("unexpected substituter message '%1%'") % input); | ||
| 3132 | } | ||
| 3133 | |||
| 3134 | input = (end != string::npos) ? input.substr(end + 1) : ""; | ||
| 3128 | } | 3135 | } |
| 3129 | } | 3136 | } |
| 3130 | } | 3137 | } |
