Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: return ConsumedCapacity 'stats' for Write operations #444

Closed
andrew-permiso opened this issue Feb 7, 2023 · 2 comments
Closed

Idea: return ConsumedCapacity 'stats' for Write operations #444

andrew-permiso opened this issue Feb 7, 2023 · 2 comments
Labels
enhancement New feature or request fixed Issue has been fixed in the repo

Comments

@andrew-permiso
Copy link

Hey team!

Summary

I'm optimizing Dynamo writes for a write-heavy workload, and I wanted to make a case for adding support for WriteUnits to the stats API parameter. The OneTable documentation (stats param) suggests this is only for find/query/scan operations for now, and it would be great to have it for Write operations (e.g. DeleteItem, PutItem, UpdateItem, BatchWriteItem).

Motivation

Why this may be helpful to others:

  • Writes cost more than reads, per unit
  • Write Units may not be intuitive, especially for deletions or update expressions
    • Writing a 1 character field writes the whole entry (ie 1 byte may cause > 1 WCU write)
    • Indexes affect overall write usage
  • Estimations are helpful, but not as precise as empirical measurements with AWS counts

Or if someone can guide me to the place in the codebase where the change should be made, and it's quick enough, maybe I/someone else can find some time to submit a Pull Request.

Code Sample

Example Output with ConsumedCapacity when calling DeleteItem and PutItem:

/** Output via raw Dynamo lib, of the code snippet below:
 * Starting: dynamoWriteExperiments.ts
 * Deletion: { ConsumedCapacity: { TableName: 'example', CapacityUnits: 2 } }
 * Creation { ConsumedCapacity: { TableName: 'example', CapacityUnits: 2 } }
 */

Code sample using underlying AWS SDK:

import DynamoDB from "aws-sdk/clients/dynamodb";

const dynamodb = new DynamoDB({ region: "us-east-1" });
const table = "example";
const keys = { pk: { S: "pk1" }, sk: { S: "sk1" } };

const createParams = {
  Item: {
    ...keys,
    str: { S: new Array(2_000).join("0") }, // Generate 2k string of 0's
  },
  ReturnConsumedCapacity: "TOTAL",
  TableName: table,
};

// Deletion returns write units
const deletion = await dynamodb.deleteItem({
  Key: keys,
  ReturnConsumedCapacity: "TOTAL",
  TableName: table,
}).promise();
console.log("Deletion:", deletion);

// PutItem returns write units
const creation = await dynamodb.putItem(createParams).promise();
console.log("Creation", creation);
@mobsense mobsense added the enhancement New feature or request label Feb 15, 2023
@mobsense
Copy link
Contributor

Thank you. That is actually an easy fix.

Will apply.

mobsense pushed a commit that referenced this issue Feb 15, 2023
@mobsense mobsense added the fixed Issue has been fixed in the repo label Feb 15, 2023
@andrew-permiso
Copy link
Author

Awesome, thanks @mobsense!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed Issue has been fixed in the repo
Projects
None yet
Development

No branches or pull requests

2 participants