GithubHelp home page GithubHelp logo

dynamodb-throughput's Introduction

dynamodb-throughput

Build Status

Set and reset provisioned DynamoDB throughput

Usage

Adjusting capacities

You can set the table's read and write capacities to perform some operation that requires a lot of throughput. After you're done, you can reset the provisioned throughput to prior levels. If you change throughput multiple times, reseting will return to the original table values, before dynamodb-throughtput made any adjustments.

var throughput = require('dynamodb-throughput')('my-table', { region: 'us-east-1' });
var queue = require('queue-async');

queue(1)
  .defer(throughput.setCapacity, { read: 1000, write: 1000 })
  .defer(doSomethingStrenuous)
  .defer(throughput.resetCapacity)
  .awaitAll(function(err) {
    console.log(err || 'All done!');
  });

It also works on GlobalSecondaryIndexes.

var throughput = require('dynamodb-throughput')('my-table', { region: 'us-east-1' });
var queue = require('queue-async');

queue(1)
  .defer(throughput.setIndexCapacity, 'my-index', { read: 1000, write: 1000 })
  .defer(doSomethingStrenuous)
  .defer(throughput.resetIndexCapacity, 'my-index')
  .awaitAll(function(err) {
    console.log(err || 'All done!');
  });

If you prefer, you can make adjustments to the table's existing throughput. For example, if you wanted to add 500 to the table's existing read capacity:

var throughput = require('dynamodb-throughput')('my-table', { region: 'us-east-1' });
var queue = require('queue-async');

queue(1)
  .defer(throughput.adjustCapacity, { read: 500 })
  .defer(doSomethingStrenuous)
  .defer(throughput.resetCapacity)
  .awaitAll(function(err) {
    console.log(err || 'All done!');
  });

... and similarly for GlobalSecondaryIndexes:

var throughput = require('dynamodb-throughput')('my-table', { region: 'us-east-1' });
var queue = require('queue-async');

queue(1)
  .defer(throughput.setIndexCapacity, 'my-index', { read: 500 })
  .defer(doSomethingStrenuous)
  .defer(throughput.resetIndexCapacity, 'my-index')
  .awaitAll(function(err) {
    console.log(err || 'All done!');
  });

The second argument when creating the throughput object ({ region: 'us-east-1' } in these examples) is an options object passed to new AWS.DynamoDB(options) to communicate with DynamoDB. Usually you should only need to provide a region property.

Getting throughput / partitioning information

You can use this library to gather information about a table's current throughput and estimate its partitioning needs. See the AWS DynamoDB documentation for more information about the way a table's partitioning needs are calculated.

var throughput = require('dynamodb-throughput')('my-table', { region: 'us-east-1' });
throughput.tableInfo(function(err, info) {
  console.log(info);
  // {
  //   main: {
  //     read: 4000,
  //     write: 300,
  //     size: 67432123,
  //     partitions: 2
  //   },
  //   indexes: {
  //     indexName: {
  //       read: 300,
  //       write: 100,
  //       size: 873624,
  //       partitions: 1
  //     }
  //   }
  // }
});

Increasing throughput can require your table to be repartitioned, and this can have unexpected consequences on the throughput performance of your table. This library can estimate the partitioning that would be required by a proposed throughput adjustment. Running this function has no impact on your table, it simply provides you with information about your table's state if you were to perform such an adjustment.

var throughput = require('dynamodb-throughput')('my-table', { region: 'us-east-1' });
var adjustment = { main: { read: 13000 } } // increases table's read capacity to 13000
throughput.adjustedTableInfo(adjustment, function(err, info, warnings) {
  console.log(info);
  // {
  //   main: {
  //     read: 13000,
  //     write: 300,
  //     size: 67432123,
  //     partitions: 5
  //   },
  //   indexes: {
  //     indexName: {
  //       read: 300,
  //       write: 100,
  //       size: 873624,
  //       partitions: 1
  //     }
  //   }
  // }
  console.log(warnings);
  // {
  //   main: true,
  //   indexes: {}
  // }
});

Included shell scripts can be used to run either of these functions.

$ npm install -g dynamodb-throughput
$ dynamodb-throughput-info us-east-1/my-table
# {
#   main: {
#     read: 4000,
#     write: 300,
#     size: 67432123,
#     partitions: 2
#   },
#   indexes: {
#     indexName: {
#       read: 300,
#       write: 100,
#       size: 873624,
#       partitions: 1
#     }
#   }
# }
$ dynamodb-throughput-adjustment us-east-1/my-table --main-read 13000
# WARNING: This adjustment would force the table to be repartitioned
# {
#   main: {
#     read: 13000,
#     write: 300,
#     size: 67432123,
#     partitions: 5
#   },
#   indexes: {
#     indexName: {
#       read: 300,
#       write: 100,
#       size: 873624,
#       partitions: 1
#     }
#   }
# }

dynamodb-throughput's People

Contributors

rclark avatar tmcw avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dynamodb-throughput's Issues

addCapacity

Provide a function by which you can add throughput capacity, rather than set it to a specified value.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.