简体   繁体   English

AWS-SDK DynamoDB NodeJS性能不好?

[英]AWS-SDK DynamoDB NodeJS bad performance?

I'm testing the dynamoDB API with the AWS-SDK for NodeJS. 我正在使用适用于NodeJS的AWS-SDK测试dynamoDB API。 But I have some strange behavior, dynamoDB seems to be slower to respond and I don't understand why. 但是我有一些奇怪的行为,dynamoDB似乎响应速度较慢,我也不明白为什么。

From the AWS Console, I set "100" Read capacity units to "MyTable" 在AWS控制台中,我将“ 100”读取容量单位设置为“ MyTable”

I made some benchmarks : 我做了一些基准测试:

For 10 calls the services seems to respond in less then 1 sec; 对于10个呼叫,服务似乎在不到1秒的时间内响应; 100 calls (1,5 sec), 1000 calls (4,5 secs), 5000 calls (30 secs) 100个通话(1.5秒),1000个通话(4.5秒),5000个通话(30秒)

See below for my code : 请参阅以下代码:

var http = require('http');
var https = require('https');
var AWS = require("aws-sdk");

var start = new Date();

http.globalAgent.maxSockets = 100000;
https.globalAgent.maxSockets = 100000;

AWS.config.update({
  accessKeyId: 'MyAccessKey',
  secretAccessKey: 'MySecretKey',
  region: 'MyRegion'
});

var dynamodbDoc = new AWS.DynamoDB.DocumentClient();

var startedDate = new Date()
console.log('Start');
for (var i = 0; i < 5000; i++) {
    getVolume("604275e8-17de-4582-bbc2-1b5eaf3b0a4c");
}   
console.log('Over ' + (new Date() - startedDate) + ' ms');

function getVolume(key) {
    var params = {
        TableName: "MyTable",
        KeyConditionExpression: "#id = :key",
        ExpressionAttributeNames: {
            "#id": "id"
        },
        ExpressionAttributeValues: {
            ":key": key
        }
    };
    var requestStarted = new Date()
    dynamodbDoc.query(params, function (err, data) {
        if (err) {
            console.error("Unable to query. Error:", JSON.stringify(err, null, 2));
        } else {
            console.log("DynamoDB : " + (new Date() - requestStarted));
        }
    });
}

With the 5000 calls, the "for" statement is over after 3 seconds but the first dynamoDB respond after 30 seconds, why ? 对于5000个调用,“ for”语句在3秒后结束,但是第一个dynamoDB在30秒后响应,为什么?

Thank you in advance, 先感谢您,

You are sending 5000 calls to DynamoDB virtually simultaneously. 您实际上同时向DynamoDB发送了5000个呼叫。 First, there is probably some CPU and network bottlenecks on the computer running the test keeping this from performing as well as you want. 首先,在运行测试的计算机上可能存在一些CPU和网络瓶颈,无法按预期运行。 Second, if this is really what you intend to be testing then you would need to increase the write capacity of DynamoDB to something much higher. 第二,如果这确实是您要测试的内容,则需要将DynamoDB的写容量增加到更高。

If you are trying to perform the calls to DynamoDB one at a time, then you need to wait for the callback to finish before executing the next call. 如果您尝试一次执行一次对DynamoDB的调用,则需要等待回调完成才能执行下一个调用。

thank you for your answer. 谢谢您的回答。

Currently I have a nodejs web server (with restify) and when I did a load test on it (more than 1000 req/s), dynamodb seems to be slow to respond, more than 60 seconds and of course some request have a timeout. 当前,我有一个nodejs Web服务器(带有restify),当我对其进行负载测试(超过1000 req / s)时,dynamodb的响应速度似乎很慢,超过60秒,当然还有一些请求超时。

With my code I would like to understand why dynamodb seems to be slow. 通过我的代码,我想了解为什么dynamodb似乎很慢。 I'm looking for the bottleneck in my code. 我正在寻找代码中的瓶颈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM