[Java] Quarkus saves Java Lambda! ??

less than 1 minute read

It’s amazing Quarkus !!!!!!
Java’s Lambda cold start is Chopaya! !!

I tried it with reference to the following official website.

https://quarkus.io/guides/amazon-lambda#tracing-with-aws-xray-and-graalvm

Test target

Last time AWS Lambda Java is slow? , but with the following differences. Are all Quarkus restrictions? Constraint? is.

  • Annotated
  • httpClient is UrlConnectionHttpClient

entire source </summary> <div>

package example;

import javax.inject.Named;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;

import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import software.amazon.awssdk.services.s3.model.PutObjectResponse;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.regions.Region;

@Named("test")
public class TestLambda implements RequestHandler<Object, Object> {

    @Override
    public Object handleRequest(Object input, Context context) {

        String ENV_BUCKET = System.getenv("BUCKET");

        S3Client s3 = S3Client.builder()
                            .region(Region.AP_NORTHEAST_1)
                            .httpClient(software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient.builder().build())
                            .build();

        PutObjectResponse result = s3.putObject(
                PutObjectRequest.builder().bucket(ENV_BUCKET).key("filename.txt").build(),
                RequestBody.fromString("contents"));

        System.out.println(result);

        return "";
    }
}

</div></details>

inspection result

Number of times Latency(ms) Processing content
1 2700  
2 250  
3 305  
4 319  
5 187  

Last time the cold start was 6200ms, so it was really fast!

Verification result (+ Provisioned Concurrency)

What would happen if Quarkus, who is such a chopper, is Provisioned? I’m excited.

Number of times Latency(ms) Processing content
1 417  
2 198  
3 206  
4 270  
5 147  

Speed that does not disappoint! Great, Quarkus!

reference

https://quarkus.io/guides/amazon-lambda#tracing-with-aws-xray-and-graalvm https://aws.amazon.com/jp/blogs/architecture/field-notes-optimize-your-java-application-for-aws-lambda-with-quarkus/