diff --git a/src/main/java/com/aws/greengrass/componentmanager/Unarchiver.java b/src/main/java/com/aws/greengrass/componentmanager/Unarchiver.java index 1bcf433e70..cdfdf44810 100644 --- a/src/main/java/com/aws/greengrass/componentmanager/Unarchiver.java +++ b/src/main/java/com/aws/greengrass/componentmanager/Unarchiver.java @@ -38,6 +38,9 @@ public void unarchive(Unarchive method, File toUnarchive, Path unarchiveInto) th static void unzip(File zipFile, File destDir) throws IOException { try (ZipFile zf = new ZipFile(zipFile)) { Enumeration entries = zf.entries(); + // IOUtils uses a 4K buffer by default. Using 64K will make things go faster. + byte[] buffer = new byte[1024 * 64]; + while (entries.hasMoreElements()) { ZipEntry zipEntry = entries.nextElement(); File newFile = safeNewZipFile(destDir, zipEntry); @@ -52,7 +55,7 @@ static void unzip(File zipFile, File destDir) throws IOException { StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.SYNC); InputStream is = zf.getInputStream(zipEntry)) { - IOUtils.copy(is, fos); + IOUtils.copyLarge(is, fos, buffer); } } } diff --git a/src/main/java/com/aws/greengrass/componentmanager/builtins/ArtifactDownloader.java b/src/main/java/com/aws/greengrass/componentmanager/builtins/ArtifactDownloader.java index e2d4ba4c7a..bc485e5907 100644 --- a/src/main/java/com/aws/greengrass/componentmanager/builtins/ArtifactDownloader.java +++ b/src/main/java/com/aws/greengrass/componentmanager/builtins/ArtifactDownloader.java @@ -40,7 +40,8 @@ public abstract class ArtifactDownloader { protected static final String HTTP_RANGE_HEADER_KEY = "Range"; static final String ARTIFACT_DOWNLOAD_EXCEPTION_FMT = "Failed to download artifact name: '%s' for component %s-%s, reason: "; - private static final int DOWNLOAD_BUFFER_SIZE = 1024; + private static final int DOWNLOAD_BUFFER_SIZE = 1024 * 64; // Download/write with 64KB buffer + private static final int READ_BUFFER_SIZE = 8192; protected final Logger logger; protected final ComponentIdentifier identifier; protected final ComponentArtifact artifact; @@ -64,7 +65,7 @@ protected ArtifactDownloader(ComponentIdentifier identifier, ComponentArtifact a private void updateDigestFromFile(Path filePath, MessageDigest digest) throws IOException { try (InputStream existingArtifact = Files.newInputStream(filePath)) { - byte[] buffer = new byte[DOWNLOAD_BUFFER_SIZE]; + byte[] buffer = new byte[READ_BUFFER_SIZE]; int readBytes = existingArtifact.read(buffer); while (readBytes > -1) { digest.update(buffer, 0, readBytes);