27
votes

I have lambda function and dynamo db table in the same region (us-east-1). In lambda function I perform very simple query:

params =
  TableName: 'users'
  Item:
    email:
      S: event.body.email
  ConditionExpression: 'attribute_not_exists (email)'
dynamodb.putItem(params, context.done)

There are only few rows in DynamoDB table, there is Hash Key on email and Read/Write throughtputs are set to 5/5.

Lambda function exeutes in ~4 seconds... This is very slow. Am I doing something wrong?


I've tested my function with different memory settings for lambda function (it was set to 128mb previously):

  • 256mb => ~2000ms
  • 512mb => ~1000ms
  • 1024mb => ~500ms
  • 1536mb => ~300ms

So it seems that response time depends 1-1 on memory (well in fact on compute capacity as AWS scales it along with memory). Still this is crazy because to make very simple REST API I have to set 1536mb memory to make it "responsive" while my program uses 17mb!


Hmm on the other hand I've calculated that it will cost:

  • 8.32$ per 1 milion 4000ms requests using 128mb memory
  • 10.004$ per 1 milion 300ms requests using 1536mb memory

So it's not so bad I guess...

1
Are you sure that you are not doing anything else in your Lambda function? Simple JS call should not need that much memory and shouldn't take that much time. - Guy
Just for the sake of comparison, what sort of performance do you get if you hit SimpleDB? - StartupGuy
Have you found a solution to this? I am facing a similar issue, I am using batch writes in my lambda function and its taking way too long. Also, the function hardly uses 80MB memory, so increasing the memory to get better performance doesn't seem quite right to me. - ShwetaJ
For what it's worth; the Lambda config dialog states "Your function is allocated CPU proportional to the memory configured" - looks like AWS also give you more CPU when you configure more memory... - Journeyman
I'm doing a simple lookup from a table with 5 entries using the index. I'm getting 16 sec response times with 128MB RAM! adding more ram decreases the latency proportionally too but this is still huge latency! - Shubham Jain

1 Answers

2
votes

Well, the problem might also be related to un-pausing the container the Lambda function is running at. You also may want to optimize how you initialize your objects so they don't get re-initialized every time the function is called.

See the article Container reuse in Lambda.