Created
December 20, 2021 12:35
-
-
Save bahrmichael/347839d2882eb168e4996a6dd11d8337 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
import * as DynamoDB from 'aws-sdk/clients/dynamodb'; | |
import {v4 as uuid} from 'uuid'; | |
const ddb = new DynamoDB.DocumentClient({region: 'us-east-1'}); | |
const t = (startInMinutes: number) => { | |
const d = new Date(new Date().getTime() + 1_000 * 60 * startInMinutes); | |
return { | |
"pk": `j#${d.getUTCFullYear()}-${d.getUTCMonth()}-${d.getUTCDate()}T${d.getUTCHours()}:${d.getUTCMinutes()}`, | |
"sk": `${d.toISOString()}#${uuid()}`, | |
"detail": { | |
"action": "send-reminder", | |
"userId": "16f3a019-e3a5-47ed-8c46-f668347503d1", | |
"taskId": "6d2f710d-99d8-49d8-9f52-92a56d0c6b81", | |
"params": { | |
"can_skip": false, | |
"reminder_volume": 0.5 | |
} | |
}, | |
"detail_type": "job-reminder" | |
} | |
}; | |
// Test data and interpolation. | |
// 100: 2.5s => 2,400/m | |
// 500; 13.3s => 2,300/m | |
// 16:15 => 5,200; breaks | |
async function runMe() { | |
// Choose a reasonably high value to write all the events before the job starts. Find it by trying out smaller batches like 100 events. | |
const startInMinutes = 10; | |
const eventCount = 100; | |
const s = new Date(); | |
const promises = []; | |
for (let i = 0; i < eventCount; i++) { | |
const item = t(startInMinutes); | |
promises.push(await ddb.put({ | |
TableName: 'JobsTable', | |
Item: item, | |
}).promise()); | |
} | |
await Promise.all(promises); | |
const e = new Date(); | |
console.log({s, e}); | |
} | |
runMe().catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment