Skip to content

Instantly share code, notes, and snippets.

@thom-vend
Last active February 5, 2024 03:24
Show Gist options
  • Save thom-vend/c710e4fb173b4bea91bc12204c25ee86 to your computer and use it in GitHub Desktop.
Save thom-vend/c710e4fb173b4bea91bc12204c25ee86 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from icecream import ic
"""
Cost of burstable CPU credit above baseline:
- $0.09 per vCPU-Hour for Aurora Standard
- $0.12 per vCPU-Hour for Aurora I/O-Optimized clusters
Baseline cannot be foudn for aurora, but should be the same as ec2:
https://aws.amazon.com/ec2/instance-types/t4/
t4g.large: 30%
t4g.medium: 20%
Standard aurora pricing not I/O optimized
db.r7g.large pricing: $0.276 per h
db.t4g.large pricing: $0.146 per h
db.t4g.medium pricing: $0.073 per h
"""
def compute_break_even(
r_price=0.276, # newer r7g price per hour
t_price=0.073, # t4g.medium price per hour
t_baseline=20, # % CPU included in the burstable
t_vCPU=2, # Number of vCPUs of the burstable instance
credit_price_per_h=0.09 # Price per vCPU hour
):
tr_price_diff = r_price - t_price
ic(tr_price_diff)
credit_price_per_min = credit_price_per_h / 60
# from price diff: possible burst in min (without including the baseline)
burst_allowed_min = tr_price_diff / credit_price_per_min / t_vCPU
ic(burst_allowed_min)
burst_allowed_CPUusage = burst_allowed_min / 60 * 100
ic(burst_allowed_CPUusage)
break_even = burst_allowed_CPUusage + t_baseline
return round(break_even, 2)
if __name__ == "__main__":
print(compute_break_even())
print(compute_break_even(t_price=0.164, t_baseline=30)) # db.t3.large vs db.r7g.large
print(compute_break_even(r_price=0.260, t_price=0.164, t_baseline=30)) # db.t3.large vs db.r6g.large
print(compute_break_even(r_price=0.260, t_price=0.146, t_baseline=30)) # db.t4g.large vs db.r6g.large
@thom-vend
Copy link
Author

thom-vend commented Feb 5, 2024

Results:

ic| tr_price_diff: 0.203
ic| burst_allowed_min: 67.66666666666667
ic| burst_allowed_CPUusage: 112.77777777777777
132.78
ic| tr_price_diff: 0.11200000000000002
ic| burst_allowed_min: 37.333333333333336
ic| burst_allowed_CPUusage: 62.22222222222222
92.22
ic| tr_price_diff: 0.096
ic| burst_allowed_min: 32.0
ic| burst_allowed_CPUusage: 53.333333333333336
83.33
ic| tr_price_diff: 0.11400000000000002
ic| burst_allowed_min: 38.00000000000001
ic| burst_allowed_CPUusage: 63.33333333333334
93.33

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment