-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http/fetch: Optimise memory consumption
The previous `http/fetch` logic would load into memory the tar file, causing large files to increase the likelihood of concurrent reconciliations to cause OOM. The Fetch func downloads a file, and then hashs it content and if the checksum matches, it then goes ahead and extract its contents. The `resp.Body` is not a `io.SeekReader`, which means that to avoid loading the full size of the file into memory, we need to save it into a temporary file, and then load the file to the subsequent operations. With this approach the memory consumption per operation was reduced from 23mb to 2.1mb: ``` Benchmark_Fetch-16 5 227630480 ns/op 23003358 B/op 19511 allocs/op Benchmark_FetchNew-16 5 227570375 ns/op 2106795 B/op 19504 allocs/op ``` The tar size use was 7mb. Expanding on preventing programming, the download process and subsequent operations are short-circuited after a Max Download Size is reached. With a max limit set to 100 bytes, the error message yielded is: `artifact is 7879239 bytes greater than the max download size of 100 bytes` Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
- Loading branch information
Paulo Gomes
committed
Oct 14, 2022
1 parent
3868547
commit 30a4aca
Showing
2 changed files
with
65 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters