Last active
June 15, 2023 02:43
-
-
Save leafypout/df0fecaee7a2f57f910808c4c9639d27 to your computer and use it in GitHub Desktop.
Calculate approximate GameLift compute usage from player count and other variables
This file contains hidden or 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
# --- CONFIG --- | |
# Options here can be set by normal users. | |
# Total amount of players playing the game | |
n_players = 500 | |
# Amount of players per match (includes both teams) | |
n_players_per_match = 16 * 2 # 16 players per team | |
# Duration (in minutes) of each match | |
match_duration_mins = 30 | |
# How many hours the playtest lasts | |
# This can be 730.001 maximum (1 month), since otherwise the | |
# calculations below wouldn't be correct (this script is for | |
# calculating monthly costs only). | |
playtest_hours = 8 | |
# How much the GameLift instance type costs per hour | |
# Pricing can be found at: https://aws.amazon.com/gamelift/pricing/ | |
cost_per_hour = 0.109 # c5.large | |
# Amount of compute hours free per month before costs incur. | |
# This is currently 125 hours/month for c5.large On-Demand instance type ONLY. | |
# If you change the instance type above, change this to zero. | |
free_tier_hours = 125 | |
# Amount of matches per instance | |
n_matches_per_instance = 2 | |
# --- GENERATED DATA --- | |
# Everything below this line is generated data. | |
# Users should only edit the variables above. | |
import math | |
import locale | |
# Validate config options | |
def non_zero(value, name): | |
assert value > 0, "%s must be greater than zero (got %d)" % (name, value) | |
non_zero(n_players, "n_players") | |
non_zero(n_players_per_match, "n_players_per_match") | |
non_zero(match_duration_mins, "match_duration_mins") | |
assert playtest_hours > 0 and playtest_hours <= 730.001, "playtest_hours must be greater than 0 and greater than or equal to 730.001" | |
non_zero(cost_per_hour, "cost_per_hour") | |
non_zero(n_matches_per_instance, "n_matches_per_instance") | |
# Set locale | |
locale.setlocale(locale.LC_ALL, "") | |
# Amount of running matches every match_duration_mins, rounded up to | |
# the nearest integer | |
n_matches_duration = math.ceil(n_players / n_players_per_match) | |
# Amount of running matches each hour | |
n_matches_per_hour = n_matches_duration / (match_duration_mins / 60) | |
# Amount of running matches for the entire playtest duration | |
n_matches = playtest_hours * n_matches_per_hour | |
# Amount of compute minutes used by all matches | |
compute_mins = (n_matches * match_duration_mins) / n_matches_per_instance | |
# Converted to hours | |
compute_hours = compute_mins / 60 | |
# Calculate cost | |
cost = max(compute_hours - free_tier_hours, 0) * cost_per_hour | |
cost_excl_free_tier = compute_hours * cost_per_hour | |
print("Running matches (every %d mins): %d" % (match_duration_mins, n_matches_duration)) | |
print("Running matches (per hour): %d" % n_matches_per_hour) | |
print("Running matches (entire playtest): %d" % n_matches) | |
print("Compute minutes: %d (%d hours)" % (compute_mins, compute_mins / 60)) | |
print("Total cost (after free tier): %s" % locale.currency(cost, grouping=True)) | |
print("Total cost (excluding free tier): %s" % locale.currency(cost_excl_free_tier, grouping=True)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment