Skip to content

Commit

Permalink
Allow scale down at 0%, fixes #17
Browse files Browse the repository at this point in the history
  • Loading branch information
sebdah committed Apr 10, 2013
1 parent 79248a5 commit 72afa97
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
18 changes: 16 additions & 2 deletions dynamic_dynamodb/dynamic_dynamodb.py
Expand Up @@ -49,6 +49,8 @@ def __init__(self, region, table_name,
increase_writes_with, decrease_writes_with,
min_provisioned_reads=None, max_provisioned_reads=None,
min_provisioned_writes=None, max_provisioned_writes=None,
allow_scaling_down_reads_on_0_percent=False,
allow_scaling_down_writes_on_0_percent=False,
check_interval=300, dry_run=True,
aws_access_key_id=None, aws_secret_access_key=None,
maintenance_windows=None, logger=None):
Expand Down Expand Up @@ -82,6 +84,12 @@ def __init__(self, region, table_name,
:param min_provisioned_writes: Minimum number of provisioned writes
:type max_provisioned_writes: int
:param max_provisioned_writes: Maximum number of provisioned writes
:type allow_scaling_down_reads_on_0_percent: bool
:param allow_scaling_down_reads_on_0_percent:
Allow scaling when 0 percent of the reads are consumed
:type allow_scaling_down_writes_on_0_percent: bool
:param allow_scaling_down_writes_on_0_percent:
Allow scaling when 0 percent of the writes are consumed
:type check_interval: int
:param check_interval: How many seconds to wait between checks
:type dry_run: bool
Expand Down Expand Up @@ -129,6 +137,10 @@ def __init__(self, region, table_name,
self.aws_access_key_id = aws_access_key_id
self.aws_secret_access_key = aws_secret_access_key
self.maintenance_windows = maintenance_windows
self.allow_scaling_down_reads_on_0_percent = \
allow_scaling_down_reads_on_0_percent
self.allow_scaling_down_writes_on_0_percent = \
allow_scaling_down_writes_on_0_percent

if min_provisioned_reads:
self.min_provisioned_reads = int(min_provisioned_reads)
Expand Down Expand Up @@ -165,7 +177,8 @@ def ensure_proper_provisioning(self):
}

# Check if we should update read provisioning
if read_usage_percent == 0:
if read_usage_percent == 0 and not \
self.allow_scaling_down_reads_on_0_percent:
self.logger.info(
'Scaling down reads is not done when usage is at 0%')
elif read_usage_percent >= self.reads_upper_threshold:
Expand All @@ -183,7 +196,8 @@ def ensure_proper_provisioning(self):
throughput['read_units'] = new_value

# Check if we should update write provisioning
if write_usage_percent == 0:
if write_usage_percent == 0 and not \
self.allow_scaling_down_writes_on_0_percent:
self.logger.info(
'Scaling down writes is not done when usage is at 0%')
elif write_usage_percent >= self.writes_upper_threshold:
Expand Down
24 changes: 21 additions & 3 deletions dynamic_dynamodb/main.py
Expand Up @@ -164,6 +164,8 @@ def main():
config['max-provisioned-reads'] = args.max_provisioned_reads
config['min-provisioned-writes'] = args.min_provisioned_writes
config['max-provisioned-writes'] = args.max_provisioned_writes
config['allow-scaling-down-reads-on-0-percent'] = False
config['allow-scaling-down-writes-on-0-percent'] = False
config['check-interval'] = args.check_interval
config['aws-access-key-id'] = args.aws_access_key_id
config['aws-secret-access-key'] = args.aws_secret_access_key
Expand Down Expand Up @@ -197,6 +199,8 @@ def main():
config['max-provisioned-reads'],
config['min-provisioned-writes'],
config['max-provisioned-writes'],
config['allow-scaling-down-reads-on-0-percent'],
config['allow-scaling-down-writes-on-0-percent'],
check_interval=config['check-interval'],
dry_run=config['dry-run'],
aws_access_key_id=config['aws-access-key-id'],
Expand Down Expand Up @@ -227,6 +231,8 @@ def main():
config['max-provisioned-reads'],
config['min-provisioned-writes'],
config['max-provisioned-writes'],
config['allow-scaling-down-reads-on-0-percent'],
config['allow-scaling-down-writes-on-0-percent'],
check_interval=config['check-interval'],
dry_run=config['dry-run'],
aws_access_key_id=config['aws-access-key-id'],
Expand Down Expand Up @@ -341,19 +347,31 @@ def parse_configuration_file(config_path):
('max-provisioned-reads', False),
('min-provisioned-writes', False),
('max-provisioned-writes', False),
('maintenance-windows', False)
('maintenance-windows', False),
('allow-scaling-down-reads-on-0-percent', False),
('allow-scaling-down-writes-on-0-percent', False),
]

# Populate the table options
for option, required in table_options:
try:
config[option] = config_file.get(section, option)
if option == 'allow-scaling-down-reads-on-0-percent':
config[option] = config_file.getboolean(section, option)
elif option == 'allow-scaling-down-writes-on-0-percent':
config[option] = config_file.getboolean(section, option)
else:
config[option] = config_file.get(section, option)
except ConfigParser.NoOptionError:
if required:
print 'Missing [{0}] option "{1}" in {2}'.format(
section, option, config_path)
sys.exit(1)
else:
config[option] = None
if option == 'allow-scaling-down-reads-on-0-percent':
config[option] = False
elif option == 'allow-scaling-down-writes-on-0-percent':
config[option] = False
else:
config[option] = None

return config
8 changes: 8 additions & 0 deletions example-dynamic-dynamodb.conf
Expand Up @@ -56,3 +56,11 @@ decrease-writes-with: 50
# Maintenance windows (in UTC)
#
#maintenance-windows: 22:00-23:59,00:00-06:00

#
# Other settings
#

# Allow down scaling when at 0% consumed reads
#allow-scaling-down-reads-on-0-percent: true
#allow-scaling-down-writes-on-0-percent: true

0 comments on commit 72afa97

Please sign in to comment.