diff --git a/notes/s3_simulate.py b/notes/s3_simulate.py index aecae7f..401980f 100644 --- a/notes/s3_simulate.py +++ b/notes/s3_simulate.py @@ -1,7 +1,7 @@ import datetime from dataclasses import dataclass from typing import List, Dict, Tuple - +from argparse import ArgumentParser @dataclass class S3PricingConfig: @@ -170,77 +170,92 @@ class S3PricingSimulator: break return total_cost +pricing = {} +# Sample pricing configuration based on approximated AWS S3 Standard pricing +pricing['aws'] = S3PricingConfig( + # Storage tiers (GB range min, max, price per GB-month) + storage_tiers=[ + (0, 50 * 1024, 0.023), # First 50 TB + (50 * 1024, 450 * 1024, 0.022), # Next 400 TB + (450 * 1024, float('inf'), 0.021) # Over 450 TB + ], + # Data transfer in (usually free) + transfer_in_tiers=[ + (0, float('inf'), 0.0) + ], + # Data transfer out tiers + transfer_out_tiers=[ + (0, 1, 0.0), # First 1 GB free + (1, 10 * 1024, 0.09), # Up to 10 TB + (10 * 1024, 50 * 1024, 0.085), # Next 40 TB + (50 * 1024, 150 * 1024, 0.07), # Next 100 TB + (150 * 1024, float('inf'), 0.05) # Over 150 TB + ], + # Request pricing (per 1000) + put_request_price=0.005, + get_request_price=0.0004, + delete_request_price=0.0 +) + +# +pricing['b2'] = S3PricingConfig( + # Storage tiers (GB range min, max, price per GB-month) + storage_tiers=[ + (0, 10, 0), # First 10 GB + (10, float('inf'), 0.0006) + ], + # Data transfer in (usually free) + transfer_in_tiers=[ + (0, float('inf'), 0.0) + ], + # Data transfer out tiers + transfer_out_tiers=[ + (0, float('inf'), 0.01) # Over 150 TB + ], + # Request pricing (per 1000) + put_request_price=0.000, + get_request_price=0.0004, + delete_request_price=0.0 +) + +def main () : + services = ['aws', 'b2'] + service_name = {} + service_name['aws'] = 'Amazon' + service_name['b2'] = 'Back Blaze B2' + + parser = ArgumentParser(description='Simulate s3-like service pricing scenarios') + + parser.add_argument('-f', '--file', default=80, type=int, help='File size (GB)') + parser.add_argument('-c', '--count', default=100, type=int, help='Number of files to simulate') + parser.add_argument('-d', '--downloads', default=10, type=int, help='Number of downloads per file to simulate') + parser.add_argument('-l', '--length', default=30, type=int, help='Length of upload in days') + parser.add_argument('-s', '--service', default='aws', choices=services, type=str, help='File size (GB)') -# Example usage -def run_example(): - # Sample pricing configuration based on approximated AWS S3 Standard pricing - amazon_pricing = S3PricingConfig( - # Storage tiers (GB range min, max, price per GB-month) - storage_tiers=[ - (0, 50 * 1024, 0.023), # First 50 TB - (50 * 1024, 450 * 1024, 0.022), # Next 400 TB - (450 * 1024, float('inf'), 0.021) # Over 450 TB - ], - # Data transfer in (usually free) - transfer_in_tiers=[ - (0, float('inf'), 0.0) - ], - # Data transfer out tiers - transfer_out_tiers=[ - (0, 1, 0.0), # First 1 GB free - (1, 10 * 1024, 0.09), # Up to 10 TB - (10 * 1024, 50 * 1024, 0.085), # Next 40 TB - (50 * 1024, 150 * 1024, 0.07), # Next 100 TB - (150 * 1024, float('inf'), 0.05) # Over 150 TB - ], - # Request pricing (per 1000) - put_request_price=0.005, - get_request_price=0.0004, - delete_request_price=0.0 - ) + args = parser.parse_args() - # - backblaze_pricing = S3PricingConfig( - # Storage tiers (GB range min, max, price per GB-month) - storage_tiers=[ - (0, 10, 0.023), # First 10 GB - (10, float('inf'), 0.0006) - ], - # Data transfer in (usually free) - transfer_in_tiers=[ - (0, float('inf'), 0.0) - ], - # Data transfer out tiers - transfer_out_tiers=[ - (0, float('inf'), 0.01) # Over 150 TB - ], - # Request pricing (per 1000) - put_request_price=0.000, - get_request_price=0.0004, - delete_request_price=0.0 - ) + simulator = S3PricingSimulator(pricing[args.service]) - simulator = S3PricingSimulator(backblaze_pricing) - - # Example scenario: large file stored for 90 days with frequent downloads today = datetime.date.today() large_file = S3Usage( - file_size_gb=80, + file_size_gb=args.file, upload_date=today, - download_count=7, + download_count=args.downloads, delete_date=today + datetime.timedelta(days=15) ) - # A few smaller files with varying lifetimes - usage_list = [ large_file ] * 50 + usage_list = [ large_file ] * args.count - # Run the simulation results = simulator.simulate(usage_list) - # Print the results print("S3 Cost Simulation Results") print("=========================") + print(f"File Size: {args.file}GB") + print(f" Count: {args.count}") + print(f"Downloads: {args.downloads}") + print(f" Service: {service_name[args.service]}") + print("=========================") print(f"Period: {results['simulation_period']['start_date']} to {results['simulation_period']['end_date']}") print("\nStorage Costs:") @@ -264,4 +279,5 @@ def run_example(): if __name__ == "__main__": - run_example() \ No newline at end of file + main() +