Skip to content

[ws-daemon] Improve download speed of snapshots #13515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/ws-daemon/debug.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ RUN apt update \
apt-transport-https \
python3-crcmod \
gnupg \
aria2 \
&& 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 \
&& curl -sSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - \
&& apt update && apt install -y --no-install-recommends google-cloud-sdk=${CLOUD_SDK_VERSION}-0 \
Expand Down
1 change: 1 addition & 0 deletions components/ws-daemon/leeway.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ RUN apt update \
git git-lfs openssh-client lz4 e2fsprogs coreutils tar strace xfsprogs curl ca-certificates \
apt-transport-https \
python3-crcmod \
aria2 \
&& 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 \
&& curl -sSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - \
&& apt update && apt install -y --no-install-recommends google-cloud-sdk=${CLOUD_SDK_VERSION}-0 \
Expand Down
24 changes: 19 additions & 5 deletions components/ws-daemon/pkg/content/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/json"
"errors"
"io/ioutil"
"net/http"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -390,13 +389,28 @@ func (rs *remoteContentStorage) Download(ctx context.Context, destination string
}

span.SetTag("URL", info.URL)
resp, err := http.Get(info.URL)

tempFile, err := os.CreateTemp("", "remote-content-")
if err != nil {
return true, xerrors.Errorf("cannot create temporal file: %w", err)
}
defer tempFile.Close()
defer os.Remove(tempFile.Name())

args := []string{
"-x16", "-j12",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently, by default, retries are repeated 5 times. This seems a bit much.
https://aria2.github.io/manual/en/html/aria2c.html#cmdoption-m

info.URL,
"-o", tempFile.Name(),
}
cmd := exec.Command("aria2c", args...)
var out []byte
out, err = cmd.CombinedOutput()
if err != nil {
return true, err
log.WithError(err).WithField("out", string(out)).Error("unexpected error downloading file")
return true, xerrors.Errorf("unexpected error downloading file")
}
defer resp.Body.Close()

err = archive.ExtractTarbal(ctx, resp.Body, destination, archive.WithUIDMapping(mappings), archive.WithGIDMapping(mappings))
err = archive.ExtractTarbal(ctx, tempFile, destination, archive.WithUIDMapping(mappings), archive.WithGIDMapping(mappings))
if err != nil {
return true, xerrors.Errorf("tar %s: %s", destination, err.Error())
}
Expand Down