age_cache_simulation/aoi_cache_simulation.ipynb

1026 lines
130 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "markdown",
"id": "befdd01f-254a-409c-bcdf-fcd31b023212",
"metadata": {},
"source": [
"# Description\n",
"\n",
"This is a simulation of a Client, Cache, DB setup.\n",
"\n",
"## Client\n",
"The client sends requests to the Cache for certain objects.\n",
"The rate at which the client sends request is ~exp(REQUEST_FREQUENCY).\n",
"The kind of object that are requested follow a Zipf distribution.\n",
"\n",
"## Cache\n",
"The cache is an intermediate storage for the objects.\n",
"It saves the objects, along with their age in the cache and TTL.\n",
"When the TTL is over the object expires from the cache.\n",
"The age of the object describes the \"freshness\" of the object from the point when it was pulled from the database.\n",
"\n",
"The cache regularly refreshes the objects in its database, based on ~exp(mu).\n",
"The mu is a fixed value, individual to each object.\n",
"\n",
"When the client requests an object and it isn't in the cache, a cache miss occurs and the cache has to get the object from the database.\n",
"When the object is in the database at the time the client requests it a cache hit occurs and the TTL of the object is refreshed.\n",
"\n",
"## Database\n",
"The database stores the available objects and provides them to the cache when requested.\n",
"Along with a value, the database also stores the refresh rate mu for each object.\n",
"The refresh rate is used by the cache to periodically refresh the cache information from the database."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "920665b8-9204-42df-ab59-1b9324387750",
"metadata": {},
"outputs": [],
"source": [
"import simpy\n",
"import random\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# Constants\n",
"SEED = 256\n",
"CACHE_TTL = 5 # Cache TTL in seconds\n",
"CACHE_CAPACITY = 100 # Maximum number of objects the cache can hold\n",
"SIMULATION_TIME = 60 # Total time to run the simulation\n",
"REQUEST_FREQUENCY = 1 # Mean time between client requests\n",
"OBJECT_FREQUENCY_LAMBDA = 1 # Shape parameter for the Zipf distribution (controls skewness)\n",
"\n",
"\n",
"# Set random seeds\n",
"random.seed(SEED)\n",
"np.random.seed(SEED)\n",
"\n",
"# Initialize simulation environment\n",
"env = simpy.Environment()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "5cea042f-e9fc-4a1e-9750-de212ca70601",
"metadata": {},
"outputs": [],
"source": [
"class Database:\n",
" def __init__(self):\n",
" # Each object now has a specific refresh rate 'mu'\n",
" self.data = {i: f\"Object {i}\" for i in range(1, CACHE_CAPACITY + 1)}\n",
" self.mu_values = {i: random.uniform(1, 10) for i in range(1, CACHE_CAPACITY + 1)} # Assign a random mu for each object\n",
"\n",
"\n",
" def get_object(self, obj_id):\n",
" print(f\"[{env.now:.2f}] Database: Fetched {self.data.get(obj_id, 'Unknown')} for ID {obj_id}\")\n",
" return self.data.get(obj_id, None)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "499bf543-b2c6-4e4d-afcc-0a6665ce3ae1",
"metadata": {},
"outputs": [],
"source": [
"class Cache:\n",
" def __init__(self, env, db):\n",
" self.env = env\n",
" self.db = db\n",
" self.storage = {} # Dictionary to store cached objects\n",
" self.ttl = {} # Dictionary to store TTLs\n",
" self.age = {} # Dictionary to store age of each object\n",
" self.cache_state_over_time = [] # To record cache state at each interval\n",
" self.hits = {i: 0 for i in range(1, CACHE_CAPACITY + 1)} # Track hits per object\n",
" self.misses = {i: 0 for i in range(1, CACHE_CAPACITY + 1)} # Track misses per object\n",
" self.cumulative_age = {i: 0 for i in range(1, CACHE_CAPACITY + 1)} # Track cumulative age per object\n",
" self.access_count = {i: 0 for i in range(1, CACHE_CAPACITY + 1)} # Track access count per object\n",
" self.next_refresh = {} # Track the next refresh time for each cached object\n",
" \n",
" def get(self, obj_id):\n",
" if obj_id in self.storage and self.ttl[obj_id] > env.now:\n",
" # Cache hit: increment hit count and update cumulative age\n",
" self.hits[obj_id] += 1\n",
" self.cumulative_age[obj_id] += self.age[obj_id]\n",
" self.access_count[obj_id] += 1\n",
" else:\n",
" # Cache miss: increment miss count\n",
" self.misses[obj_id] += 1\n",
" self.access_count[obj_id] += 1\n",
" \n",
" # Fetch the object from the database if its not in cache\n",
" obj = self.db.get_object(obj_id)\n",
" \n",
" # If the cache is full, evict the oldest object\n",
" if len(self.storage) >= CACHE_CAPACITY:\n",
" self.evict_oldest()\n",
" \n",
" # Add the object to cache, set TTL, reset age, and schedule next refresh\n",
" self.storage[obj_id] = obj\n",
" self.ttl[obj_id] = env.now + CACHE_TTL\n",
" self.age[obj_id] = 0\n",
" self.next_refresh[obj_id] = env.now + np.random.exponential(self.db.mu_values[obj_id]) # Schedule refresh\n",
"\n",
" \n",
" def evict_oldest(self):\n",
" \"\"\"Remove the oldest item from the cache to make space.\"\"\"\n",
" oldest_id = max(self.age, key=self.age.get) # Find the oldest item by age\n",
" print(f\"[{env.now:.2f}] Cache: Evicting object {oldest_id} to make space\")\n",
" del self.storage[oldest_id]\n",
" del self.ttl[oldest_id]\n",
" del self.age[oldest_id]\n",
" \n",
" def refresh_object(self, obj_id):\n",
" \"\"\"Refresh the object from the database to keep it up-to-date.\"\"\"\n",
" obj = self.db.get_object(obj_id)\n",
" self.storage[obj_id] = obj\n",
" self.ttl[obj_id] = env.now + CACHE_TTL\n",
" self.age[obj_id] = 0\n",
" print(f\"[{env.now:.2f}] Cache: Refreshed object {obj_id}\")\n",
" \n",
" def age_objects(self):\n",
" \"\"\"Increment age of each cached object.\"\"\"\n",
" for obj_id in list(self.age.keys()):\n",
" if self.ttl[obj_id] > env.now:\n",
" self.age[obj_id] += 1\n",
" print(f\"[{env.now:.2f}] Cache: Object {obj_id} aged to {self.age[obj_id]}\")\n",
" else:\n",
" # Remove object if its TTL expired\n",
" print(f\"[{env.now:.2f}] Cache: Object {obj_id} expired\")\n",
" del self.storage[obj_id]\n",
" del self.ttl[obj_id]\n",
" del self.age[obj_id]\n",
" \n",
" def record_cache_state(self):\n",
" \"\"\"Record the current cache state (number of objects in cache) over time.\"\"\"\n",
" self.cache_state_over_time.append((env.now, len(self.storage)))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "7286d498-aa6c-4efb-bb28-fe29736eab64",
"metadata": {},
"outputs": [],
"source": [
"def age_cache_process(env, cache):\n",
" \"\"\"Process that ages cache objects over time, removes expired items, and refreshes based on object-specific intervals.\"\"\"\n",
" while True:\n",
" cache.age_objects() # Age objects and remove expired ones\n",
"\n",
" # Refresh objects based on their individual refresh intervals\n",
" for obj_id in list(cache.storage.keys()):\n",
" # Check if it's time to refresh this object based on next_refresh\n",
" if env.now >= cache.next_refresh[obj_id]:\n",
" cache.refresh_object(obj_id)\n",
" # Schedule the next refresh based on the object's mu\n",
" cache.next_refresh[obj_id] = env.now + np.random.exponential(cache.db.mu_values[obj_id])\n",
" \n",
" cache.record_cache_state() # Record cache state at each time step\n",
" yield env.timeout(1) # Run every second\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "687f5634-8edf-4337-b42f-bbb292d47f0f",
"metadata": {},
"outputs": [],
"source": [
"def client_request_process(env, cache):\n",
" \"\"\"Client process that makes requests for objects from the cache.\"\"\"\n",
" while True:\n",
" # Use numpy's exponential distribution for request interval\n",
" next_request = np.random.exponential(REQUEST_FREQUENCY)\n",
" yield env.timeout(next_request)\n",
"\n",
" # Use numpy's Zipf distribution to select object ID, reroll if out of bounds\n",
" while True:\n",
" obj_id = np.random.zipf(OBJECT_FREQUENCY_LAMBDA)\n",
" if obj_id <= 100: # Ensure obj_id is within range [1, 100]\n",
" break # Valid obj_id, exit loop\n",
" # If obj_id is out of bounds, reroll (continue the loop)\n",
" \n",
" print(f\"[{env.now:.2f}] Client: Requesting object {obj_id}\")\n",
" cache.get(obj_id)\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "c8516830-9880-4d9e-a91b-000338baf9d6",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0.05] Client: Requesting object 82\n",
"[0.05] Database: Fetched Object 82 for ID 82\n",
"[0.07] Client: Requesting object 13\n",
"[0.07] Database: Fetched Object 13 for ID 13\n",
"[1.00] Cache: Object 82 aged to 1\n",
"[1.00] Cache: Object 13 aged to 1\n",
"[1.00] Database: Fetched Object 82 for ID 82\n",
"[1.00] Cache: Refreshed object 82\n",
"[1.00] Database: Fetched Object 13 for ID 13\n",
"[1.00] Cache: Refreshed object 13\n",
"[1.71] Client: Requesting object 11\n",
"[1.71] Database: Fetched Object 11 for ID 11\n",
"[1.97] Client: Requesting object 1\n",
"[1.97] Database: Fetched Object 1 for ID 1\n",
"[2.00] Cache: Object 82 aged to 1\n",
"[2.00] Cache: Object 13 aged to 1\n",
"[2.00] Cache: Object 11 aged to 1\n",
"[2.00] Cache: Object 1 aged to 1\n",
"[3.00] Cache: Object 82 aged to 2\n",
"[3.00] Cache: Object 13 aged to 2\n",
"[3.00] Cache: Object 11 aged to 2\n",
"[3.00] Cache: Object 1 aged to 2\n",
"[4.00] Cache: Object 82 aged to 3\n",
"[4.00] Cache: Object 13 aged to 3\n",
"[4.00] Cache: Object 11 aged to 3\n",
"[4.00] Cache: Object 1 aged to 3\n",
"[4.00] Database: Fetched Object 13 for ID 13\n",
"[4.00] Cache: Refreshed object 13\n",
"[4.00] Database: Fetched Object 11 for ID 11\n",
"[4.00] Cache: Refreshed object 11\n",
"[4.00] Database: Fetched Object 1 for ID 1\n",
"[4.00] Cache: Refreshed object 1\n",
"[4.49] Client: Requesting object 5\n",
"[4.49] Database: Fetched Object 5 for ID 5\n",
"[4.72] Client: Requesting object 22\n",
"[4.72] Database: Fetched Object 22 for ID 22\n",
"[5.00] Cache: Object 82 aged to 4\n",
"[5.00] Cache: Object 13 aged to 1\n",
"[5.00] Cache: Object 11 aged to 1\n",
"[5.00] Cache: Object 1 aged to 1\n",
"[5.00] Cache: Object 5 aged to 1\n",
"[5.00] Cache: Object 22 aged to 1\n",
"[5.00] Database: Fetched Object 82 for ID 82\n",
"[5.00] Cache: Refreshed object 82\n",
"[6.00] Cache: Object 82 aged to 1\n",
"[6.00] Cache: Object 13 aged to 2\n",
"[6.00] Cache: Object 11 aged to 2\n",
"[6.00] Cache: Object 1 aged to 2\n",
"[6.00] Cache: Object 5 aged to 2\n",
"[6.00] Cache: Object 22 aged to 2\n",
"[6.00] Database: Fetched Object 5 for ID 5\n",
"[6.00] Cache: Refreshed object 5\n",
"[6.00] Client: Requesting object 63\n",
"[6.00] Database: Fetched Object 63 for ID 63\n",
"[6.64] Client: Requesting object 1\n",
"[7.00] Cache: Object 82 aged to 2\n",
"[7.00] Cache: Object 13 aged to 3\n",
"[7.00] Cache: Object 11 aged to 3\n",
"[7.00] Cache: Object 1 aged to 3\n",
"[7.00] Cache: Object 5 aged to 1\n",
"[7.00] Cache: Object 22 aged to 3\n",
"[7.00] Cache: Object 63 aged to 1\n",
"[7.00] Database: Fetched Object 1 for ID 1\n",
"[7.00] Cache: Refreshed object 1\n",
"[7.63] Client: Requesting object 65\n",
"[7.63] Database: Fetched Object 65 for ID 65\n",
"[8.00] Cache: Object 82 aged to 3\n",
"[8.00] Cache: Object 13 aged to 4\n",
"[8.00] Cache: Object 11 aged to 4\n",
"[8.00] Cache: Object 1 aged to 1\n",
"[8.00] Cache: Object 5 aged to 2\n",
"[8.00] Cache: Object 22 aged to 4\n",
"[8.00] Cache: Object 63 aged to 2\n",
"[8.00] Cache: Object 65 aged to 1\n",
"[8.00] Database: Fetched Object 82 for ID 82\n",
"[8.00] Cache: Refreshed object 82\n",
"[8.00] Database: Fetched Object 11 for ID 11\n",
"[8.00] Cache: Refreshed object 11\n",
"[8.40] Client: Requesting object 1\n",
"[9.00] Cache: Object 82 aged to 1\n",
"[9.00] Cache: Object 13 expired\n",
"[9.00] Cache: Object 11 aged to 1\n",
"[9.00] Cache: Object 1 aged to 2\n",
"[9.00] Cache: Object 5 aged to 3\n",
"[9.00] Cache: Object 22 aged to 5\n",
"[9.00] Cache: Object 63 aged to 3\n",
"[9.00] Cache: Object 65 aged to 2\n",
"[9.00] Database: Fetched Object 5 for ID 5\n",
"[9.00] Cache: Refreshed object 5\n",
"[9.00] Database: Fetched Object 22 for ID 22\n",
"[9.00] Cache: Refreshed object 22\n",
"[9.00] Database: Fetched Object 65 for ID 65\n",
"[9.00] Cache: Refreshed object 65\n",
"[9.66] Client: Requesting object 3\n",
"[9.66] Database: Fetched Object 3 for ID 3\n",
"[10.00] Cache: Object 82 aged to 2\n",
"[10.00] Cache: Object 11 aged to 2\n",
"[10.00] Cache: Object 1 aged to 3\n",
"[10.00] Cache: Object 5 aged to 1\n",
"[10.00] Cache: Object 22 aged to 1\n",
"[10.00] Cache: Object 63 aged to 4\n",
"[10.00] Cache: Object 65 aged to 1\n",
"[10.00] Cache: Object 3 aged to 1\n",
"[10.00] Database: Fetched Object 63 for ID 63\n",
"[10.00] Cache: Refreshed object 63\n",
"[10.01] Client: Requesting object 5\n",
"[11.00] Cache: Object 82 aged to 3\n",
"[11.00] Cache: Object 11 aged to 3\n",
"[11.00] Cache: Object 1 aged to 4\n",
"[11.00] Cache: Object 5 aged to 2\n",
"[11.00] Cache: Object 22 aged to 2\n",
"[11.00] Cache: Object 63 aged to 1\n",
"[11.00] Cache: Object 65 aged to 2\n",
"[11.00] Cache: Object 3 aged to 2\n",
"[11.00] Database: Fetched Object 11 for ID 11\n",
"[11.00] Cache: Refreshed object 11\n",
"[11.17] Client: Requesting object 1\n",
"[11.25] Client: Requesting object 31\n",
"[11.25] Database: Fetched Object 31 for ID 31\n",
"[11.69] Client: Requesting object 2\n",
"[11.69] Database: Fetched Object 2 for ID 2\n",
"[12.00] Cache: Object 82 aged to 4\n",
"[12.00] Cache: Object 11 aged to 1\n",
"[12.00] Cache: Object 1 expired\n",
"[12.00] Cache: Object 5 aged to 3\n",
"[12.00] Cache: Object 22 aged to 3\n",
"[12.00] Cache: Object 63 aged to 2\n",
"[12.00] Cache: Object 65 aged to 3\n",
"[12.00] Cache: Object 3 aged to 3\n",
"[12.00] Cache: Object 31 aged to 1\n",
"[12.00] Cache: Object 2 aged to 1\n",
"[12.00] Database: Fetched Object 31 for ID 31\n",
"[12.00] Cache: Refreshed object 31\n",
"[12.50] Client: Requesting object 3\n",
"[13.00] Cache: Object 82 expired\n",
"[13.00] Cache: Object 11 aged to 2\n",
"[13.00] Cache: Object 5 aged to 4\n",
"[13.00] Cache: Object 22 aged to 4\n",
"[13.00] Cache: Object 63 aged to 3\n",
"[13.00] Cache: Object 65 aged to 4\n",
"[13.00] Cache: Object 3 aged to 4\n",
"[13.00] Cache: Object 31 aged to 1\n",
"[13.00] Cache: Object 2 aged to 2\n",
"[13.00] Database: Fetched Object 11 for ID 11\n",
"[13.00] Cache: Refreshed object 11\n",
"[13.52] Client: Requesting object 41\n",
"[13.52] Database: Fetched Object 41 for ID 41\n",
"[13.87] Client: Requesting object 6\n",
"[13.87] Database: Fetched Object 6 for ID 6\n",
"[14.00] Cache: Object 11 aged to 1\n",
"[14.00] Cache: Object 5 expired\n",
"[14.00] Cache: Object 22 expired\n",
"[14.00] Cache: Object 63 aged to 4\n",
"[14.00] Cache: Object 65 expired\n",
"[14.00] Cache: Object 3 aged to 5\n",
"[14.00] Cache: Object 31 aged to 2\n",
"[14.00] Cache: Object 2 aged to 3\n",
"[14.00] Cache: Object 41 aged to 1\n",
"[14.00] Cache: Object 6 aged to 1\n",
"[14.00] Database: Fetched Object 63 for ID 63\n",
"[14.00] Cache: Refreshed object 63\n",
"[14.04] Client: Requesting object 1\n",
"[14.04] Database: Fetched Object 1 for ID 1\n",
"[14.09] Client: Requesting object 2\n",
"[14.56] Client: Requesting object 1\n",
"[15.00] Cache: Object 11 aged to 2\n",
"[15.00] Cache: Object 63 aged to 1\n",
"[15.00] Cache: Object 3 expired\n",
"[15.00] Cache: Object 31 aged to 3\n",
"[15.00] Cache: Object 2 aged to 4\n",
"[15.00] Cache: Object 41 aged to 2\n",
"[15.00] Cache: Object 6 aged to 2\n",
"[15.00] Cache: Object 1 aged to 1\n",
"[15.00] Database: Fetched Object 11 for ID 11\n",
"[15.00] Cache: Refreshed object 11\n",
"[15.00] Database: Fetched Object 31 for ID 31\n",
"[15.00] Cache: Refreshed object 31\n",
"[15.00] Database: Fetched Object 2 for ID 2\n",
"[15.00] Cache: Refreshed object 2\n",
"[15.17] Client: Requesting object 6\n",
"[15.47] Client: Requesting object 2\n",
"[16.00] Cache: Object 11 aged to 1\n",
"[16.00] Cache: Object 63 aged to 2\n",
"[16.00] Cache: Object 31 aged to 1\n",
"[16.00] Cache: Object 2 aged to 1\n",
"[16.00] Cache: Object 41 aged to 3\n",
"[16.00] Cache: Object 6 aged to 3\n",
"[16.00] Cache: Object 1 aged to 2\n",
"[16.00] Database: Fetched Object 31 for ID 31\n",
"[16.00] Cache: Refreshed object 31\n",
"[17.00] Cache: Object 11 aged to 2\n",
"[17.00] Cache: Object 63 aged to 3\n",
"[17.00] Cache: Object 31 aged to 1\n",
"[17.00] Cache: Object 2 aged to 2\n",
"[17.00] Cache: Object 41 aged to 4\n",
"[17.00] Cache: Object 6 aged to 4\n",
"[17.00] Cache: Object 1 aged to 3\n",
"[18.00] Cache: Object 11 aged to 3\n",
"[18.00] Cache: Object 63 aged to 4\n",
"[18.00] Cache: Object 31 aged to 2\n",
"[18.00] Cache: Object 2 aged to 3\n",
"[18.00] Cache: Object 41 aged to 5\n",
"[18.00] Cache: Object 6 aged to 5\n",
"[18.00] Cache: Object 1 aged to 4\n",
"[18.00] Database: Fetched Object 11 for ID 11\n",
"[18.00] Cache: Refreshed object 11\n",
"[19.00] Cache: Object 11 aged to 1\n",
"[19.00] Cache: Object 63 expired\n",
"[19.00] Cache: Object 31 aged to 3\n",
"[19.00] Cache: Object 2 aged to 4\n",
"[19.00] Cache: Object 41 expired\n",
"[19.00] Cache: Object 6 expired\n",
"[19.00] Cache: Object 1 aged to 5\n",
"[19.00] Database: Fetched Object 31 for ID 31\n",
"[19.00] Cache: Refreshed object 31\n",
"[19.02] Client: Requesting object 6\n",
"[19.02] Database: Fetched Object 6 for ID 6\n",
"[20.00] Cache: Object 11 aged to 2\n",
"[20.00] Cache: Object 31 aged to 1\n",
"[20.00] Cache: Object 2 expired\n",
"[20.00] Cache: Object 1 expired\n",
"[20.00] Cache: Object 6 aged to 1\n",
"[20.00] Database: Fetched Object 6 for ID 6\n",
"[20.00] Cache: Refreshed object 6\n",
"[20.38] Client: Requesting object 4\n",
"[20.38] Database: Fetched Object 4 for ID 4\n",
"[20.57] Client: Requesting object 3\n",
"[20.57] Database: Fetched Object 3 for ID 3\n",
"[20.90] Client: Requesting object 15\n",
"[20.90] Database: Fetched Object 15 for ID 15\n",
"[21.00] Cache: Object 11 aged to 3\n",
"[21.00] Cache: Object 31 aged to 2\n",
"[21.00] Cache: Object 6 aged to 1\n",
"[21.00] Cache: Object 4 aged to 1\n",
"[21.00] Cache: Object 3 aged to 1\n",
"[21.00] Cache: Object 15 aged to 1\n",
"[21.00] Database: Fetched Object 11 for ID 11\n",
"[21.00] Cache: Refreshed object 11\n",
"[21.00] Database: Fetched Object 31 for ID 31\n",
"[21.00] Cache: Refreshed object 31\n",
"[21.52] Client: Requesting object 2\n",
"[21.52] Database: Fetched Object 2 for ID 2\n",
"[22.00] Cache: Object 11 aged to 1\n",
"[22.00] Cache: Object 31 aged to 1\n",
"[22.00] Cache: Object 6 aged to 2\n",
"[22.00] Cache: Object 4 aged to 2\n",
"[22.00] Cache: Object 3 aged to 2\n",
"[22.00] Cache: Object 15 aged to 2\n",
"[22.00] Cache: Object 2 aged to 1\n",
"[22.00] Database: Fetched Object 6 for ID 6\n",
"[22.00] Cache: Refreshed object 6\n",
"[22.00] Database: Fetched Object 4 for ID 4\n",
"[22.00] Cache: Refreshed object 4\n",
"[22.00] Database: Fetched Object 15 for ID 15\n",
"[22.00] Cache: Refreshed object 15\n",
"[22.00] Database: Fetched Object 2 for ID 2\n",
"[22.00] Cache: Refreshed object 2\n",
"[23.00] Cache: Object 11 aged to 2\n",
"[23.00] Cache: Object 31 aged to 2\n",
"[23.00] Cache: Object 6 aged to 1\n",
"[23.00] Cache: Object 4 aged to 1\n",
"[23.00] Cache: Object 3 aged to 3\n",
"[23.00] Cache: Object 15 aged to 1\n",
"[23.00] Cache: Object 2 aged to 1\n",
"[23.00] Database: Fetched Object 11 for ID 11\n",
"[23.00] Cache: Refreshed object 11\n",
"[23.00] Database: Fetched Object 6 for ID 6\n",
"[23.00] Cache: Refreshed object 6\n",
"[23.00] Database: Fetched Object 4 for ID 4\n",
"[23.00] Cache: Refreshed object 4\n",
"[23.57] Client: Requesting object 1\n",
"[23.57] Database: Fetched Object 1 for ID 1\n",
"[24.00] Client: Requesting object 1\n",
"[24.00] Cache: Object 11 aged to 1\n",
"[24.00] Cache: Object 31 aged to 3\n",
"[24.00] Cache: Object 6 aged to 1\n",
"[24.00] Cache: Object 4 aged to 1\n",
"[24.00] Cache: Object 3 aged to 4\n",
"[24.00] Cache: Object 15 aged to 2\n",
"[24.00] Cache: Object 2 aged to 2\n",
"[24.00] Cache: Object 1 aged to 1\n",
"[24.00] Database: Fetched Object 4 for ID 4\n",
"[24.00] Cache: Refreshed object 4\n",
"[24.00] Database: Fetched Object 3 for ID 3\n",
"[24.00] Cache: Refreshed object 3\n",
"[24.00] Database: Fetched Object 2 for ID 2\n",
"[24.00] Cache: Refreshed object 2\n",
"[25.00] Cache: Object 11 aged to 2\n",
"[25.00] Cache: Object 31 aged to 4\n",
"[25.00] Cache: Object 6 aged to 2\n",
"[25.00] Cache: Object 4 aged to 1\n",
"[25.00] Cache: Object 3 aged to 1\n",
"[25.00] Cache: Object 15 aged to 3\n",
"[25.00] Cache: Object 2 aged to 1\n",
"[25.00] Cache: Object 1 aged to 2\n",
"[25.00] Database: Fetched Object 4 for ID 4\n",
"[25.00] Cache: Refreshed object 4\n",
"[25.32] Client: Requesting object 3\n",
"[25.41] Client: Requesting object 1\n",
"[26.00] Cache: Object 11 aged to 3\n",
"[26.00] Cache: Object 31 expired\n",
"[26.00] Cache: Object 6 aged to 3\n",
"[26.00] Cache: Object 4 aged to 1\n",
"[26.00] Cache: Object 3 aged to 2\n",
"[26.00] Cache: Object 15 aged to 4\n",
"[26.00] Cache: Object 2 aged to 2\n",
"[26.00] Cache: Object 1 aged to 3\n",
"[26.00] Database: Fetched Object 11 for ID 11\n",
"[26.00] Cache: Refreshed object 11\n",
"[26.40] Client: Requesting object 2\n",
"[27.00] Cache: Object 11 aged to 1\n",
"[27.00] Cache: Object 6 aged to 4\n",
"[27.00] Cache: Object 4 aged to 2\n",
"[27.00] Cache: Object 3 aged to 3\n",
"[27.00] Cache: Object 15 expired\n",
"[27.00] Cache: Object 2 aged to 3\n",
"[27.00] Cache: Object 1 aged to 4\n",
"[27.00] Database: Fetched Object 11 for ID 11\n",
"[27.00] Cache: Refreshed object 11\n",
"[27.00] Database: Fetched Object 6 for ID 6\n",
"[27.00] Cache: Refreshed object 6\n",
"[27.37] Client: Requesting object 20\n",
"[27.37] Database: Fetched Object 20 for ID 20\n",
"[27.73] Client: Requesting object 6\n",
"[27.82] Client: Requesting object 13\n",
"[27.82] Database: Fetched Object 13 for ID 13\n",
"[28.00] Cache: Object 11 aged to 1\n",
"[28.00] Cache: Object 6 aged to 1\n",
"[28.00] Cache: Object 4 aged to 3\n",
"[28.00] Cache: Object 3 aged to 4\n",
"[28.00] Cache: Object 2 aged to 4\n",
"[28.00] Cache: Object 1 aged to 5\n",
"[28.00] Cache: Object 20 aged to 1\n",
"[28.00] Cache: Object 13 aged to 1\n",
"[28.00] Database: Fetched Object 4 for ID 4\n",
"[28.00] Cache: Refreshed object 4\n",
"[28.00] Database: Fetched Object 3 for ID 3\n",
"[28.00] Cache: Refreshed object 3\n",
"[28.00] Database: Fetched Object 1 for ID 1\n",
"[28.00] Cache: Refreshed object 1\n",
"[28.37] Client: Requesting object 1\n",
"[29.00] Cache: Object 11 aged to 2\n",
"[29.00] Cache: Object 6 aged to 2\n",
"[29.00] Cache: Object 4 aged to 1\n",
"[29.00] Cache: Object 3 aged to 1\n",
"[29.00] Cache: Object 2 expired\n",
"[29.00] Cache: Object 1 aged to 1\n",
"[29.00] Cache: Object 20 aged to 2\n",
"[29.00] Cache: Object 13 aged to 2\n",
"[29.00] Database: Fetched Object 6 for ID 6\n",
"[29.00] Cache: Refreshed object 6\n",
"[29.00] Database: Fetched Object 4 for ID 4\n",
"[29.00] Cache: Refreshed object 4\n",
"[30.00] Cache: Object 11 aged to 3\n",
"[30.00] Cache: Object 6 aged to 1\n",
"[30.00] Cache: Object 4 aged to 1\n",
"[30.00] Cache: Object 3 aged to 2\n",
"[30.00] Cache: Object 1 aged to 2\n",
"[30.00] Cache: Object 20 aged to 3\n",
"[30.00] Cache: Object 13 aged to 3\n",
"[30.00] Database: Fetched Object 6 for ID 6\n",
"[30.00] Cache: Refreshed object 6\n",
"[30.00] Database: Fetched Object 4 for ID 4\n",
"[30.00] Cache: Refreshed object 4\n",
"[30.00] Database: Fetched Object 3 for ID 3\n",
"[30.00] Cache: Refreshed object 3\n",
"[30.00] Database: Fetched Object 13 for ID 13\n",
"[30.00] Cache: Refreshed object 13\n",
"[30.01] Client: Requesting object 1\n",
"[30.95] Client: Requesting object 88\n",
"[30.95] Database: Fetched Object 88 for ID 88\n",
"[31.00] Cache: Object 11 aged to 4\n",
"[31.00] Cache: Object 6 aged to 1\n",
"[31.00] Cache: Object 4 aged to 1\n",
"[31.00] Cache: Object 3 aged to 1\n",
"[31.00] Cache: Object 1 aged to 3\n",
"[31.00] Cache: Object 20 aged to 4\n",
"[31.00] Cache: Object 13 aged to 1\n",
"[31.00] Cache: Object 88 aged to 1\n",
"[31.00] Database: Fetched Object 11 for ID 11\n",
"[31.00] Cache: Refreshed object 11\n",
"[31.00] Database: Fetched Object 20 for ID 20\n",
"[31.00] Cache: Refreshed object 20\n",
"[31.48] Client: Requesting object 4\n",
"[32.00] Cache: Object 11 aged to 1\n",
"[32.00] Cache: Object 6 aged to 2\n",
"[32.00] Cache: Object 4 aged to 2\n",
"[32.00] Cache: Object 3 aged to 2\n",
"[32.00] Cache: Object 1 aged to 4\n",
"[32.00] Cache: Object 20 aged to 1\n",
"[32.00] Cache: Object 13 aged to 2\n",
"[32.00] Cache: Object 88 aged to 2\n",
"[32.00] Database: Fetched Object 11 for ID 11\n",
"[32.00] Cache: Refreshed object 11\n",
"[32.00] Database: Fetched Object 20 for ID 20\n",
"[32.00] Cache: Refreshed object 20\n",
"[33.00] Cache: Object 11 aged to 1\n",
"[33.00] Cache: Object 6 aged to 3\n",
"[33.00] Cache: Object 4 aged to 3\n",
"[33.00] Cache: Object 3 aged to 3\n",
"[33.00] Cache: Object 1 expired\n",
"[33.00] Cache: Object 20 aged to 1\n",
"[33.00] Cache: Object 13 aged to 3\n",
"[33.00] Cache: Object 88 aged to 3\n",
"[33.00] Database: Fetched Object 20 for ID 20\n",
"[33.00] Cache: Refreshed object 20\n",
"[34.00] Cache: Object 11 aged to 2\n",
"[34.00] Cache: Object 6 aged to 4\n",
"[34.00] Cache: Object 4 aged to 4\n",
"[34.00] Cache: Object 3 aged to 4\n",
"[34.00] Cache: Object 20 aged to 1\n",
"[34.00] Cache: Object 13 aged to 4\n",
"[34.00] Cache: Object 88 aged to 4\n",
"[34.00] Database: Fetched Object 4 for ID 4\n",
"[34.00] Cache: Refreshed object 4\n",
"[34.00] Database: Fetched Object 3 for ID 3\n",
"[34.00] Cache: Refreshed object 3\n",
"[34.00] Database: Fetched Object 13 for ID 13\n",
"[34.00] Cache: Refreshed object 13\n",
"[34.63] Client: Requesting object 1\n",
"[34.63] Database: Fetched Object 1 for ID 1\n",
"[35.00] Cache: Object 11 aged to 3\n",
"[35.00] Cache: Object 6 expired\n",
"[35.00] Cache: Object 4 aged to 1\n",
"[35.00] Cache: Object 3 aged to 1\n",
"[35.00] Cache: Object 20 aged to 2\n",
"[35.00] Cache: Object 13 aged to 1\n",
"[35.00] Cache: Object 88 aged to 5\n",
"[35.00] Cache: Object 1 aged to 1\n",
"[35.00] Database: Fetched Object 4 for ID 4\n",
"[35.00] Cache: Refreshed object 4\n",
"[36.00] Cache: Object 11 aged to 4\n",
"[36.00] Cache: Object 4 aged to 1\n",
"[36.00] Cache: Object 3 aged to 2\n",
"[36.00] Cache: Object 20 aged to 3\n",
"[36.00] Cache: Object 13 aged to 2\n",
"[36.00] Cache: Object 88 expired\n",
"[36.00] Cache: Object 1 aged to 2\n",
"[36.00] Database: Fetched Object 4 for ID 4\n",
"[36.00] Cache: Refreshed object 4\n",
"[37.00] Cache: Object 11 expired\n",
"[37.00] Cache: Object 4 aged to 1\n",
"[37.00] Cache: Object 3 aged to 3\n",
"[37.00] Cache: Object 20 aged to 4\n",
"[37.00] Cache: Object 13 aged to 3\n",
"[37.00] Cache: Object 1 aged to 3\n",
"[37.54] Client: Requesting object 3\n",
"[37.61] Client: Requesting object 36\n",
"[37.61] Database: Fetched Object 36 for ID 36\n",
"[37.81] Client: Requesting object 32\n",
"[37.81] Database: Fetched Object 32 for ID 32\n",
"[37.93] Client: Requesting object 5\n",
"[37.93] Database: Fetched Object 5 for ID 5\n",
"[38.00] Cache: Object 4 aged to 2\n",
"[38.00] Cache: Object 3 aged to 4\n",
"[38.00] Cache: Object 20 expired\n",
"[38.00] Cache: Object 13 aged to 4\n",
"[38.00] Cache: Object 1 aged to 4\n",
"[38.00] Cache: Object 36 aged to 1\n",
"[38.00] Cache: Object 32 aged to 1\n",
"[38.00] Cache: Object 5 aged to 1\n",
"[38.00] Database: Fetched Object 4 for ID 4\n",
"[38.00] Cache: Refreshed object 4\n",
"[38.36] Client: Requesting object 1\n",
"[39.00] Cache: Object 4 aged to 1\n",
"[39.00] Cache: Object 3 expired\n",
"[39.00] Cache: Object 13 expired\n",
"[39.00] Cache: Object 1 aged to 5\n",
"[39.00] Cache: Object 36 aged to 2\n",
"[39.00] Cache: Object 32 aged to 2\n",
"[39.00] Cache: Object 5 aged to 2\n",
"[39.00] Database: Fetched Object 4 for ID 4\n",
"[39.00] Cache: Refreshed object 4\n",
"[39.39] Client: Requesting object 5\n",
"[40.00] Cache: Object 4 aged to 1\n",
"[40.00] Cache: Object 1 expired\n",
"[40.00] Cache: Object 36 aged to 3\n",
"[40.00] Cache: Object 32 aged to 3\n",
"[40.00] Cache: Object 5 aged to 3\n",
"[40.00] Database: Fetched Object 36 for ID 36\n",
"[40.00] Cache: Refreshed object 36\n",
"[41.00] Cache: Object 4 aged to 2\n",
"[41.00] Cache: Object 36 aged to 1\n",
"[41.00] Cache: Object 32 aged to 4\n",
"[41.00] Cache: Object 5 aged to 4\n",
"[41.00] Database: Fetched Object 5 for ID 5\n",
"[41.00] Cache: Refreshed object 5\n",
"[41.49] Client: Requesting object 1\n",
"[41.49] Database: Fetched Object 1 for ID 1\n",
"[41.82] Client: Requesting object 1\n",
"[42.00] Cache: Object 4 aged to 3\n",
"[42.00] Cache: Object 36 aged to 2\n",
"[42.00] Cache: Object 32 aged to 5\n",
"[42.00] Cache: Object 5 aged to 1\n",
"[42.00] Cache: Object 1 aged to 1\n",
"[42.00] Database: Fetched Object 36 for ID 36\n",
"[42.00] Cache: Refreshed object 36\n",
"[42.79] Client: Requesting object 1\n",
"[43.00] Cache: Object 4 aged to 4\n",
"[43.00] Cache: Object 36 aged to 1\n",
"[43.00] Cache: Object 32 expired\n",
"[43.00] Cache: Object 5 aged to 2\n",
"[43.00] Cache: Object 1 aged to 2\n",
"[43.00] Database: Fetched Object 1 for ID 1\n",
"[43.00] Cache: Refreshed object 1\n",
"[44.00] Cache: Object 4 expired\n",
"[44.00] Cache: Object 36 aged to 2\n",
"[44.00] Cache: Object 5 aged to 3\n",
"[44.00] Cache: Object 1 aged to 1\n",
"[44.00] Database: Fetched Object 36 for ID 36\n",
"[44.00] Cache: Refreshed object 36\n",
"[44.00] Database: Fetched Object 5 for ID 5\n",
"[44.00] Cache: Refreshed object 5\n",
"[44.12] Client: Requesting object 3\n",
"[44.12] Database: Fetched Object 3 for ID 3\n",
"[44.45] Client: Requesting object 5\n",
"[45.00] Cache: Object 36 aged to 1\n",
"[45.00] Cache: Object 5 aged to 1\n",
"[45.00] Cache: Object 1 aged to 2\n",
"[45.00] Cache: Object 3 aged to 1\n",
"[45.00] Database: Fetched Object 36 for ID 36\n",
"[45.00] Cache: Refreshed object 36\n",
"[45.25] Client: Requesting object 7\n",
"[45.25] Database: Fetched Object 7 for ID 7\n",
"[45.54] Client: Requesting object 2\n",
"[45.54] Database: Fetched Object 2 for ID 2\n",
"[46.00] Cache: Object 36 aged to 1\n",
"[46.00] Cache: Object 5 aged to 2\n",
"[46.00] Cache: Object 1 aged to 3\n",
"[46.00] Cache: Object 3 aged to 2\n",
"[46.00] Cache: Object 7 aged to 1\n",
"[46.00] Cache: Object 2 aged to 1\n",
"[46.97] Client: Requesting object 6\n",
"[46.97] Database: Fetched Object 6 for ID 6\n",
"[47.00] Cache: Object 36 aged to 2\n",
"[47.00] Cache: Object 5 aged to 3\n",
"[47.00] Cache: Object 1 aged to 4\n",
"[47.00] Cache: Object 3 aged to 3\n",
"[47.00] Cache: Object 7 aged to 2\n",
"[47.00] Cache: Object 2 aged to 2\n",
"[47.00] Cache: Object 6 aged to 1\n",
"[47.00] Database: Fetched Object 1 for ID 1\n",
"[47.00] Cache: Refreshed object 1\n",
"[47.50] Client: Requesting object 2\n",
"[48.00] Cache: Object 36 aged to 3\n",
"[48.00] Cache: Object 5 aged to 4\n",
"[48.00] Cache: Object 1 aged to 1\n",
"[48.00] Cache: Object 3 aged to 4\n",
"[48.00] Cache: Object 7 aged to 3\n",
"[48.00] Cache: Object 2 aged to 3\n",
"[48.00] Cache: Object 6 aged to 2\n",
"[48.00] Database: Fetched Object 3 for ID 3\n",
"[48.00] Cache: Refreshed object 3\n",
"[48.00] Database: Fetched Object 2 for ID 2\n",
"[48.00] Cache: Refreshed object 2\n",
"[49.00] Cache: Object 36 aged to 4\n",
"[49.00] Cache: Object 5 expired\n",
"[49.00] Cache: Object 1 aged to 2\n",
"[49.00] Cache: Object 3 aged to 1\n",
"[49.00] Cache: Object 7 aged to 4\n",
"[49.00] Cache: Object 2 aged to 1\n",
"[49.00] Cache: Object 6 aged to 3\n",
"[49.00] Database: Fetched Object 2 for ID 2\n",
"[49.00] Cache: Refreshed object 2\n",
"[49.93] Client: Requesting object 1\n",
"[50.00] Cache: Object 36 expired\n",
"[50.00] Cache: Object 1 aged to 3\n",
"[50.00] Cache: Object 3 aged to 2\n",
"[50.00] Cache: Object 7 aged to 5\n",
"[50.00] Cache: Object 2 aged to 1\n",
"[50.00] Cache: Object 6 aged to 4\n",
"[50.00] Database: Fetched Object 7 for ID 7\n",
"[50.00] Cache: Refreshed object 7\n",
"[50.00] Database: Fetched Object 2 for ID 2\n",
"[50.00] Cache: Refreshed object 2\n",
"[51.00] Cache: Object 1 aged to 4\n",
"[51.00] Cache: Object 3 aged to 3\n",
"[51.00] Cache: Object 7 aged to 1\n",
"[51.00] Cache: Object 2 aged to 1\n",
"[51.00] Cache: Object 6 aged to 5\n",
"[51.00] Database: Fetched Object 7 for ID 7\n",
"[51.00] Cache: Refreshed object 7\n",
"[51.27] Client: Requesting object 6\n",
"[52.00] Cache: Object 1 expired\n",
"[52.00] Cache: Object 3 aged to 4\n",
"[52.00] Cache: Object 7 aged to 1\n",
"[52.00] Cache: Object 2 aged to 2\n",
"[52.00] Cache: Object 6 expired\n",
"[53.00] Cache: Object 3 expired\n",
"[53.00] Cache: Object 7 aged to 2\n",
"[53.00] Cache: Object 2 aged to 3\n",
"[53.04] Client: Requesting object 5\n",
"[53.04] Database: Fetched Object 5 for ID 5\n",
"[53.78] Client: Requesting object 29\n",
"[53.78] Database: Fetched Object 29 for ID 29\n",
"[54.00] Cache: Object 7 aged to 3\n",
"[54.00] Cache: Object 2 aged to 4\n",
"[54.00] Cache: Object 5 aged to 1\n",
"[54.00] Cache: Object 29 aged to 1\n",
"[54.89] Client: Requesting object 2\n",
"[55.00] Cache: Object 7 aged to 4\n",
"[55.00] Cache: Object 2 expired\n",
"[55.00] Cache: Object 5 aged to 2\n",
"[55.00] Cache: Object 29 aged to 2\n",
"[55.03] Client: Requesting object 12\n",
"[55.03] Database: Fetched Object 12 for ID 12\n",
"[56.00] Cache: Object 7 expired\n",
"[56.00] Cache: Object 5 aged to 3\n",
"[56.00] Cache: Object 29 aged to 3\n",
"[56.00] Cache: Object 12 aged to 1\n",
"[56.34] Client: Requesting object 17\n",
"[56.34] Database: Fetched Object 17 for ID 17\n",
"[56.82] Client: Requesting object 54\n",
"[56.82] Database: Fetched Object 54 for ID 54\n",
"[57.00] Cache: Object 5 aged to 4\n",
"[57.00] Cache: Object 29 aged to 4\n",
"[57.00] Cache: Object 12 aged to 2\n",
"[57.00] Cache: Object 17 aged to 1\n",
"[57.00] Cache: Object 54 aged to 1\n",
"[57.00] Database: Fetched Object 29 for ID 29\n",
"[57.00] Cache: Refreshed object 29\n",
"[57.00] Database: Fetched Object 12 for ID 12\n",
"[57.00] Cache: Refreshed object 12\n",
"[58.00] Cache: Object 5 aged to 5\n",
"[58.00] Cache: Object 29 aged to 1\n",
"[58.00] Cache: Object 12 aged to 1\n",
"[58.00] Cache: Object 17 aged to 2\n",
"[58.00] Cache: Object 54 aged to 2\n",
"[58.00] Database: Fetched Object 12 for ID 12\n",
"[58.00] Cache: Refreshed object 12\n",
"[58.50] Client: Requesting object 13\n",
"[58.50] Database: Fetched Object 13 for ID 13\n",
"[59.00] Cache: Object 5 expired\n",
"[59.00] Cache: Object 29 aged to 2\n",
"[59.00] Cache: Object 12 aged to 1\n",
"[59.00] Cache: Object 17 aged to 3\n",
"[59.00] Cache: Object 54 aged to 3\n",
"[59.00] Cache: Object 13 aged to 1\n",
"[59.00] Database: Fetched Object 17 for ID 17\n",
"[59.00] Cache: Refreshed object 17\n",
"[59.52] Client: Requesting object 5\n",
"[59.52] Database: Fetched Object 5 for ID 5\n"
]
}
],
"source": [
"# Instantiate components\n",
"db = Database()\n",
"cache = Cache(env, db)\n",
"\n",
"# Start processes\n",
"env.process(age_cache_process(env, cache))\n",
"env.process(client_request_process(env, cache))\n",
"\n",
"# Run the simulation\n",
"env.run(until=SIMULATION_TIME)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "3b6f7c1f-ea54-4496-bb9a-370cee2d2751",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Object 1: Hit Rate = 0.71, Average Age = 1.50\n",
"Object 2: Hit Rate = 0.62, Average Age = 2.20\n",
"Object 3: Hit Rate = 0.50, Average Age = 2.33\n",
"Object 4: Hit Rate = 0.50, Average Age = 1.00\n",
"Object 5: Hit Rate = 0.43, Average Age = 1.00\n",
"Object 6: Hit Rate = 0.50, Average Age = 2.33\n"
]
}
],
"source": [
"# Calculate and print hit rate and average age for each object\n",
"for obj_id in range(1, CACHE_CAPACITY + 1):\n",
" if cache.hits[obj_id] != 0:\n",
" hit_rate = cache.hits[obj_id] / max(1, cache.access_count[obj_id]) # Avoid division by zero\n",
" avg_age = cache.cumulative_age[obj_id] / max(1, cache.hits[obj_id]) # Only average over hits\n",
" print(f\"Object {obj_id}: Hit Rate = {hit_rate:.2f}, Average Age = {avg_age:.2f}\")\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "01f8f9ee-c278-4a22-8562-ba02e77f5ddd",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAACU8AAAHWCAYAAABNZ+o8AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy80BEi2AAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOzdd3QU9dvG4c/upvcECCWE3nsJQUBAUcSGiChNCIEAIvb6sysqCiqK2GghEBALClYEwQIoSAi9995DIL3uzvtHJK9IkUCS2ST3dY7nmNnZ79yzWYZl99nnsRiGYSAiIiIiIiIiIiIiIiIiIiIiIlLGWM0OICIiIiIiIiIiIiIiIiIiIiIiYgYVT4mIiIiIiIiIiIiIiIiIiIiISJmk4ikRERERERERERERERERERERESmTVDwlIiIiIiIiIiIiIiIiIiIiIiJlkoqnRERERERERERERERERERERESkTFLxlIiIiIiIiIiIiIiIiIiIiIiIlEkqnhIRERERERERERERERERERERkTJJxVMiIiIiIiIiIiIiIiIiIiIiIlImqXhKRERERERERERERERERERERETKJBVPiYiIiIiIiEip9/vvv2OxWPjqq6/MjnJZjh8/zt133025cuWwWCyMHz++0Nbet28fFouFd9555z/3feWVV7BYLIV27OJgsVh45ZVXzI5RKCwWCw8++KDZMUq0GjVqEBkZaXYMEREREREREXFiKp4SERERERERkUIxffp0LBYLHh4eHD58+Lzbr7vuOpo0aWJCspLnscceY+HChTz77LPMnDmTm2+++ZL7p6Wl8dprr9GsWTO8vLzw9/enY8eOxMbGYhhGMaUuuPnz55eYQqfff/+du+66i0qVKuHm5kZwcDDdu3dn7ty5ZkcrFDk5OUyYMIE2bdrg6+uLj48Pbdq0YcKECeTk5JgdL9/ZQsjL+U9ERERERERE5HK4mB1AREREREREREqXrKwsxowZwwcffGB2lBLr119/pUePHjz55JP/ue/x48e54YYb2Lp1K3379uXBBx8kMzOTr7/+mkGDBjF//nw+/fRTbDZbgXO88MILPPPMM1dyCpdl/vz5fPTRR4VaQJWRkYGLS+G+5fXyyy/z6quvUrduXe677z6qV6/OqVOnmD9/Pr169eLTTz+lf//+hXrM4pSWlsZtt93GkiVLuP3224mMjMRqtbJgwQIeeeQR5s6dy48//oi3t7fZUWnYsCEzZ848Z9uzzz6Lj48Pzz///Hn7b9++HatV3x8VERERERERkYtT8ZSIiIiIiIiIFKoWLVowZcoUnn32WapUqWJ2nGKVlpZWKAUmJ06cICAg4LL2HTRoEFu3bmXevHnccccd+dsffvhhnnrqKd555x1atmzJ//73vwLncHFxKfRCpKLm4eFRqOt99dVXvPrqq9x9993Mnj0bV1fX/NueeuopFi5c6FSdma7E448/zpIlS/jggw/OGRN4//3389FHH/Hggw/y5JNP8sknnxRbJsMwyMzMxNPT85ztFStWZMCAAedsGzNmDOXLlz9vO4C7u3uR5hQRERERERGRkk9fuxIRERERERGRQvXcc89ht9sZM2bMJffbt28fFouF6dOnn3ebxWI5pxvRK6+8gsViYceOHQwYMAB/f38qVKjAiy++iGEYHDx4kB49euDn50elSpUYN27cBY9pt9t57rnnqFSpEt7e3txxxx0cPHjwvP1WrlzJzTffjL+/P15eXnTu3Jk///zznH3OZtqyZQv9+/cnMDCQa6+99pLnvGfPHu655x6CgoLw8vLimmuu4ccff8y//ezoQ8Mw+Oijj/5z/Nhff/3FwoULiYyMPKdw6qw333yTunXrMnbsWDIyMs67/b333qN69ep4enrSuXNnNm3adMFz/LdZs2bRunVrPD09CQoKom/fvhd9HG+99VYCAwPx9vamWbNmvP/++wBERkby0UcfAVxw1Nrnn39O69at8fX1xc/Pj6ZNm+bf91Iu9tzZtWsXkZGRBAQE4O/vz+DBg0lPT//P9V588UWCgoKYNm3aOYVTZ3Xr1o3bb78dgOzsbF566SVat26Nv78/3t7edOzYkd9+++28+zkcDt5//32aNm2Kh4cHFSpU4OabbyY+Pv68fb/55huaNGmCu7s7jRs3ZsGCBeftc/jwYYYMGULFihXz95s2bdp/nt+hQ4eIjo6mS5cu5xROnfXAAw9w/fXXM3XqVA4dOgRAkyZNuP766y94TiEhIdx9993nbBs/fjyNGzfGw8ODihUrct9993H69Olz7lujRg1uv/12Fi5cSFhYGJ6enkyaNOk/8/+XGjVqEBkZmf/z2T9jf/zxBw8//DAVKlQgICCA++67j+zsbM6cOUNERASBgYEEBgby9NNPnzf68nLPSURERERERERKBhVPiYiIiIiIiEihqlmzJhEREUyZMoUjR44U6tp9+vTB4XAwZswY2rZty+uvv8748ePp2rUrISEhjB07ljp16vDkk0+ydOnS8+4/evRofvzxR/73v//x8MMPs2jRIm688cZzCot+/fVXOnXqRHJyMi+//DJvvPEGZ86coUuXLsTFxZ235j333EN6ejpvvPEGw4YNu2j248eP0759exYuXMjIkSMZPXo0mZmZ3HHHHcybNw+ATp065Y8k69q1KzNnzjxvRNk/ff/99wBERERc8HYXFxf69+/P6dOnzyv+io2NZcKECTzwwAM8++yzbNq0iS5dunD8+PGLHg/yHsOIiAjq1q3Lu+++y6OPPsovv/xCp06dOHPmTP5+ixYtolOnTmzZsoVHHnmEcePGcf311/PDDz8AcN9999G1a1eA/PM8e66LFi2iX79+BAYGMnbsWMaMGcN111133jkURO/evUlJSeHNN9+kd+/eTJ8+nVGjRl3yPjt37mTbtm3ceeed+Pr6/ucxkpOTmTp1Ktdddx1jx47llVde4eTJk3Tr1o1169ads29UVBSPPvoooaGhjB07lmeeeQYPDw/++uuvc/b7448/GDlyJH379uWtt94iMzOTXr16cerUqfx9jh8/zjXXXMPixYt58MEHef/996lTpw5RUVGMHz/+kpl/+ukn7Hb7RZ9DkPf8ys3NzS/a6tOnD0uXLuXYsWPnZT1y5Ah9+/bN33bffffx1FNP0aFDB95//30GDx7Mp59+Srdu3c7r2LV9+3b69etH165def/992nRosUls1+Nhx56iJ07dzJq1CjuuOMOJk+ezIsvvkj37t2x2+288cYbXHvttbz99tvn/RksyDmJiIiIiIiISAlgiIiIiIiIiIgUgpiYGAMwVq1aZezevdtwcXExHn744fzbO3fubDRu3Dj/57179xqAERMTc95agPHyyy/n//zyyy8bgDF8+PD8bbm5uUbVqlUNi8VijBkzJn/76dOnDU9PT2PQoEH523777TcDMEJCQozk5OT87V9++aUBGO+//75hGIbhcDiMunXrGt26dTMcDkf+funp6UbNmjWNrl27npepX79+l/X4PProowZgLFu2LH9bSkqKUbNmTaNGjRqG3W4/5/wfeOCB/1zzzjvvNADj9OnTF91n7ty5BmBMmDDBMIz/f9w9PT2NQ4cO5e+3cuVKAzAee+yx887xrH379hk2m80YPXr0OcfYuHGj4eLikr89NzfXqFmzplG9evXzsv3zcX3ggQeMC7099cgjjxh+fn5Gbm7ufz4G/3ax586QIUPO2a9nz55GuXLlLrnWt99+awDGe++9d1nHzs3NNbKyss7Zdvr0aaNixYrnHP/XX381gHP+fJz1z8cHMNzc3Ixdu3blb1u/fr0BGB988EH+tqioKKNy5cpGQkLCOWv17dvX8Pf3N9LT0y+a+ezzcu3atRfdZ82aNQZgPP7444ZhGMb27dvPy2AYhjFy5EjDx8cn/3jLli0zAOPTTz89Z78FCxact7169eoGYCxYsOCiOS6mcePGRufOnS94W/Xq1c+5Fpy9Tv37z3i7du0Mi8VijBgxIn/b2WvMP9cuyDmJiIiIiIiISMmgzlMiIiIiIiIiUuhq1arFwIEDmTx5MkePHi20dYc
"text/plain": [
"<Figure size 3000x500 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Extract recorded data for plotting\n",
"times, cache_sizes = zip(*cache.cache_state_over_time)\n",
"\n",
"# Plot the cache size over time\n",
"plt.figure(figsize=(30, 5))\n",
"plt.plot(times, cache_sizes, label=\"Objects in Cache\")\n",
"plt.xlabel(\"Time (s)\")\n",
"plt.ylabel(\"Number of Cached Objects\")\n",
"plt.title(\"Number of Objects in Cache Over Time\")\n",
"plt.legend()\n",
"plt.grid(True)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "99cac143-ef09-4205-a73e-8816eecc9a1e",
"metadata": {},
"source": [
"Object 1: Hit Rate = 0.99, Average Age = 0.00\n",
"Object 2: Hit Rate = 0.97, Average Age = 0.55\n",
"Object 3: Hit Rate = 0.96, Average Age = 0.87\n",
"Object 4: Hit Rate = 0.94, Average Age = 1.24\n",
"Object 5: Hit Rate = 0.18, Average Age = 2.33\n",
"Object 6: Hit Rate = 0.09, Average Age = 4.00\n",
"Object 9: Hit Rate = 0.25, Average Age = 2.33\n",
"Object 10: Hit Rate = 0.08, Average Age = 0.00\n",
"Object 11: Hit Rate = 0.25, Average Age = 1.00\n",
"Object 12: Hit Rate = 0.29, Average Age = 1.00"
]
},
{
"cell_type": "markdown",
"id": "88918958-f883-4a67-8212-31a8c9355634",
"metadata": {},
"source": [
"Object 1: Hit Rate = 0.99, Average Age = 0.00\n",
"Object 2: Hit Rate = 0.97, Average Age = 0.56\n",
"Object 3: Hit Rate = 0.96, Average Age = 0.78\n",
"Object 4: Hit Rate = 0.92, Average Age = 1.83\n",
"Object 5: Hit Rate = 0.14, Average Age = 0.00\n",
"Object 7: Hit Rate = 0.29, Average Age = 2.00\n",
"Object 24: Hit Rate = 0.50, Average Age = 1.00\n",
"Object 44: Hit Rate = 0.33, Average Age = 1.00"
]
},
{
"cell_type": "markdown",
"id": "3d911168-f981-4552-8d7d-99a47916312f",
"metadata": {},
"source": [
"Object 1: Hit Rate = 0.99, Average Age = 0.00\n",
"Object 2: Hit Rate = 0.97, Average Age = 0.42\n",
"Object 3: Hit Rate = 0.95, Average Age = 1.38\n",
"Object 4: Hit Rate = 0.96, Average Age = 1.44\n",
"Object 7: Hit Rate = 0.33, Average Age = 3.20\n",
"Object 23: Hit Rate = 0.50, Average Age = 1.00"
]
},
{
"cell_type": "markdown",
"id": "536e087f-3992-4192-b5da-62c496df2741",
"metadata": {},
"source": [
"Object 1: Hit Rate = 0.99, Average Age = 0.00\n",
"Object 2: Hit Rate = 0.97, Average Age = 0.65\n",
"Object 3: Hit Rate = 0.96, Average Age = 0.81\n",
"Object 4: Hit Rate = 0.91, Average Age = 1.90\n",
"Object 5: Hit Rate = 0.08, Average Age = 3.00\n",
"Object 6: Hit Rate = 0.12, Average Age = 3.50\n",
"Object 7: Hit Rate = 0.12, Average Age = 3.00\n",
"Object 15: Hit Rate = 0.33, Average Age = 4.00\n",
"Object 65: Hit Rate = 0.50, Average Age = 0.00"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "graphs",
"language": "python",
"name": "graphs"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}