Created
December 18, 2018 15:56
-
-
Save yaasita/f28763aad3007a06e45c17ae82d46673 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const AWS = require("aws-sdk"); | |
const dynamodb = new AWS.DynamoDB({ | |
region: "us-east-2" | |
}); | |
(async function() { | |
console.log("start"); | |
let wait = []; | |
for (let i = 0; i < 10000; i++) { | |
wait.push(add_dummy()); | |
} | |
const result = await Promise.all(wait); | |
console.log(count(result)); | |
})(); | |
function count(array) { | |
let success = 0; | |
let fail = 0; | |
for (let i = 0; i < array.length; i++) { | |
if (array[i] === 0) { | |
success++; | |
} else { | |
fail++; | |
} | |
} | |
return { | |
success: success, | |
fail: fail | |
}; | |
} | |
function unixtime() { | |
const d1 = new Date(); | |
const d2 = d1.getTime(); | |
const d3 = parseInt(d2 / 1000); | |
return String(d3); | |
} | |
async function add_dummy() { | |
const id = Math.random() | |
.toString(36) | |
.slice(-8); | |
const evaluated = Math.floor(Math.random() * Math.floor(1000)).toString(); | |
var params = { | |
Item: { | |
article_id: { | |
S: id | |
}, | |
evaluated_at: { | |
N: evaluated | |
}, | |
created_at: { | |
N: unixtime() | |
} | |
}, | |
TableName: "hogehogetable" | |
}; | |
let result = 0; | |
try { | |
await dynamodb.putItem(params).promise(); | |
result = 0; | |
} catch (e) { | |
console.log(`error = ${e}`); | |
result = 1; | |
} | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
let AWS = require('aws-sdk'); | |
let dynamodb = new AWS.DynamoDB({ | |
region: 'us-east-2' | |
}); | |
(async function() { | |
console.log("start"); | |
let wait = []; | |
for (let i = 0; i < 100; i++) { | |
wait.push(get_items()); | |
} | |
const result = await Promise.all(wait); | |
console.log(count(result)); | |
})() | |
function count(array) { | |
let success = 0; | |
let fail = 0; | |
for (let i = 0; i < array.length; i++) { | |
if (array[i] === 0) { | |
success++; | |
} else { | |
fail++; | |
} | |
} | |
return { | |
success: success, | |
fail: fail | |
}; | |
} | |
async function get_items(key1, key2){ | |
const params = { | |
ExpressionAttributeNames: { | |
"#AD": "article_id", | |
"#EV": "evaluated_at" | |
}, | |
ConsistentRead: true, | |
ProjectionExpression: "#AD,#EV", | |
TableName: "hogehogetable", | |
}; | |
let result = 0; | |
try { | |
const response = await dynamodb.scan(params).promise(); | |
console.log("OK"); | |
result = 0; | |
} | |
catch (e) { | |
console.log(`error = ${e}`); | |
result = 1; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment