Skip to content

Instantly share code, notes, and snippets.

@knight42
Created November 3, 2022 03:29
Show Gist options
  • Save knight42/63b278c3f5e6eb9bd6ac63225d4a6751 to your computer and use it in GitHub Desktop.
Save knight42/63b278c3f5e6eb9bd6ac63225d4a6751 to your computer and use it in GitHub Desktop.
比较阿里云 OSS 于 CDN 价格
#!/usr/bin/env python -O
def compare_price(requests_count: int, cdn_hit_ratio: float, obj_size_kb: int):
cdn_traffic_per_gb_price = 0.24
cdn_https_requests_per_10_thousand_price = 0.05
cdn_back_to_origin_traffic_per_gb = 0.15
oss_traffic_per_gb_price = 0.5
oss_get_per_10_thousand_price = 0.01
# CDN
# https://www.aliyun.com/price/detail/cdn
# https://help.aliyun.com/document_detail/326338.html
hit_requests = int(requests_count * cdn_hit_ratio)
miss_requests = requests_count - hit_requests
cdn_total_price = requests_count * obj_size_kb * cdn_traffic_per_gb_price / 1024**2 + requests_count * cdn_https_requests_per_10_thousand_price / 10000 + miss_requests * obj_size_kb * cdn_back_to_origin_traffic_per_gb / 1024**2
# OSS
# https://www.aliyun.com/price/detail/oss
oss_total_price = requests_count * obj_size_kb * oss_traffic_per_gb_price / 1024**2 + requests_count * oss_get_per_10_thousand_price / 10000
print('OSS total price:', oss_total_price)
print('CDN total price:', cdn_total_price)
compare_price(10000, 0.5, 200)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment