Charlie Fish
Charlie Fish

Reputation: 20496

Amazon Web Services DynamoDB Requests Slow

I'm currently using the library dynamoose to handle DynamoDB in Node.js. I have been doing some tests about why my express requests are taking 1000+ ms in some cases and have pin pointed it to the dynamoose functions. When doing a scan or save it takes ABOUT 240ms for each of those requests. So if I'm having to do a few of those in one function it can get long.

According to AWS I'm FAR below my provisioned read and write capacity.Read and Write capacity

Also one of my tables is showing 10-40ms scan and put latency. Which doesn't seem to bad but still seems slightly high (could be totally normal tho).

Put and Scan latency

Any ideas on how to improve the speed of all this so my DB requests don't take 240ms?

Upvotes: 1

Views: 1261

Answers (2)

Mircea
Mircea

Reputation: 10566

A scan fetches everything in a table. So depending on how big the table is it can take a while to bring in everything.

The Scan Latency you see here is for 1 scan request on the server (it does not account for network or client latency).

To grab everything in the table you normally perform several scan requests (there is an upper bound on the size of the data that can come back 1MB IIRC)

You also need to look and see if you have keepalive enabled in the SDK you are using (ie: are you reusing a connection or opening a new one) and consider how far you are from the AWS Region (if you don't run the code on an EC2 instance in the same region as the DDB you are using you will see a penalty on the network latency).

Upvotes: 1

Piyush Patil
Piyush Patil

Reputation: 14523

By default, keepAlive is not enabled in node. Enabling this should speed things up as existing sockets will be reused. Do you mind testing this option out? You can do this by instantiating your DynamoDB client with the following options:

var dynamo = new AWS.DynamoDB({
  region: "ap-southeast-2",
  httpOptions: {
    agent: new https.Agent({
      rejectUnauthorized: true,
      keepAlive: true
    })
  }
});

Upvotes: 1

Related Questions