Despite using multi-threading for S3 uploads in Spring, why is the execution time still slow?

I am currently modifying a Spring application to implement an API for uploading multiple images to S3 at once using @Async for asynchronous processing with multi-threading to achieve faster responses. However, after implementing this, the response time is not as fast as expected.

The logs indicate that multi-threading is functioning correctly, but the actual S3 upload times are longer, and the overall response is not faster during testing. I understand that S3 can handle concurrent requests, so I am unsure where the issue might be. Could you help identify the problem? Thank you!

Here is the code I wrote and the log output:

@Operation(summary = "다중 이미지 업로드 - 비동기", description = "새로운 이미지를 다중으로 업로드합니다.")
    @PostMapping(value = "/images/async", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public ApiResponse<List<String>> uploadMultipleImagesAsync(
            @Parameter(description = "업로드할 이미지 파일들", required = true, schema = @Schema(type = "array", format = "binary"))
            @RequestPart("files") List<MultipartFile> files,
            @Parameter(description = "이미지들이 업로드될 도메인 이름(notice or kindergarten)", required = true)
            @RequestParam("domainName") String domainName) {
        List<String> urls = imageService.uploadImagesAsync(files, domainName);
        return ApiResponse.onSuccess(urls);
    }
@Service
@RequiredArgsConstructor
public class ImageService {
    private final S3Service s3Service;

    // 여러 개의 이미지 업로드 - 비동기
    public List<String> uploadImagesAsync(List<MultipartFile> multipartFiles, String domainName) {
        List<CompletableFuture<String>> futures = new ArrayList<>();

        for (MultipartFile file : multipartFiles) {
            futures.add(s3Service.uploadImageAsync(file, domainName));
        }

        List<String> urls = new ArrayList<>();

        futures.forEach(future ->
                urls.add(future.join())
        );

        return urls;
    }

}

// 이미지 업로드 - 비동기
    @Async("imageUploadExecutor")
    public CompletableFuture<String> uploadImageAsync(MultipartFile file, String domainName) {
        CompletableFuture<String> future = new CompletableFuture<>();
        String fileName = createFileName(file.getOriginalFilename());
        String folder = IMAGES_FOLDER + domainName + "/";

        long startTime = System.currentTimeMillis();

        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setContentLength(file.getSize());
        metadata.setContentType(file.getContentType());

        future.complete(uploadToS3(file, folder, fileName));

        long endTime = System.currentTimeMillis();
        log.info("{} - 실행 시간: {}", Thread.currentThread().getName(), endTime - startTime);

        return future;
    }

// S3에 업로드 공통 로직
    private String uploadToS3(MultipartFile file, String folder, String fileName) {
        ObjectMetadata objectMetadata = new ObjectMetadata();
        objectMetadata.setContentLength(file.getSize());
        objectMetadata.setContentType(file.getContentType());

        try (InputStream inputStream = file.getInputStream()) {
            amazonS3Client.putObject(new PutObjectRequest(bucket, folder + fileName, inputStream,
                objectMetadata).withCannedAcl(CannedAccessControlList.PublicRead));
        } catch (IOException e) {
            throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR,
                "파일 업로드에 실패했습니다.");
        }
        return amazonS3Client.getUrl(bucket, folder + fileName).toString();
    }

@Bean(name = "imageUploadExecutor")
    public Executor imageUploadExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();

        executor.setThreadGroupName("imageUploadExecutor");
        executor.setCorePoolSize(10);
        executor.setMaxPoolSize(15);
        executor.setQueueCapacity(100);
        executor.initialize();

        return executor;
    }

async log
synch log

In practice, I expected to see a noticeable improvement in response time with asynchronous processing, but there was no significant difference compared to synchronous processing.

I also tried adjusting the thread pool settings and tested it on a VM rather than locally, but I didn’t observe any substantial effect. I really want to understand the cause.

New contributor

