Rambrabu Jaganathan
Rambrabu Jaganathan

Reputation: 91

How to increase performance in AWS Lambda service?

I have created simple Lambda function in java and exposing it using API gateway. The Billed duration for lambda function in 60 ms, api gateway taking 40 ms more to response so the latency is 100 ms here.

Note : Memory Size: 1.5GB Max Memory Used: 40 MB. All the response time which mentioned here is when lambda function in warm state (active)

If we test the latency in AWS API Gateway its taking 100 ms.

If we test it in Rest client in my local machine, the latency is 1500 ms.

If we consume (call) this lambda function in EC2 instance for same region and same account, the latency is 200 ms

Why this much variation in Rest client, we get to know that the reason is network latency. How can I increase its performance because we need to consume this Lambda function in native app its taking almost 1500 ms.

For the web app which deployed in EC2 Instance for same region and same account we are getting fair response that is* 200 ms.

Upvotes: 1

Views: 926

Answers (1)

Robo
Robo

Reputation: 1032

Short answer: your best option for now is to deploy lambda in a region as close to your client as possible

Long answer: this is a problem of any web based application, not just lambda/api gateway. There are a few techniques to combat this.

  • cache content. API Gateway automatically comes with a CloudFront distribution so if you cache responses they are served from the nearest POP to the client.

  • multi region deployments. If you have clients in many disperse geographical locations you can deploy lamda + api gateway in several of those regions then use route53 with latency based routing to serve the client from the nearest location.

  • Lambda @edge. This is currently only in preview and only supports node.js for now, but would be ideal for responding to requests from the nearest POP

Upvotes: 1

Related Questions