RAM, AWS Lambda and Java's Parallelism

On my i9 laptop, Java reports 16 available CPUs:


jshell> Runtime.getRuntime().availableProcessors()
$1 ==> 16    

Which value can we expect on AWS Lambda?

The more RAM you configure for an AWS Lambda function, the more vCPU(s) you get:

Lambda allocates CPU power in proportion to the amount of memory configured. Memory is the amount of memory available to your Lambda function at runtime. You can increase or decrease the memory and CPU power allocated to your function using the Memory (MB) setting. To configure the memory for your function, set a value between 128 MB and 10,240 MB in 1-MB increments. At 1,769 MB, a function has the equivalent of one vCPU (one vCPU-second of credits per second). from https://docs.aws.amazon.com/lambda/latest/dg/configuration-function-common.html#configuration-memory-console

With the minimal configuration of 128 MB RAM you get only a fraction of a vCPU, and with 1,769 MB RAM a whole vCPU.

What value the following AWS Lambda will report with the 128 MB configuration?


public class Greetings{

    public String onEvent(Map<String,String> input) {
        var processors = Runtime.getRuntime().availableProcessors();
        return String.format("available processors %s ", processors);
    } 
}    

Although, you only have a fraction of the vCPU available, Lambda function returns:


"available processors 2"
With the RAM setting of 10 GB (10240), the AWS Lambda returns: available processors 6 and with 5 GB (5120): "available processors 3"

ForkJoinPool's and parallelStream() are also relying on the number of available CPUs to configure Java's parallelism. On AWS Lambda with 128MB memory you only get a fraction of CPU, but Runtime.getRuntime().availableProcessors() will report 2 which will lead to a more parallelism than expected.

The sample code is available as template from: https://github.com/AdamBien/aws-lambda-cdk-plain.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
...the last 150 posts
...the last 10 comments
License