user24348330 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Despite using multi-threading for S3 uploads in Spring, why is the execution time still slow?

I am currently modifying a Spring application to implement an API for uploading multiple images to S3 at once using @Async for asynchronous processing with multi-threading to achieve faster responses. However, after implementing this, the response time is not as fast as expected.

The logs indicate that multi-threading is functioning correctly, but the actual S3 upload times are longer, and the overall response is not faster during testing. I understand that S3 can handle concurrent requests, so I am unsure where the issue might be. Could you help identify the problem? Thank you!

Here is the code I wrote and the log output:

@Operation(summary = "다중 이미지 업로드 - 비동기", description = "새로운 이미지를 다중으로 업로드합니다.")
    @PostMapping(value = "/images/async", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public ApiResponse<List<String>> uploadMultipleImagesAsync(
            @Parameter(description = "업로드할 이미지 파일들", required = true, schema = @Schema(type = "array", format = "binary"))
            @RequestPart("files") List<MultipartFile> files,
            @Parameter(description = "이미지들이 업로드될 도메인 이름(notice or kindergarten)", required = true)
            @RequestParam("domainName") String domainName) {
        List<String> urls = imageService.uploadImagesAsync(files, domainName);
        return ApiResponse.onSuccess(urls);
    }
@Service
@RequiredArgsConstructor
public class ImageService {
    private final S3Service s3Service;

    // 여러 개의 이미지 업로드 - 비동기
    public List<String> uploadImagesAsync(List<MultipartFile> multipartFiles, String domainName) {
        List<CompletableFuture<String>> futures = new ArrayList<>();

        for (MultipartFile file : multipartFiles) {
            futures.add(s3Service.uploadImageAsync(file, domainName));
        }

        List<String> urls = new ArrayList<>();

        futures.forEach(future ->
                urls.add(future.join())
        );

        return urls;
    }

}

// 이미지 업로드 - 비동기
    @Async("imageUploadExecutor")
    public CompletableFuture<String> uploadImageAsync(MultipartFile file, String domainName) {
        CompletableFuture<String> future = new CompletableFuture<>();
        String fileName = createFileName(file.getOriginalFilename());
        String folder = IMAGES_FOLDER + domainName + "/";

        long startTime = System.currentTimeMillis();

        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setContentLength(file.getSize());
        metadata.setContentType(file.getContentType());

        future.complete(uploadToS3(file, folder, fileName));

        long endTime = System.currentTimeMillis();
        log.info("{} - 실행 시간: {}", Thread.currentThread().getName(), endTime - startTime);

        return future;
    }

// S3에 업로드 공통 로직
    private String uploadToS3(MultipartFile file, String folder, String fileName) {
        ObjectMetadata objectMetadata = new ObjectMetadata();
        objectMetadata.setContentLength(file.getSize());
        objectMetadata.setContentType(file.getContentType());

        try (InputStream inputStream = file.getInputStream()) {
            amazonS3Client.putObject(new PutObjectRequest(bucket, folder + fileName, inputStream,
                objectMetadata).withCannedAcl(CannedAccessControlList.PublicRead));
        } catch (IOException e) {
            throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR,
                "파일 업로드에 실패했습니다.");
        }
        return amazonS3Client.getUrl(bucket, folder + fileName).toString();
    }

@Bean(name = "imageUploadExecutor")
    public Executor imageUploadExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();

        executor.setThreadGroupName("imageUploadExecutor");
        executor.setCorePoolSize(10);
        executor.setMaxPoolSize(15);
        executor.setQueueCapacity(100);
        executor.initialize();

        return executor;
    }

async log
synch log

In practice, I expected to see a noticeable improvement in response time with asynchronous processing, but there was no significant difference compared to synchronous processing.

I also tried adjusting the thread pool settings and tested it on a VM rather than locally, but I didn’t observe any substantial effect. I really want to understand the cause.

New contributor

user24348330 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật