Created
April 21, 2016 14:37
-
-
Save jg75/7b1e712212bb23fd2a9c16a7ed4d4bb7 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 getopt | |
import math | |
import sys | |
db_iops_limits = { | |
"aurora": { | |
"MinimumStorage": 100, | |
"MaximumStorage": 6000, | |
"TheoreticalMaximumIOPS": 30000 | |
}, | |
"mariadb": { | |
"MinimumStorage": 100, | |
"MaximumStorage": 6000, | |
"TheoreticalMaximumIOPS": 30000 | |
}, | |
"MySQL": { | |
"MinimumStorage": 100, | |
"MaximumStorage": 4000, | |
"TheoreticalMaximumIOPS": 30000 | |
}, | |
"oracle-sel": { | |
"MinimumStorage": 100, | |
"MaximumStorage": 6000, | |
"TheoreticalMaximumIOPS": 25000 | |
}, | |
"oracle-se": { | |
"MinimumStorage": 100, | |
"MaximumStorage": 6000, | |
"TheoreticalMaximumIOPS": 25000 | |
}, | |
"oracle-ee": { | |
"MinimumStorage": 100, | |
"MaximumStorage": 6000, | |
"TheoreticalMaximumIOPS": 25000 | |
}, | |
"postgres": { | |
"MinimumStorage": 100, | |
"MaximumStorage": 6000, | |
"TheoreticalMaximumIOPS": 30000 | |
}, | |
"sqlserver-se": { | |
"MinimumStorage": 100, | |
"MaximumStorage": 6000, | |
"TheoreticalMaximumIOPS": 20000 | |
}, | |
"sqlserver-ee": { | |
"MinimumStorage": 100, | |
"MaximumStorage": 6000, | |
"TheoreticalMaximumIOPS": 20000 | |
}, | |
"sqlserver-ex": { | |
"MinimumStorage": 100, | |
"MaximumStorage": 6000, | |
"TheoreticalMaximumIOPS": 20000 | |
}, | |
"sqlserver-web": { | |
"MinimumStorage": 100, | |
"MaximumStorage": 6000, | |
"TheoreticalMaximumIOPS": 20000 | |
} | |
} | |
def get_iops_limits(storage, engine): | |
""" | |
Gets the IOPS limitations for a given RDS database engine. | |
Args: | |
storage (float): The amount IO1 SSD storage in GB. | |
Returns: | |
iops_limits A dictionary containing the IOPS limits for | |
a given RDS database engine. | |
Throws: | |
ValueError if the RDS engine is unknown or | |
storage is less than the minimum storage or | |
greater than the maximum storage. | |
""" | |
iops_limits = db_iops_limits.get(engine) | |
if not iops_limits: | |
raise ValueError("Unknown RDS engine: %s" % engine) | |
elif storage < iops_limits['MinimumStorage'] or \ | |
storage > iops_limits['MaximumStorage']: | |
raise ValueError( | |
"Storage (%s) must be between %s and %s" % ( | |
storage, | |
iops_limits['MinimumStorage'], | |
iops_limits['MaximumStorage'] | |
) | |
) | |
iops_limits['MinimumRatio'] = 3 | |
iops_limits['MaximumRatio'] = 10 | |
iops_limits['Incriment'] = 1000 | |
return iops_limits | |
def valid_iops(storage, engine): | |
""" | |
AWS RDS Provisioned IOPS calculator. | |
IOPS is a measurement of I/O throughput usage. Baseline performance | |
scales at a rate of iops:storage in incriments of 1000, | |
where one IOPS is equal to up to 16KiB of disk I/O | |
and storage equals 1GB ranging from 3:1 to 10:1. | |
Args: | |
storage (float): The amount IO1 SSD storage in GB. | |
engine (string): The RDS database engine, e.g. postgres. | |
Returns: | |
A list of valid IOPS. | |
Throws: | |
ValueError if the RDS engine is unknown or | |
storage is less than the minimum storage or | |
greater than the maximum storage. | |
""" | |
iops_limits = get_iops_limits(storage, engine) | |
minimum_iops = int(math.ceil( | |
storage * iops_limits['MinimumRatio'] / iops_limits['Incriment'] | |
)) * iops_limits['Incriment'] | |
maximum_iops = int(math.floor( | |
storage * iops_limits['MaximumRatio'] / iops_limits['Incriment'] | |
)) * iops_limits['Incriment'] | |
if maximum_iops > iops_limits['TheoreticalMaximumIOPS']: | |
maximum_iops = iops_limits['TheoreticalMaximumIOPS'] | |
return [ | |
iops for iops in range( | |
minimum_iops, | |
maximum_iops + iops_limits['Incriment'], | |
iops_limits['Incriment'] | |
) | |
] | |
def is_valid_iops(iops, storage, engine): | |
""" | |
Checks if the IOPS value is valid for a given volume. | |
Args: | |
iops (int): Disk I/O operations per second. | |
storage (float): The amount IO1 SSD storage in GB. | |
engine (string): The RDS database engine, e.g. postgres. | |
Returns: | |
True if the IOPS value is valid for a given volume | |
Throws: | |
ValueError if the RDS engine is unknown or | |
storage is less than the minimum storage or | |
greater than the maximum storage. | |
""" | |
return iops in get_valid_iops(storage, engine) | |
def minimum_iops(storage, engine): | |
""" | |
AWS RDS minimum Provisioned IOPS calculator. | |
Args: | |
storage (float): The amount IO1 SSD storage in GB. | |
engine (string): The RDS database engine, e.g. postgres. | |
Returns: | |
iops The lowest possible IOPS value for a given volume. | |
Throws: | |
ValueError if the RDS engine is unknown or | |
storage is less than the minimum storage or | |
greater than the maximum storage. | |
""" | |
return valid_iops(storage, engine)[0] | |
def maximum_iops(storage, engine): | |
""" | |
AWS RDS maximum Provisioned IOPS calculator. | |
Args: | |
storage (float): The amount IO1 SSD storage in GB. | |
engine (string): The RDS database engine, e.g. postgres. | |
Returns: | |
iops The highest possible IOPS value for a given volume. | |
""" | |
return valid_iops(storage, engine)[-1] | |
if __name__ == '__main__': | |
engine = 'postgres' | |
options, argv = getopt.getopt(sys.argv[1:], 'he:', ['help', 'engine=']) | |
for option, argument in options: | |
if option in ('-h', '--help'): | |
print('usage') | |
sys.exit(0) | |
elif option in ('-e', '--engine'): | |
engine = argument | |
for arg in argv: | |
print("%-6s%s" % (arg + ':', str(valid_iops(float(arg), engine)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment