Skip to content

Commit 9c8fad1

Browse files
committed
[ws-daemon] Improve download speed of snapshots
1 parent df77406 commit 9c8fad1

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

components/ws-daemon/debug.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ RUN apt update \
2727
apt-transport-https \
2828
python3-crcmod \
2929
gnupg \
30+
aria22 \
3031
&& echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list \
3132
&& curl -sSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - \
3233
&& apt update && apt install -y --no-install-recommends google-cloud-sdk=${CLOUD_SDK_VERSION}-0 \

components/ws-daemon/leeway.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ RUN apt update \
2626
git git-lfs openssh-client lz4 e2fsprogs coreutils tar strace xfsprogs curl ca-certificates \
2727
apt-transport-https \
2828
python3-crcmod \
29+
aria22 \
2930
&& echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list \
3031
&& curl -sSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - \
3132
&& apt update && apt install -y --no-install-recommends google-cloud-sdk=${CLOUD_SDK_VERSION}-0 \

components/ws-daemon/pkg/content/initializer.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"encoding/json"
1111
"errors"
1212
"io/ioutil"
13-
"net/http"
1413
"os"
1514
"os/exec"
1615
"path/filepath"
@@ -390,13 +389,28 @@ func (rs *remoteContentStorage) Download(ctx context.Context, destination string
390389
}
391390

392391
span.SetTag("URL", info.URL)
393-
resp, err := http.Get(info.URL)
392+
393+
tempFile, err := os.CreateTemp("", "remote-content-")
394+
if err != nil {
395+
return true, xerrors.Errorf("cannot create temporal file: %w", err)
396+
}
397+
defer tempFile.Close()
398+
defer os.Remove(tempFile.Name())
399+
400+
args := []string{
401+
"-x16", "-j12",
402+
info.URL,
403+
"-o", tempFile.Name(),
404+
}
405+
cmd := exec.Command("aria2c", args...)
406+
var out []byte
407+
out, err = cmd.CombinedOutput()
394408
if err != nil {
395-
return true, err
409+
log.WithError(err).WithField("out", string(out)).Error("unexpected error downloading file")
410+
return true, xerrors.Errorf("unexpected error downloading file")
396411
}
397-
defer resp.Body.Close()
398412

399-
err = archive.ExtractTarbal(ctx, resp.Body, destination, archive.WithUIDMapping(mappings), archive.WithGIDMapping(mappings))
413+
err = archive.ExtractTarbal(ctx, tempFile, destination, archive.WithUIDMapping(mappings), archive.WithGIDMapping(mappings))
400414
if err != nil {
401415
return true, xerrors.Errorf("tar %s: %s", destination, err.Error())
402416
}

0 commit comments

Comments
 (0)