AWS Lambda Functions powered by AWS Graviton2 Processors (Java, CDK)

Collin Smith
5 min readSep 29, 2021

--

This article will present a demonstration illustrating the price performance gains to be had by the newly released AWS Lambda Functions powered by AWS Graviton2. AWS Lambda functions powered by AWS Graviton2 processors offer up to 34% better price performance over x86-based Lambda functions.

In addition, we will review how to do this with a Java 11 CDK example where we compare the performance of Lambdas in the current x86_64 architecture to the Graviton2(arm64) architecture. The documented test below illustrates how the Graviton2 architecture executed a compute workload 2.08 times faster than the default(x86_84) architecture. This helps reduce the billed duration for the lambda function resulting in a cost savings as well.

What is Graviton2?

  • Custom AWS silicon with 64-bit Arm Neoverse cores
  • Targeted optimizations for cloud-native workloads
  • Rapidly innovate, build, and iterate on behalf of customers
  • Learn more about price performance improvements at Graviton2

Graviton2 Lambda Overview

  • AWS Lambda functions powered by AWS Graviton2 processors offer up to 34% better price performance over x86-based Lambda functions.
  • Configured by a new field “Architectures” in FunctionConfiguration data type with 2 possible values (x86_64 or arm64(Graviton2)
  • At launch, currently available for Python, Node, Java, .NET 3.1, Ruby, Custom Runtime (provided.al2) and OCI Base Images
  • At launch, 10 regions will be supported including Asia Pacific(Mumbai), Asia Pacific(Singapore), Asia Pacific(Sydney), Asia Pacific(Tokyo), EU (Frankfurt) EU(Ireland), EU(London), US East (N.Virginia), US East(Ohio) and US West(Oregon)

Graviton2 Java CDK Demonstration

We will now demonstrate the performance improvements of Graviton2 powered Lambda functions with a Java 11 with CDK. Xerris has been granted access to the private beta of the Graviton2 powered Lambda functions. If you are unfamiliar with how to create Java 11 Graviton2 powered Lambda functions with CDK and want to learn more please refer to Creating an AWS Serverless Java 11 Application with CDK).

For this demonstration, we will compare two Lambda functions executing an identical compute only workload. The only difference will be that one is using the x86_64 architecture and the other one will be using the new Graviton2(arm64) architecture.

Configuring the Architectures field in CDK

Our demonstration will configure 2 Lambda functions that execute the same handler code with only their architectures field being different.

The first lambda function simpleLambda will have it’s architecture left as the default x86_64 value.

The second lambda function gravitonSimpleLambda will have it set to be

The arm64 architecture is configured as follows in our Java 11 CDK code.We set with Property based escape hatches for the AWS Cloud Development Kit (CDK)

String key = "Architectures";
JSONArray values = new JSONArray();
values.add("arm64");
CfnFunction cfnFunction = (CfnFunction)gravitonSimpleLambdaFunction.getNode().getDefaultChild();
cfnFunction.addPropertyOverride(key, values);

Look at the basic workload

Our simple workload in the handler executes some simple code that is compute intensive(although not all that useful).

public static void executeCPUIntensiveTask()
{
//some cpu intensive task
long limit = 5000;
String lastSqRoot = "";
for (int i=0;i<limit;i++){
for (int j=0;j<limit;j++){
double sqroot = Math.sqrt(j);
lastSqRoot = ""+sqroot;
}
}
System.out.println("lastSqRoot="+lastSqRoot);
}

Performance improvements with Graviton2

The lambdas will display how long it takes to execute the cpu intensive task above.

3 runs of simpleLambda(x86_64): 31150, 32561, 31348 = Average of 31686ms

3 runs of gravitonSimpleLambda(arm64): 15621, 15463, 14621 = Average of 15235ms

With this test, running a lambda with the Graviton2(arm64) architecture setting, one can see an that a Lambda utilizing the Graviton2 architecture runs 2.08 times faster. Also note that for compute, this means that the Billed Duration is reduced by that amount as well. This results in an obvious performance and cost gain.

If the pricing for the x86_64 lambda is the same as the pricing for the arm64 architecture, this would imply that the Graviton2 architecture would only use 48% (1/2.08) of a billing duration. This means that an organization would be saving 52% on Lambda compute if both architectures are billed at the same rate.

The code for this demonstration can be found at https://github.com/collin-smith/javagravitonlambda.

Price improvements with Graviton2

In terms of price, the Arm Price(Graviton2) wins hands down.

For example in the US West Region, for a x86 price for a 128MB Lambda the price is $0.0000000021 per 1ms compared to $0.0000000017 per 1ms. This is a savings of about 20%.

Please consult https://aws.amazon.com/lambda/pricing/ for current pricing.

Conclusion

We hope that this demonstration has illustrated the performance and cost benefits that lie in the use of the Graviton2 architecture with your Lambda functions.

To summarize, Graviton2 Java Lambda functions are essentially twice as fast as the previous x86_64 architecture. In addition, there are cost savings as the billed rate is about 20% lower than the x86_64 architecture. This means that the overall cost is less than half for compute intensive workloads because they will take have less overall billed duration for each lambda call and cost 20% less for the compute required.

Graviton2 Java Lambda functions show a definite performance and price gain when compared to the x86_64 architecture.

A similar article was written for DotNet Graviton2 Lambda functions. The DotNet Graviton2 Lambda function testing results can be found at https://collin-smith.medium.com/aws-dotnet-lambda-functions-powered-by-aws-graviton2-processors-c-cdk-c7efc160324d.

For more information on Graviton2 powered lambda functions please consult https://aws.amazon.com/blogs/aws/aws-lambda-functions-powered-by-aws-graviton2-processor-run-your-functions-on-arm-and-get-up-to-34-better-price-performance/ . Xerris was an AWS Launch Partner for this feature release.

If you want to learn more about this or look to applying the best practices of cloud development, please reach out to us as Xerris.com

--

--

Collin Smith
Collin Smith

Written by Collin Smith

AWS Ambassador/Solutions Architect/Ex-French Foreign Legion