Last active
December 5, 2016 03:04
-
-
Save riceissa/51ceb243a2f23995b902c1e320efdf71 to your computer and use it in GitHub Desktop.
amazon s3 modeling
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
This is free and unencumbered software released into the public domain. | |
Anyone is free to copy, modify, publish, use, compile, sell, or | |
distribute this software, either in source code form or as a compiled | |
binary, for any purpose, commercial or non-commercial, and by any | |
means. | |
In jurisdictions that recognize copyright laws, the author or authors | |
of this software dedicate any and all copyright interest in the | |
software to the public domain. We make this dedication for the benefit | |
of the public at large and to the detriment of our heirs and | |
successors. We intend this dedication to be an overt act of | |
relinquishment in perpetuity of all present and future rights to this | |
software under copyright law. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
OTHER DEALINGS IN THE SOFTWARE. | |
For more information, please refer to <http://unlicense.org/> |
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
https://aws.amazon.com/glacier/pricing/ | |
https://aws.amazon.com/s3/pricing/ | |
https://cloud.google.com/storage/pricing#storage-pricing | |
https://www.sumologic.com/aws/s3/10-things-might-not-know-using-s3/ | |
https://encrypted.google.com/search?hl=en&q=optimize%20amazon%20s3%20costs | |
http://www.wikihow.com/Optimize-Your-Amazon-S3-Costs#Optimizing_storage_costs_through_storage_class_selection.2C_object_versioning.2C_and_lifecycle_policies_sub |
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
#!/usr/bin/python3 | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.animation as animation | |
POINTS = 100000 | |
def cost(n, s, c_1, c_PUT, c_GET, c_DEL, r_PUT, r_GET, r_DEL, n_min=0, s_min=0, | |
r_GET_per_month=0, c_RET=0, lam=1): | |
''' | |
Compute the single-file hosting cost on S3 in dollars. | |
Arguments: | |
- n is the number of months | |
- s is the size of the stored data in GB | |
- c_1 is the storage cost in dollar per GB-month | |
- c_PUT is the cost of 'PUT, COPY, POST, or LIST Requests' in dollar | |
per request | |
- c_GET is the cost of 'GET and all other Requests' in dollar per | |
request | |
- c_DEL is the cost of 'Delete Requests' in dollar per request | |
- r_PUT is the number of 'PUT, COPY, POST, or LIST Requests' | |
- r_GET is the number of 'GET and all other Requests'; this overrides | |
r_GET_per_month | |
- r_DEL is the number of 'Delete Requests' | |
- n_min is the minimum number of months | |
- s_min is the minimum size of stored data in GB | |
- r_GET_per_month is the number of 'GET and all other Requests' in | |
requsts per month; r_GET overrides this value | |
- c_RET is the cost of data retrieval in dollars per GB retrieved | |
''' | |
if r_GET == 0 and r_GET_per_month != 0: | |
# r_GET = r_GET_per_month * n | |
r_GET = (1 - np.exp(-lam * n)) * r_GET_per_month/(1-np.exp(-lam)) | |
storage_cost = max(n, n_min) * max(s, s_min) * c_1 | |
request_cost = c_PUT*r_PUT + c_GET*r_GET + c_DEL*r_DEL | |
retrieval_cost = s * c_RET * r_GET | |
return storage_cost + request_cost + retrieval_cost | |
def standard(n, s, r_GET_per_month=0, lam=1): | |
return cost(n, s, c_1=0.023, c_PUT=0.005/1000, c_GET=0.004/10000, c_DEL=0, | |
r_PUT=1, r_GET=0, r_DEL=1, | |
r_GET_per_month=r_GET_per_month, lam=lam) | |
def ia(n, s, r_GET_per_month=0, lam=1): | |
return cost(n, s, c_1=0.0125, c_PUT=0.01/1000, c_GET=0.01/10000, c_DEL=0, | |
r_PUT=1, r_GET=0, r_DEL=1, n_min=1, s_min=128/10**6, | |
r_GET_per_month=r_GET_per_month, lam=lam) | |
def glacier(n, s, r_GET_per_month=0, lam=1): | |
return cost(n, s, c_1=0.004, c_PUT=0.05/1000, c_GET=0.01, c_DEL=0, | |
r_PUT=1, r_GET=0, r_DEL=1, n_min=3, | |
r_GET_per_month=r_GET_per_month, c_RET=0.03, lam=lam) | |
def argmin_plans(*args, **kwargs): | |
return np.argmin([standard(*args, **kwargs), | |
ia(*args, **kwargs), | |
glacier(*args, **kwargs)]) | |
# ns = np.random.uniform(low=0, high=4, size=POINTS) | |
# ss = np.random.uniform(low=0, high=0.10, size=POINTS) | |
# ss.fill(0.000129) | |
# ns.fill(1) | |
r_1 = np.random.uniform(low=-5, high=5, size=POINTS) | |
r_2 = np.random.uniform(low=-5, high=5, size=POINTS) | |
ns = np.power(10, r_1) | |
ss = np.power(10, r_2) | |
def do_a_plot(ims, r_GET_per_month=0, lam=1): | |
colors = [] | |
for p in range(POINTS): | |
n = ns[p] | |
s = ss[p] | |
cmap = {0: 'blue', 1: 'red', 2: 'yellow'} | |
colors.append(cmap[argmin_plans(n, s, | |
r_GET_per_month=r_GET_per_month, lam=lam)]) | |
colors = np.array(colors) | |
plt.xscale('log') | |
plt.yscale('log') | |
ims.append((plt.scatter(ns, ss, c=colors, edgecolors='none', s=0.3),)) | |
fig = plt.figure() | |
ims = [] | |
for v in [0, 0.1, 1, 10, 100, 1000]: | |
do_a_plot(ims, v) | |
ani = animation.ArtistAnimation(fig, ims, interval=50, repeat_delay=3000, | |
blit=True) | |
# plt.show() | |
ani.save('im.gif', writer='imagemagick', fps=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment