Skip to content

Commit 0275a9b

Browse files
committed
fix: increase file download buffer size (#1395)
1 parent 44d3f33 commit 0275a9b

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/main/java/com/aws/greengrass/componentmanager/Unarchiver.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public void unarchive(Unarchive method, File toUnarchive, Path unarchiveInto) th
3838
static void unzip(File zipFile, File destDir) throws IOException {
3939
try (ZipFile zf = new ZipFile(zipFile)) {
4040
Enumeration<? extends ZipEntry> entries = zf.entries();
41+
// IOUtils uses a 4K buffer by default. Using 64K will make things go faster.
42+
byte[] buffer = new byte[1024 * 64];
43+
4144
while (entries.hasMoreElements()) {
4245
ZipEntry zipEntry = entries.nextElement();
4346
File newFile = safeNewZipFile(destDir, zipEntry);
@@ -52,7 +55,7 @@ static void unzip(File zipFile, File destDir) throws IOException {
5255
StandardOpenOption.TRUNCATE_EXISTING,
5356
StandardOpenOption.SYNC);
5457
InputStream is = zf.getInputStream(zipEntry)) {
55-
IOUtils.copy(is, fos);
58+
IOUtils.copyLarge(is, fos, buffer);
5659
}
5760
}
5861
}

src/main/java/com/aws/greengrass/componentmanager/builtins/ArtifactDownloader.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public abstract class ArtifactDownloader {
4040
protected static final String HTTP_RANGE_HEADER_KEY = "Range";
4141
static final String ARTIFACT_DOWNLOAD_EXCEPTION_FMT =
4242
"Failed to download artifact name: '%s' for component %s-%s, reason: ";
43-
private static final int DOWNLOAD_BUFFER_SIZE = 1024;
43+
private static final int DOWNLOAD_BUFFER_SIZE = 1024 * 64; // Download/write with 64KB buffer
44+
private static final int READ_BUFFER_SIZE = 8192;
4445
protected final Logger logger;
4546
protected final ComponentIdentifier identifier;
4647
protected final ComponentArtifact artifact;
@@ -64,7 +65,7 @@ protected ArtifactDownloader(ComponentIdentifier identifier, ComponentArtifact a
6465

6566
private void updateDigestFromFile(Path filePath, MessageDigest digest) throws IOException {
6667
try (InputStream existingArtifact = Files.newInputStream(filePath)) {
67-
byte[] buffer = new byte[DOWNLOAD_BUFFER_SIZE];
68+
byte[] buffer = new byte[READ_BUFFER_SIZE];
6869
int readBytes = existingArtifact.read(buffer);
6970
while (readBytes > -1) {
7071
digest.update(buffer, 0, readBytes);

0 commit comments

Comments
 (0)