2024-12-12 22:08:59 +01:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "71f85f2a-423f-44d2-b80d-da9ac8d3961a",
"metadata": {},
"outputs": [],
"source": [
"import simpy\n",
"import random\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"from enum import Enum\n",
"import os\n",
"import shutil\n",
"from tqdm import tqdm\n",
"import math\n",
"from dataclasses import dataclass, field\n",
"from typing import List, Union, Dict\n",
"\n",
"# Constants\n",
"SEED = 42\n",
"ACCESS_COUNT_LIMIT = 1000 # Total time to run the simulation\n",
"EXPERIMENT_BASE_DIR = \"./experiments/\"\n",
"TEMP_BASE_DIR = \"./.aoi_cache/\"\n",
"BASE_FILE = pd.read_csv(\"../calculated.csv\")\n",
"BASE_FILE.index += 1\n",
"\n",
"ZIPF_CONSTANT = 2 # Shape parameter for the Zipf distribution (controls skewness) Needs to be: 1< \n",
"\n",
"# Set random seeds\n",
"random.seed(SEED)\n",
"np.random.seed(SEED)\n",
"\n",
"os.makedirs(TEMP_BASE_DIR, exist_ok=True)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "d88effd8-d92b-47d1-9e15-527166073e81",
"metadata": {},
"outputs": [],
"source": [
"# Types of cache\n",
"class EvictionStrategy(Enum):\n",
" LRU = 1\n",
" RANDOM_EVICTION = 2\n",
" TTL = 3"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "1d6a3c67-f9a5-4d9c-8ade-e1ca6944867c",
"metadata": {},
"outputs": [],
"source": [
"@dataclass\n",
"class DatabaseObject:\n",
" id: int\n",
" data: str\n",
" lambda_value: int\n",
" mu_value: Union[float, None]\n",
" ttl: Union[float, None]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "f40af914-a6c3-4e44-b7de-b3b40a743fb2",
"metadata": {},
"outputs": [],
"source": [
"@dataclass\n",
"class CacheObject:\n",
" id: int # id of object\n",
" data: DatabaseObject # body of object\n",
" initial_fetch_timer: float # time at which the object was initially pulled into the cache (object_start_time)\n",
" age_timer: float # time at which the object was last pulled into the cache (initial fetch)\n",
" next_refresh: Union[float, None] # scheduled time for the object to be requested (for refresh cache)\n",
" next_expiry: Union[float, None] # scheduled time for the object to be evicted (for ttl cache) (ttl)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "00a944e4-842b-49ba-bb36-587d9c12fdf4",
"metadata": {},
"outputs": [],
"source": [
"# Base class for all cache types\n",
"@dataclass\n",
"class SimulationConfig:\n",
" db_objects: Union[int, List[DatabaseObject]]\n",
" cache_size: int\n",
" eviction_strategy: EvictionStrategy\n",
"\n",
" def __post_init__(self):\n",
" if not hasattr(self, 'eviction_strategy') or self.eviction_strategy is None:\n",
" raise ValueError(\"Eviction strategy must be defined in subclasses.\")\n",
" \n",
" def generate_objects(self):\n",
" if isinstance(self.db_objects, int):\n",
" self.db_objects = [\n",
" DatabaseObject(id=i, data=f\"Generated Object {i}\", lambda_value=np.random.zipf(ZIPF_CONSTANT), mu_value=None, ttl=None) \n",
" for i in range(self.db_objects)\n",
" ]\n",
"\n",
" def from_file(self, path: str, lambda_column_name: str):\n",
" df = pd.read_csv(path)\n",
" lambdas = df[lambda_column_name]\n",
"\n",
" self.db_objects = [\n",
2024-12-13 11:54:19 +01:00
" DatabaseObject(id=i, data=f\"Generated Object {i}\", lambda_value=lambdas[i], mu_value=None, ttl=None) \n",
2024-12-12 22:08:59 +01:00
" for i in range(self.db_objects)\n",
" ]\n",
" \n",
"# Specific cache type variants\n",
"@dataclass\n",
"class TTLSimulation(SimulationConfig):\n",
" eviction_strategy: EvictionStrategy = field(default=EvictionStrategy.TTL, init=False)\n",
" \n",
" def generate_objects(self, fixed_ttl):\n",
" if isinstance(self.db_objects, int):\n",
" self.db_objects = [\n",
" DatabaseObject(id=i, data=f\"Generated Object {i}\", lambda_value=np.random.zipf(ZIPF_CONSTANT), mu_value=None, ttl=fixed_ttl) \n",
" for i in range(self.db_objects)\n",
" ]\n",
" \n",
" def from_file(self, path: str, lambda_column_name: str, ttl_column_name: str):\n",
" df = pd.read_csv(path)\n",
" lambdas = df[lambda_column_name]\n",
" ttls = df[ttl_column_name]\n",
"\n",
" self.db_objects = [\n",
" DatabaseObject(id=i, data=f\"Generated Object {i}\", lambda_value=lambdas[i], mu_value=None, ttl=ttls[i]) \n",
" for i in range(self.db_objects)\n",
" ]\n",
" \n",
"@dataclass\n",
"class LRUSimulation(SimulationConfig):\n",
" eviction_strategy: EvictionStrategy = field(default=EvictionStrategy.LRU, init=False)\n",
"\n",
"@dataclass\n",
"class RandomEvictionSimulation(SimulationConfig):\n",
" eviction_strategy: EvictionStrategy = field(default=EvictionStrategy.RANDOM_EVICTION, init=False)\n",
"\n",
"@dataclass\n",
"class RefreshSimulation(TTLSimulation):\n",
2024-12-13 11:54:19 +01:00
" \n",
2024-12-12 22:08:59 +01:00
" def generate_objects(self, fixed_ttl, max_refresh_rate):\n",
" if isinstance(self.db_objects, int):\n",
" self.db_objects = [\n",
" DatabaseObject(id=i, data=f\"Generated Object {i}\", lambda_value=np.random.zipf(ZIPF_CONSTANT), mu_value=np.random.uniform(1, max_refresh_rate), ttl=fixed_ttl) \n",
" for i in range(self.db_objects)\n",
2024-12-13 11:54:19 +01:00
" ]\n",
" \n",
" def from_file(self, path: str, lambda_column_name: str, ttl_column_name: str, mu_column_name: str):\n",
" df = pd.read_csv(path)\n",
" lambdas = df[lambda_column_name]\n",
" ttls = df[ttl_column_name]\n",
" mus = df[mu_column_name]\n",
"\n",
" self.db_objects = [\n",
" DatabaseObject(id=i, data=f\"Generated Object {i}\", lambda_value=lambdas[i], mu_value=mus[i], ttl=ttls[i]) \n",
" for i in range(self.db_objects)\n",
2024-12-12 22:08:59 +01:00
" ]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "5cea042f-e9fc-4a1e-9750-de212ca70601",
"metadata": {},
"outputs": [],
"source": [
"class Database:\n",
" data: Dict[int, DatabaseObject]\n",
" \n",
" def __init__(self, data: List[DatabaseObject]):\n",
" self.data = {i: data[i] for i in range(len(data))}\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": 7,
"id": "499bf543-b2c6-4e4d-afcc-0a6665ce3ae1",
"metadata": {},
"outputs": [],
"source": [
"class Cache:\n",
" capacity: int\n",
" eviction_strategy: EvictionStrategy\n",
" cache_size_over_time: List[int] # To record cache state at each interval\n",
" storage: Dict[int, CacheObject]\n",
" hits: Dict[int, int] # hit counter for each object\n",
" misses: Dict[int, int] # miss counter for each object\n",
" access_count: Dict[int, int] # access counter for each object (should be hit+miss)\n",
" next_request: Dict[int, float] # scheduled time for each object to be requested\n",
" cumulative_age: Dict[int, List[float]] # list of ages of each object at the time it was requested (current time - age_timer)\n",
" cumulative_cache_time: Dict[int, List[float]] # list of total time of each object spent in cache when it was evicted (current time - initial fetch time)\n",
" request_log: Dict[int, List[float]] # list of timestamps when each object was requested\n",
" \n",
" def __init__(self, env, db, simulation_config):\n",
" self.env = env\n",
" self.db = db\n",
" self.capacity = simulation_config.cache_size\n",
" self.eviction_strategy = simulation_config.eviction_strategy\n",
" self.cache_size_over_time = []\n",
" self.storage = {}\n",
"\n",
" db_object_count = len(self.db.data)\n",
" \n",
" self.hits = {i: 0 for i in range(db_object_count)}\n",
" self.misses = {i: 0 for i in range(db_object_count)}\n",
" self.access_count = {i: 0 for i in range(db_object_count)}\n",
" self.next_request = {i: np.random.exponential(1/self.db.data[i].lambda_value) for i in range(len(self.db.data))}\n",
" self.cumulative_age = {i: [] for i in range(db_object_count)}\n",
" self.cumulative_cache_time = {i: [] for i in range(db_object_count)}\n",
" self.request_log = {i: [] for i in range(db_object_count)}\n",
"\n",
" \n",
" def get(self, obj_id):\n",
" assert len(self.storage) <= self.capacity, f\"Too many objects in cache ({len(self.storage)}). \"\n",
"\n",
" # Schedule next request\n",
" next_request = self.env.now + np.random.exponential(1/self.db.data[obj_id].lambda_value)\n",
" self.request_log[obj_id].append(next_request)\n",
" self.next_request[obj_id] = next_request\n",
" # print(f\"[{self.env.now:.2f}] Client: Schedule next request for {obj_id}@{next_request:.2f}\")\n",
" \n",
" if obj_id in self.storage:\n",
" # Cache hit: Refresh TTL if TTL-Cache\n",
" if self.storage[obj_id].next_expiry:\n",
" assert self.env.now <= self.storage[obj_id].next_expiry, f\"[{self.env.now:.2f}] Cache should never hit on an expired cache entry.\"\n",
" self.storage[obj_id].next_expiry = self.env.now + self.db.data[obj_id].ttl\n",
" \n",
" # Cache hit: increment hit count and update cumulative age\n",
" self.hits[obj_id] += 1\n",
" self.access_count[obj_id] += 1\n",
" age = self.env.now - self.storage[obj_id].age_timer\n",
" self.cumulative_age[obj_id].append(age)\n",
"\n",
" assert len(self.cumulative_age[obj_id]) == self.access_count[obj_id], f\"[{self.env.now:.2f}] Age values collected and object access count do not match.\"\n",
"\n",
" # print(f\"[{env.now:.2f}] {obj_id} Hit: Current Age {age:.2f} (Average: {sum(self.cumulative_age[obj_id])/len(self.cumulative_age[obj_id]):.2f}) \")\n",
" else:\n",
" # Cache miss: Add TTL if TTL-Cache\n",
" # When full cache: If Non-TTL-Cache: Evict. If TTL-Cache: Don't add to Cache.\n",
" if len(self.storage) == self.capacity:\n",
" if self.eviction_strategy == EvictionStrategy.LRU:\n",
" self.evict_oldest()\n",
" elif self.eviction_strategy == EvictionStrategy.RANDOM_EVICTION:\n",
" self.evict_random()\n",
" elif self.eviction_strategy == EvictionStrategy.TTL:\n",
" # print(f\"[{self.env.now:.2f}] Cache: Capacity reached. Not accepting new request.\")\n",
" return\n",
" \n",
" # Cache miss: increment miss count\n",
" self.misses[obj_id] += 1\n",
" self.access_count[obj_id] += 1\n",
" self.cumulative_age[obj_id].append(0)\n",
"\n",
" # Cache miss: Construct CacheObject from Database Object\n",
" db_object = self.db.get_object(obj_id)\n",
" initial_fetch_timer=self.env.now\n",
" age_timer=self.env.now\n",
" next_refresh = (self.env.now + np.random.exponential(1/db_object.mu_value)) if db_object.mu_value is not None else None\n",
" next_expiry = (self.env.now + db_object.ttl) if db_object.ttl is not None else None\n",
" cache_object = CacheObject(id=obj_id, data=db_object, \n",
" initial_fetch_timer=initial_fetch_timer, age_timer=age_timer, \n",
" next_refresh=next_refresh, next_expiry=next_expiry\n",
" )\n",
" self.storage[obj_id] = cache_object\n",
" \n",
" assert len(self.cumulative_age[obj_id]) == self.access_count[obj_id], f\"[{self.env.now:.2f}] Age values collected and object access count do not match.\"\n",
" \n",
" # print(f\"[{env.now:.2f}] {obj_id} Miss: Average Age {sum(self.cumulative_age[obj_id])/len(self.cumulative_age[obj_id]):.2f} \")\n",
"\n",
" def refresh_object(self, obj_id):\n",
" \"\"\"Refresh the object from the database to keep it up-to-date. TTL is increased on refresh.\"\"\"\n",
" assert obj_id in self.storage, f\"[{self.env.now:.2f}] Refreshed object has to be in cache\"\n",
" db_object = self.db.get_object(obj_id)\n",
" age_timer = self.env.now\n",
" next_refresh = self.env.now + np.random.exponential(1/db_object.mu_value)\n",
" # next_expiry = self.env.now + db_object.ttl if db_object.ttl is not None else None\n",
"\n",
" self.storage[obj_id].data = db_object\n",
" self.storage[obj_id].age_timer = age_timer\n",
" self.storage[obj_id].next_refresh = next_refresh\n",
"\n",
" # print(f\"[{self.env.now:.2f}] Cache: Refreshed object {obj_id}\")\n",
" \n",
" def evict_oldest(self):\n",
" \"\"\"Remove the oldest item from the cache to make space.\"\"\"\n",
" assert self.capacity == len(self.storage), f\"[{self.env.now:.2f}] Expecting cache to be at capacity\"\n",
" oldest_id = min(self.storage.items(), key=lambda item: item[1].initial_fetch_timer)[0]\n",
" \n",
" # print(f\"[{self.env.now:.2f}] Cache: Evicting oldest object {oldest_id}.\")\n",
" self.cumulative_cache_time[oldest_id].append(self.env.now - self.storage[oldest_id].initial_fetch_timer)\n",
" del self.storage[oldest_id]\n",
" \n",
" def evict_random(self):\n",
" \"\"\"Remove a random item from the cache to make space.\"\"\"\n",
" assert self.capacity == len(self.storage), f\"[{self.env.now:.2f}] Expecting cache to be at capacity\"\n",
" random_id = np.random.choice(list(self.storage.keys())) # Select a random key from the cache\n",
" \n",
" # print(f\"[{self.env.now:.2f}] Cache: Evicting random object {random_id}.\")\n",
" self.cumulative_cache_time[random_id].append(self.env.now - self.storage[random_id].initial_fetch_timer)\n",
" del self.storage[random_id]\n",
" \n",
" def check_expired(self, obj_id):\n",
" \"\"\"Remove object if its TTL expired.\"\"\"\n",
" assert self.storage, f\"[{self.env.now:.2f}] Expecting cache to be not empty\"\n",
" assert self.env.now >= self.storage[obj_id].next_expiry\n",
" \n",
" # print(f\"[{self.env.now:.2f}] Cache: Object {obj_id} expired\")\n",
" self.cumulative_cache_time[obj_id].append(self.env.now - self.storage[obj_id].initial_fetch_timer)\n",
" del self.storage[obj_id]\n",
"\n",
" \n",
" def record_cache_state(self):\n",
" \"\"\"Record the current cache state (number of objects in cache) over time.\"\"\"\n",
" self.cache_size_over_time.append((self.env.now, len(self.storage)))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "687f5634-8edf-4337-b42f-bbb292d47f0f",
"metadata": {},
"outputs": [],
"source": [
"def client_request_process(env, cache, event):\n",
" \"\"\"Client process that makes requests for objects from the cache.\"\"\"\n",
" last_print = 0\n",
" with tqdm(total=ACCESS_COUNT_LIMIT, desc=\"Progress\", leave=True) as pbar:\n",
" while True:\n",
" request_id, next_request = min(cache.next_request.items(), key=lambda x: x[1])\n",
" expiry_id = -1\n",
" next_expiry = float('inf')\n",
" refresh_id = -1\n",
" next_refresh = float('inf')\n",
"\n",
" if cache.storage:\n",
" expiry_id, next_expiry = min(cache.storage.items(), key=lambda x: x[1].next_expiry if x[1].next_expiry is not None else float('inf'))\n",
" next_expiry = cache.storage[expiry_id].next_expiry\n",
" refresh_id, next_refresh = min(cache.storage.items(), key=lambda x: x[1].next_refresh if x[1].next_refresh is not None else float('inf'))\n",
" next_refresh = cache.storage[refresh_id].next_refresh\n",
"\n",
" events = [\n",
" (request_id, next_request),\n",
" (expiry_id, next_expiry),\n",
" (refresh_id, next_refresh)\n",
" ]\n",
"\n",
" event_id, event_timestamp = min(events, key=lambda x: x[1] if x[1] is not None else float('inf'))\n",
" \n",
" # if event_id == request_id and event_timestamp == next_request:\n",
" # print(f\"[{env.now:.2f}] Waiting for request...\")\n",
" # elif event_id == expiry_id and event_timestamp == next_expiry:\n",
" # print(f\"[{env.now:.2f}] Waiting for expiry until...\")\n",
" # elif event_id == refresh_id and event_timestamp == next_refresh:\n",
" # print(f\"[{env.now:.2f}] Waiting for refresh...\")\n",
" \n",
" yield(env.timeout(event_timestamp - env.now))\n",
"\n",
" if event_id == request_id and event_timestamp == next_request:\n",
" assert env.now >= next_request, f\"[{env.now}] Time for request should've been reached for Object {request_id}\"\n",
" cache.get(request_id)\n",
" elif event_id == expiry_id and event_timestamp == next_expiry:\n",
" assert env.now >= next_expiry, f\"[{env.now}] Time for expiry should've been reached for Object {expiry_id}\"\n",
" cache.check_expired(expiry_id)\n",
" elif event_id == refresh_id and event_timestamp == next_refresh:\n",
" assert env.now >= next_refresh, f\"[{env.now}] Time for refresh should've been reached for Object {refresh_id}\"\n",
" cache.refresh_object(refresh_id)\n",
" else:\n",
" assert False, \"Unreachable\"\n",
"\n",
" # For progress bar\n",
" if (int(env.now) % 1) == 0 and int(env.now) != last_print:\n",
" last_print = int(env.now)\n",
" pbar.n = min(cache.access_count.values())\n",
" pbar.refresh()\n",
" \n",
" # Simulation stop condition\n",
" if all(access_count >= ACCESS_COUNT_LIMIT for access_count in cache.access_count.values()):\n",
" print(f\"Simulation ended after {env.now} seconds.\")\n",
" for obj_id in cache.storage.keys():\n",
" cache.cumulative_cache_time[obj_id].append(env.now - cache.storage[obj_id].initial_fetch_timer)\n",
" event.succeed()\n",
" \n",
" cache.record_cache_state()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "c8516830-9880-4d9e-a91b-000338baf9d6",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"class Simulation:\n",
" def __init__(self, simulation_config: Union[TTLSimulation, LRUSimulation, RandomEvictionSimulation, RefreshSimulation]):\n",
" # Initialize simulation environment\n",
" self.env = simpy.Environment()\n",
" \n",
" # Instantiate components\n",
" self.db = Database(simulation_config.db_objects)\n",
" self.cache = Cache(self.env, self.db, simulation_config)\n",
"\n",
" def run_simulation(self):\n",
" # Start processes\n",
" # env.process(age_cache_process(env, cache))\n",
" stop_event = self.env.event()\n",
" self.env.process(client_request_process(self.env, self.cache, stop_event))\n",
" \n",
" # Run the simulation\n",
" self.env.run(until=stop_event)\n",
" self.end_time = self.env.now"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "e269b607-16b9-46d0-8a97-7324f2002c72",
"metadata": {},
"outputs": [],
"source": [
2024-12-12 22:15:58 +01:00
"# Simulate with a Cache that does random evictions, We'll have 100 Database Objects and a Cache Size of 10\n",
"# We'll generate lambdas from a zipf distribution\n",
2024-12-12 22:08:59 +01:00
"# config = RandomEvictionSimulation(100, 10)\n",
"# config.generate_objects()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "33fdc5fd-1f39-4b51-b2c7-6ea6acf2b753",
"metadata": {},
"outputs": [],
"source": [
2024-12-12 22:15:58 +01:00
"# Simulate with a Cache that does lru, We'll have 100 Database Objects and a Cache Size of 10\n",
"# We'll generate lambdas from a zipf distribution\n",
2024-12-13 11:54:19 +01:00
"config = LRUSimulation(100, 10)\n",
"config.from_file('../test.csv', 'Lambda')"
2024-12-12 22:08:59 +01:00
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "6c391bfd-b294-4ff7-8b22-51777368a6b9",
"metadata": {},
"outputs": [],
"source": [
2024-12-12 22:15:58 +01:00
"# Simulate with a Cache that does Refreshes with TTL based eviction, We'll have 100 Database Objects and a Cache Size of 10\n",
"# We'll generate lambdas from a zipf distribution. Each object will have a fixed ttl of 1 when its pulled into the cache. Mu for the refresh rate is 10\n",
2024-12-13 11:54:19 +01:00
"# config = RefreshSimulation(100, 10)\n",
"# config.from_file('../test.csv', 'Lambda', 'h_opt_2', 'u_opt_2')"
2024-12-12 22:08:59 +01:00
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "0a444c9d-53dd-4cab-b8f1-100ad3ab213a",
"metadata": {},
"outputs": [],
"source": [
2024-12-12 22:15:58 +01:00
"# Simulate with a Cache that does TTL based eviction, We'll have 100 Database Objects and a Cache Size of 10\n",
"# We'll take lambdas from the \"lambda\" column of the file \"../calculated.csv\" and the TTLs for each object from the \"optimal_TTL\" column of the same file.\n",
2024-12-13 11:54:19 +01:00
"# config = TTLSimulation(100, 10)\n",
"# config.from_file(\"../calculated.csv\", \"lambda\", \"optimal_TTL\")"
2024-12-12 22:08:59 +01:00
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "66f65699-a3c9-48c4-8f1f-b9d7834c026a",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
2024-12-13 11:54:19 +01:00
"IOPub message rate exceeded.██████████████████████████████████████▏ | 318/1000 [00:08<00:18, 36.80it/s]\n",
"The Jupyter server will temporarily stop sending output\n",
"to the client in order to avoid crashing it.\n",
"To change this limit, set the config variable\n",
"`--ServerApp.iopub_msg_rate_limit`.\n",
"\n",
"Current values:\n",
"ServerApp.iopub_msg_rate_limit=1000.0 (msgs/sec)\n",
"ServerApp.rate_limit_window=3.0 (secs)\n",
"\n",
"IOPub message rate exceeded.████████████████████████████████████████████████████████████████████▊ | 508/1000 [00:11<00:11, 42.68it/s]\n",
"The Jupyter server will temporarily stop sending output\n",
"to the client in order to avoid crashing it.\n",
"To change this limit, set the config variable\n",
"`--ServerApp.iopub_msg_rate_limit`.\n",
"\n",
"Current values:\n",
"ServerApp.iopub_msg_rate_limit=1000.0 (msgs/sec)\n",
"ServerApp.rate_limit_window=3.0 (secs)\n",
"\n",
"IOPub message rate exceeded.█████████████████████████████████████████████████████████████████████████████████████████████████████▋ | 712/1000 [00:15<00:06, 45.55it/s]\n",
"The Jupyter server will temporarily stop sending output\n",
"to the client in order to avoid crashing it.\n",
"To change this limit, set the config variable\n",
"`--ServerApp.iopub_msg_rate_limit`.\n",
"\n",
"Current values:\n",
"ServerApp.iopub_msg_rate_limit=1000.0 (msgs/sec)\n",
"ServerApp.rate_limit_window=3.0 (secs)\n",
"\n",
"IOPub message rate exceeded.██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▎ | 890/1000 [00:18<00:02, 47.26it/s]\n",
"The Jupyter server will temporarily stop sending output\n",
"to the client in order to avoid crashing it.\n",
"To change this limit, set the config variable\n",
"`--ServerApp.iopub_msg_rate_limit`.\n",
"\n",
"Current values:\n",
"ServerApp.iopub_msg_rate_limit=1000.0 (msgs/sec)\n",
"ServerApp.rate_limit_window=3.0 (secs)\n",
"\n",
"Progress: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▊| 999/1000 [00:20<00:00, 48.26it/s]"
2024-12-12 22:08:59 +01:00
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
2024-12-13 11:54:19 +01:00
"Simulation ended after 19747.84052390687 seconds.\n",
"CPU times: user 19.6 s, sys: 3.65 s, total: 23.2 s\n",
"Wall time: 20.7 s\n"
2024-12-12 22:08:59 +01:00
]
}
],
"source": [
"%%time\n",
"\n",
"simulation = Simulation(config)\n",
"simulation.run_simulation()"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "6f900c68-1f34-48d1-b346-ef6ea6911fa5",
"metadata": {},
"outputs": [],
"source": [
"cache = simulation.cache\n",
"db = simulation.db\n",
"simulation_end_time = simulation.end_time\n",
"database_object_count = len(db.data)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "3b6f7c1f-ea54-4496-bb9a-370cee2d2751",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2024-12-13 11:54:19 +01:00
"Object 0: Hit Rate = 0.05, Expected Hit Rate = 0.05, Average Time spend in Cache: 0.04, Average Age = 0.02, Expected Age = 1.02\n",
"Object 1: Hit Rate = 0.04, Expected Hit Rate = 0.05, Average Time spend in Cache: 0.04, Average Age = 0.02, Expected Age = 0.80\n",
"Object 2: Hit Rate = 0.03, Expected Hit Rate = 0.05, Average Time spend in Cache: 0.04, Average Age = 0.01, Expected Age = 0.64\n",
"Object 3: Hit Rate = 0.04, Expected Hit Rate = 0.05, Average Time spend in Cache: 0.04, Average Age = 0.02, Expected Age = 0.83\n",
"Object 4: Hit Rate = 0.04, Expected Hit Rate = 0.05, Average Time spend in Cache: 0.04, Average Age = 0.01, Expected Age = 0.68\n",
"Object 5: Hit Rate = 0.04, Expected Hit Rate = 0.05, Average Time spend in Cache: 0.04, Average Age = 0.02, Expected Age = 0.80\n",
"Object 6: Hit Rate = 0.04, Expected Hit Rate = 0.05, Average Time spend in Cache: 0.04, Average Age = 0.02, Expected Age = 0.76\n",
"Object 7: Hit Rate = 0.03, Expected Hit Rate = 0.05, Average Time spend in Cache: 0.04, Average Age = 0.01, Expected Age = 0.56\n",
"Object 8: Hit Rate = 0.04, Expected Hit Rate = 0.05, Average Time spend in Cache: 0.04, Average Age = 0.02, Expected Age = 0.73\n",
"Object 9: Hit Rate = 0.04, Expected Hit Rate = 0.05, Average Time spend in Cache: 0.04, Average Age = 0.02, Expected Age = 0.80\n",
"Object 10: Hit Rate = 0.04, Expected Hit Rate = 0.05, Average Time spend in Cache: 0.04, Average Age = 0.02, Expected Age = 0.76\n",
"Object 11: Hit Rate = 0.05, Expected Hit Rate = 0.05, Average Time spend in Cache: 0.04, Average Age = 0.02, Expected Age = 0.88\n",
"Object 12: Hit Rate = 0.04, Expected Hit Rate = 0.05, Average Time spend in Cache: 0.04, Average Age = 0.02, Expected Age = 0.73\n",
"Object 13: Hit Rate = 0.04, Expected Hit Rate = 0.05, Average Time spend in Cache: 0.04, Average Age = 0.02, Expected Age = 0.77\n",
"Object 14: Hit Rate = 0.03, Expected Hit Rate = 0.06, Average Time spend in Cache: 0.04, Average Age = 0.01, Expected Age = 0.60\n",
"Object 15: Hit Rate = 0.05, Expected Hit Rate = 0.06, Average Time spend in Cache: 0.04, Average Age = 0.02, Expected Age = 0.81\n",
"Object 16: Hit Rate = 0.05, Expected Hit Rate = 0.06, Average Time spend in Cache: 0.04, Average Age = 0.02, Expected Age = 0.84\n",
"Object 17: Hit Rate = 0.04, Expected Hit Rate = 0.06, Average Time spend in Cache: 0.04, Average Age = 0.02, Expected Age = 0.73\n",
"Object 18: Hit Rate = 0.03, Expected Hit Rate = 0.06, Average Time spend in Cache: 0.04, Average Age = 0.02, Expected Age = 0.55\n",
"Object 19: Hit Rate = 0.04, Expected Hit Rate = 0.06, Average Time spend in Cache: 0.04, Average Age = 0.01, Expected Age = 0.63\n",
"Object 20: Hit Rate = 0.04, Expected Hit Rate = 0.06, Average Time spend in Cache: 0.05, Average Age = 0.02, Expected Age = 0.73\n",
"Object 21: Hit Rate = 0.06, Expected Hit Rate = 0.06, Average Time spend in Cache: 0.05, Average Age = 0.03, Expected Age = 0.91\n",
"Object 22: Hit Rate = 0.06, Expected Hit Rate = 0.06, Average Time spend in Cache: 0.05, Average Age = 0.03, Expected Age = 0.90\n",
"Object 23: Hit Rate = 0.04, Expected Hit Rate = 0.06, Average Time spend in Cache: 0.04, Average Age = 0.02, Expected Age = 0.69\n",
"Object 24: Hit Rate = 0.05, Expected Hit Rate = 0.06, Average Time spend in Cache: 0.04, Average Age = 0.02, Expected Age = 0.76\n",
"Object 25: Hit Rate = 0.05, Expected Hit Rate = 0.06, Average Time spend in Cache: 0.05, Average Age = 0.02, Expected Age = 0.75\n",
"Object 26: Hit Rate = 0.05, Expected Hit Rate = 0.06, Average Time spend in Cache: 0.05, Average Age = 0.02, Expected Age = 0.72\n",
"Object 27: Hit Rate = 0.05, Expected Hit Rate = 0.06, Average Time spend in Cache: 0.05, Average Age = 0.02, Expected Age = 0.70\n",
"Object 28: Hit Rate = 0.06, Expected Hit Rate = 0.06, Average Time spend in Cache: 0.05, Average Age = 0.02, Expected Age = 0.86\n",
"Object 29: Hit Rate = 0.04, Expected Hit Rate = 0.06, Average Time spend in Cache: 0.05, Average Age = 0.01, Expected Age = 0.57\n",
"Object 30: Hit Rate = 0.05, Expected Hit Rate = 0.06, Average Time spend in Cache: 0.05, Average Age = 0.02, Expected Age = 0.72\n",
"Object 31: Hit Rate = 0.05, Expected Hit Rate = 0.07, Average Time spend in Cache: 0.05, Average Age = 0.02, Expected Age = 0.78\n",
"Object 32: Hit Rate = 0.06, Expected Hit Rate = 0.07, Average Time spend in Cache: 0.05, Average Age = 0.03, Expected Age = 0.83\n",
"Object 33: Hit Rate = 0.05, Expected Hit Rate = 0.07, Average Time spend in Cache: 0.05, Average Age = 0.03, Expected Age = 0.78\n",
"Object 34: Hit Rate = 0.05, Expected Hit Rate = 0.07, Average Time spend in Cache: 0.05, Average Age = 0.02, Expected Age = 0.73\n",
"Object 35: Hit Rate = 0.05, Expected Hit Rate = 0.07, Average Time spend in Cache: 0.05, Average Age = 0.02, Expected Age = 0.74\n",
"Object 36: Hit Rate = 0.06, Expected Hit Rate = 0.07, Average Time spend in Cache: 0.05, Average Age = 0.02, Expected Age = 0.84\n",
"Object 37: Hit Rate = 0.06, Expected Hit Rate = 0.07, Average Time spend in Cache: 0.05, Average Age = 0.02, Expected Age = 0.78\n",
"Object 38: Hit Rate = 0.06, Expected Hit Rate = 0.07, Average Time spend in Cache: 0.05, Average Age = 0.02, Expected Age = 0.75\n",
"Object 39: Hit Rate = 0.06, Expected Hit Rate = 0.07, Average Time spend in Cache: 0.06, Average Age = 0.02, Expected Age = 0.80\n",
"Object 40: Hit Rate = 0.06, Expected Hit Rate = 0.07, Average Time spend in Cache: 0.05, Average Age = 0.03, Expected Age = 0.83\n",
"Object 41: Hit Rate = 0.07, Expected Hit Rate = 0.07, Average Time spend in Cache: 0.06, Average Age = 0.03, Expected Age = 0.88\n",
"Object 42: Hit Rate = 0.06, Expected Hit Rate = 0.07, Average Time spend in Cache: 0.06, Average Age = 0.03, Expected Age = 0.77\n",
"Object 43: Hit Rate = 0.06, Expected Hit Rate = 0.08, Average Time spend in Cache: 0.06, Average Age = 0.03, Expected Age = 0.81\n",
"Object 44: Hit Rate = 0.07, Expected Hit Rate = 0.08, Average Time spend in Cache: 0.06, Average Age = 0.03, Expected Age = 0.87\n",
"Object 45: Hit Rate = 0.06, Expected Hit Rate = 0.08, Average Time spend in Cache: 0.06, Average Age = 0.03, Expected Age = 0.72\n",
"Object 46: Hit Rate = 0.07, Expected Hit Rate = 0.08, Average Time spend in Cache: 0.06, Average Age = 0.03, Expected Age = 0.81\n",
"Object 47: Hit Rate = 0.07, Expected Hit Rate = 0.08, Average Time spend in Cache: 0.06, Average Age = 0.02, Expected Age = 0.79\n",
"Object 48: Hit Rate = 0.07, Expected Hit Rate = 0.08, Average Time spend in Cache: 0.06, Average Age = 0.03, Expected Age = 0.79\n",
"Object 49: Hit Rate = 0.06, Expected Hit Rate = 0.08, Average Time spend in Cache: 0.07, Average Age = 0.03, Expected Age = 0.76\n",
"Object 50: Hit Rate = 0.06, Expected Hit Rate = 0.08, Average Time spend in Cache: 0.07, Average Age = 0.03, Expected Age = 0.72\n",
"Object 51: Hit Rate = 0.06, Expected Hit Rate = 0.09, Average Time spend in Cache: 0.07, Average Age = 0.03, Expected Age = 0.72\n",
"Object 52: Hit Rate = 0.07, Expected Hit Rate = 0.09, Average Time spend in Cache: 0.07, Average Age = 0.03, Expected Age = 0.75\n",
"Object 53: Hit Rate = 0.06, Expected Hit Rate = 0.09, Average Time spend in Cache: 0.07, Average Age = 0.03, Expected Age = 0.69\n",
"Object 54: Hit Rate = 0.07, Expected Hit Rate = 0.09, Average Time spend in Cache: 0.07, Average Age = 0.03, Expected Age = 0.78\n",
"Object 55: Hit Rate = 0.08, Expected Hit Rate = 0.09, Average Time spend in Cache: 0.07, Average Age = 0.04, Expected Age = 0.82\n",
"Object 56: Hit Rate = 0.08, Expected Hit Rate = 0.09, Average Time spend in Cache: 0.07, Average Age = 0.03, Expected Age = 0.80\n",
"Object 57: Hit Rate = 0.06, Expected Hit Rate = 0.09, Average Time spend in Cache: 0.07, Average Age = 0.03, Expected Age = 0.62\n",
"Object 58: Hit Rate = 0.08, Expected Hit Rate = 0.10, Average Time spend in Cache: 0.07, Average Age = 0.04, Expected Age = 0.83\n",
"Object 59: Hit Rate = 0.07, Expected Hit Rate = 0.10, Average Time spend in Cache: 0.08, Average Age = 0.03, Expected Age = 0.68\n",
"Object 60: Hit Rate = 0.08, Expected Hit Rate = 0.10, Average Time spend in Cache: 0.08, Average Age = 0.04, Expected Age = 0.74\n",
"Object 61: Hit Rate = 0.07, Expected Hit Rate = 0.10, Average Time spend in Cache: 0.08, Average Age = 0.03, Expected Age = 0.66\n",
"Object 62: Hit Rate = 0.09, Expected Hit Rate = 0.10, Average Time spend in Cache: 0.08, Average Age = 0.04, Expected Age = 0.87\n",
"Object 63: Hit Rate = 0.08, Expected Hit Rate = 0.11, Average Time spend in Cache: 0.08, Average Age = 0.04, Expected Age = 0.74\n",
"Object 64: Hit Rate = 0.08, Expected Hit Rate = 0.11, Average Time spend in Cache: 0.09, Average Age = 0.04, Expected Age = 0.74\n",
"Object 65: Hit Rate = 0.08, Expected Hit Rate = 0.11, Average Time spend in Cache: 0.09, Average Age = 0.04, Expected Age = 0.74\n",
"Object 66: Hit Rate = 0.08, Expected Hit Rate = 0.11, Average Time spend in Cache: 0.09, Average Age = 0.03, Expected Age = 0.68\n",
"Object 67: Hit Rate = 0.09, Expected Hit Rate = 0.11, Average Time spend in Cache: 0.09, Average Age = 0.04, Expected Age = 0.73\n",
"Object 68: Hit Rate = 0.09, Expected Hit Rate = 0.12, Average Time spend in Cache: 0.10, Average Age = 0.04, Expected Age = 0.69\n",
"Object 69: Hit Rate = 0.09, Expected Hit Rate = 0.12, Average Time spend in Cache: 0.09, Average Age = 0.04, Expected Age = 0.67\n",
"Object 70: Hit Rate = 0.10, Expected Hit Rate = 0.12, Average Time spend in Cache: 0.09, Average Age = 0.04, Expected Age = 0.73\n",
"Object 71: Hit Rate = 0.09, Expected Hit Rate = 0.13, Average Time spend in Cache: 0.10, Average Age = 0.04, Expected Age = 0.69\n",
"Object 72: Hit Rate = 0.10, Expected Hit Rate = 0.13, Average Time spend in Cache: 0.10, Average Age = 0.04, Expected Age = 0.73\n",
"Object 73: Hit Rate = 0.09, Expected Hit Rate = 0.13, Average Time spend in Cache: 0.10, Average Age = 0.04, Expected Age = 0.64\n",
"Object 74: Hit Rate = 0.11, Expected Hit Rate = 0.14, Average Time spend in Cache: 0.10, Average Age = 0.05, Expected Age = 0.72\n",
"Object 75: Hit Rate = 0.11, Expected Hit Rate = 0.14, Average Time spend in Cache: 0.11, Average Age = 0.05, Expected Age = 0.74\n",
"Object 76: Hit Rate = 0.11, Expected Hit Rate = 0.15, Average Time spend in Cache: 0.12, Average Age = 0.05, Expected Age = 0.72\n",
"Object 77: Hit Rate = 0.13, Expected Hit Rate = 0.15, Average Time spend in Cache: 0.12, Average Age = 0.06, Expected Age = 0.80\n",
"Object 78: Hit Rate = 0.12, Expected Hit Rate = 0.16, Average Time spend in Cache: 0.12, Average Age = 0.05, Expected Age = 0.73\n",
"Object 79: Hit Rate = 0.12, Expected Hit Rate = 0.16, Average Time spend in Cache: 0.12, Average Age = 0.05, Expected Age = 0.68\n",
"Object 80: Hit Rate = 0.13, Expected Hit Rate = 0.17, Average Time spend in Cache: 0.13, Average Age = 0.06, Expected Age = 0.73\n",
"Object 81: Hit Rate = 0.12, Expected Hit Rate = 0.17, Average Time spend in Cache: 0.13, Average Age = 0.05, Expected Age = 0.67\n",
"Object 82: Hit Rate = 0.14, Expected Hit Rate = 0.18, Average Time spend in Cache: 0.14, Average Age = 0.06, Expected Age = 0.72\n",
"Object 83: Hit Rate = 0.15, Expected Hit Rate = 0.19, Average Time spend in Cache: 0.14, Average Age = 0.07, Expected Age = 0.72\n",
"Object 84: Hit Rate = 0.15, Expected Hit Rate = 0.20, Average Time spend in Cache: 0.15, Average Age = 0.07, Expected Age = 0.69\n",
"Object 85: Hit Rate = 0.15, Expected Hit Rate = 0.20, Average Time spend in Cache: 0.15, Average Age = 0.06, Expected Age = 0.65\n",
"Object 86: Hit Rate = 0.16, Expected Hit Rate = 0.22, Average Time spend in Cache: 0.16, Average Age = 0.07, Expected Age = 0.68\n",
"Object 87: Hit Rate = 0.17, Expected Hit Rate = 0.23, Average Time spend in Cache: 0.17, Average Age = 0.07, Expected Age = 0.67\n",
"Object 88: Hit Rate = 0.18, Expected Hit Rate = 0.24, Average Time spend in Cache: 0.18, Average Age = 0.08, Expected Age = 0.70\n",
"Object 89: Hit Rate = 0.20, Expected Hit Rate = 0.25, Average Time spend in Cache: 0.20, Average Age = 0.09, Expected Age = 0.69\n",
"Object 90: Hit Rate = 0.20, Expected Hit Rate = 0.27, Average Time spend in Cache: 0.20, Average Age = 0.09, Expected Age = 0.65\n",
"Object 91: Hit Rate = 0.22, Expected Hit Rate = 0.29, Average Time spend in Cache: 0.22, Average Age = 0.09, Expected Age = 0.67\n",
"Object 92: Hit Rate = 0.24, Expected Hit Rate = 0.32, Average Time spend in Cache: 0.23, Average Age = 0.10, Expected Age = 0.66\n",
"Object 93: Hit Rate = 0.26, Expected Hit Rate = 0.34, Average Time spend in Cache: 0.26, Average Age = 0.12, Expected Age = 0.66\n",
"Object 94: Hit Rate = 0.28, Expected Hit Rate = 0.38, Average Time spend in Cache: 0.28, Average Age = 0.13, Expected Age = 0.64\n",
"Object 95: Hit Rate = 0.31, Expected Hit Rate = 0.42, Average Time spend in Cache: 0.31, Average Age = 0.14, Expected Age = 0.62\n",
"Object 96: Hit Rate = 0.36, Expected Hit Rate = 0.48, Average Time spend in Cache: 0.35, Average Age = 0.16, Expected Age = 0.62\n",
"Object 97: Hit Rate = 0.40, Expected Hit Rate = 0.56, Average Time spend in Cache: 0.41, Average Age = 0.19, Expected Age = 0.58\n",
"Object 98: Hit Rate = 0.49, Expected Hit Rate = 0.68, Average Time spend in Cache: 0.49, Average Age = 0.22, Expected Age = 0.57\n",
"Object 99: Hit Rate = 0.63, Expected Hit Rate = 0.86, Average Time spend in Cache: 0.63, Average Age = 0.29, Expected Age = 0.52\n"
2024-12-12 22:08:59 +01:00
]
}
],
"source": [
"statistics = []\n",
"# Calculate and print hit rate and average age for each object\n",
"for obj_id in range(database_object_count):\n",
" if cache.access_count[obj_id] != 0:\n",
" hit_rate = cache.hits[obj_id] / max(1, cache.access_count[obj_id])\n",
" expected_hit_rate = 1-math.exp(-db.data[obj_id].lambda_value*(db.data[obj_id].ttl if db.data[obj_id].ttl is not None else 1))\n",
" avg_cache_time = sum(cache.cumulative_cache_time[obj_id]) / max(1, simulation_end_time) \n",
" avg_age = sum(cache.cumulative_age[obj_id]) / max(len(cache.cumulative_age[obj_id]), 1)\n",
" expected_age = hit_rate / (db.data[obj_id].lambda_value * (1 - pow(hit_rate,2)))\n",
" print(f\"Object {obj_id}: Hit Rate = {hit_rate:.2f}, Expected Hit Rate = {expected_hit_rate:.2f}, Average Time spend in Cache: {avg_cache_time:.2f}, Average Age = {avg_age:.2f}, Expected Age = {expected_age:.2f}\")\n",
" statistics.append({\"obj_id\": obj_id,\"hit_rate\": hit_rate, \"expected_hit_rate\": expected_hit_rate, \"avg_cache_time\":avg_cache_time, \"avg_age\": avg_age, \"expected_age\": expected_age})"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "b2d18372-cdba-4151-ae32-5bf45466bf94",
"metadata": {},
"outputs": [],
"source": [
"stats = pd.DataFrame(statistics)\n",
"stats.to_csv(f\"{TEMP_BASE_DIR}/hit_age.csv\",index=False)\n",
"stats.drop(\"obj_id\", axis=1).describe().to_csv(f\"{TEMP_BASE_DIR}/overall_hit_age.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "80971714-44f1-47db-9e89-85be7c885bde",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>access_count</th>\n",
" <th>hits</th>\n",
" <th>misses</th>\n",
" <th>mu</th>\n",
" <th>lambda</th>\n",
" <th>hit_rate</th>\n",
" <th>optimal_hitrates</th>\n",
" <th>expected_hit_rate</th>\n",
" <th>expected_hit_rate_delta</th>\n",
" <th>avg_cache_time</th>\n",
" <th>cache_time_delta</th>\n",
" <th>avg_age</th>\n",
" <th>expected_age</th>\n",
" <th>age_delta</th>\n",
" <th>age_delta in %</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
2024-12-13 11:54:19 +01:00
" <td>1022</td>\n",
" <td>52</td>\n",
" <td>970</td>\n",
2024-12-12 22:08:59 +01:00
" <td>None</td>\n",
2024-12-13 11:54:19 +01:00
" <td>0.0502</td>\n",
" <td>0.050881</td>\n",
2024-12-12 22:08:59 +01:00
" <td>0.0513</td>\n",
2024-12-13 11:54:19 +01:00
" <td>0.048961</td>\n",
" <td>0.001920</td>\n",
" <td>0.038411</td>\n",
" <td>0.012470</td>\n",
" <td>0.023130</td>\n",
" <td>1.016189</td>\n",
" <td>-0.993059</td>\n",
" <td>-0.977238</td>\n",
2024-12-12 22:08:59 +01:00
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
2024-12-13 11:54:19 +01:00
" <td>1045</td>\n",
" <td>42</td>\n",
" <td>1003</td>\n",
2024-12-12 22:08:59 +01:00
" <td>None</td>\n",
2024-12-13 11:54:19 +01:00
" <td>0.0506</td>\n",
" <td>0.040191</td>\n",
2024-12-12 22:08:59 +01:00
" <td>0.0513</td>\n",
2024-12-13 11:54:19 +01:00
" <td>0.049341</td>\n",
" <td>-0.009150</td>\n",
" <td>0.040332</td>\n",
" <td>-0.000141</td>\n",
" <td>0.016009</td>\n",
" <td>0.795581</td>\n",
" <td>-0.779572</td>\n",
" <td>-0.979877</td>\n",
2024-12-12 22:08:59 +01:00
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
2024-12-13 11:54:19 +01:00
" <td>1009</td>\n",
" <td>33</td>\n",
" <td>976</td>\n",
2024-12-12 22:08:59 +01:00
" <td>None</td>\n",
2024-12-13 11:54:19 +01:00
" <td>0.0511</td>\n",
" <td>0.032706</td>\n",
2024-12-12 22:08:59 +01:00
" <td>0.4000</td>\n",
2024-12-13 11:54:19 +01:00
" <td>0.049816</td>\n",
" <td>-0.017111</td>\n",
" <td>0.039100</td>\n",
" <td>-0.006394</td>\n",
" <td>0.013227</td>\n",
" <td>0.640718</td>\n",
" <td>-0.627490</td>\n",
" <td>-0.979355</td>\n",
2024-12-12 22:08:59 +01:00
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
2024-12-13 11:54:19 +01:00
" <td>1059</td>\n",
" <td>45</td>\n",
" <td>1014</td>\n",
2024-12-12 22:08:59 +01:00
" <td>None</td>\n",
2024-12-13 11:54:19 +01:00
" <td>0.0515</td>\n",
" <td>0.042493</td>\n",
2024-12-12 22:08:59 +01:00
" <td>0.2254</td>\n",
2024-12-13 11:54:19 +01:00
" <td>0.050196</td>\n",
" <td>-0.007703</td>\n",
" <td>0.041095</td>\n",
" <td>0.001398</td>\n",
" <td>0.015914</td>\n",
" <td>0.826598</td>\n",
" <td>-0.810683</td>\n",
" <td>-0.980747</td>\n",
2024-12-12 22:08:59 +01:00
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
2024-12-13 11:54:19 +01:00
" <td>1045</td>\n",
" <td>37</td>\n",
" <td>1008</td>\n",
2024-12-12 22:08:59 +01:00
" <td>None</td>\n",
2024-12-13 11:54:19 +01:00
" <td>0.0519</td>\n",
" <td>0.035407</td>\n",
2024-12-12 22:08:59 +01:00
" <td>0.0000</td>\n",
2024-12-13 11:54:19 +01:00
" <td>0.050576</td>\n",
" <td>-0.015169</td>\n",
" <td>0.041100</td>\n",
" <td>-0.005693</td>\n",
" <td>0.011848</td>\n",
" <td>0.683066</td>\n",
" <td>-0.671218</td>\n",
" <td>-0.982655</td>\n",
2024-12-12 22:08:59 +01:00
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>95</th>\n",
2024-12-13 11:54:19 +01:00
" <td>10811</td>\n",
" <td>3365</td>\n",
" <td>7446</td>\n",
2024-12-12 22:08:59 +01:00
" <td>None</td>\n",
2024-12-13 11:54:19 +01:00
" <td>0.5519</td>\n",
" <td>0.311257</td>\n",
2024-12-12 22:08:59 +01:00
" <td>0.0000</td>\n",
2024-12-13 11:54:19 +01:00
" <td>0.424145</td>\n",
" <td>-0.112888</td>\n",
" <td>0.308356</td>\n",
" <td>0.002901</td>\n",
" <td>0.137645</td>\n",
" <td>0.624473</td>\n",
" <td>-0.486829</td>\n",
" <td>-0.779583</td>\n",
2024-12-12 22:08:59 +01:00
" </tr>\n",
" <tr>\n",
" <th>96</th>\n",
2024-12-13 11:54:19 +01:00
" <td>13157</td>\n",
" <td>4684</td>\n",
" <td>8473</td>\n",
2024-12-12 22:08:59 +01:00
" <td>None</td>\n",
2024-12-13 11:54:19 +01:00
" <td>0.6598</td>\n",
" <td>0.356008</td>\n",
2024-12-12 22:08:59 +01:00
" <td>0.0000</td>\n",
2024-12-13 11:54:19 +01:00
" <td>0.483045</td>\n",
" <td>-0.127037</td>\n",
" <td>0.353400</td>\n",
" <td>0.002608</td>\n",
" <td>0.160020</td>\n",
" <td>0.617881</td>\n",
" <td>-0.457862</td>\n",
" <td>-0.741019</td>\n",
2024-12-12 22:08:59 +01:00
" </tr>\n",
" <tr>\n",
" <th>97</th>\n",
2024-12-13 11:54:19 +01:00
" <td>16227</td>\n",
" <td>6542</td>\n",
" <td>9685</td>\n",
2024-12-12 22:08:59 +01:00
" <td>None</td>\n",
2024-12-13 11:54:19 +01:00
" <td>0.8305</td>\n",
" <td>0.403155</td>\n",
2024-12-12 22:08:59 +01:00
" <td>0.0000</td>\n",
2024-12-13 11:54:19 +01:00
" <td>0.564169</td>\n",
" <td>-0.161013</td>\n",
" <td>0.407435</td>\n",
" <td>-0.004280</td>\n",
" <td>0.185865</td>\n",
" <td>0.579650</td>\n",
" <td>-0.393785</td>\n",
" <td>-0.679350</td>\n",
2024-12-12 22:08:59 +01:00
" </tr>\n",
" <tr>\n",
" <th>98</th>\n",
2024-12-13 11:54:19 +01:00
" <td>22767</td>\n",
" <td>11201</td>\n",
" <td>11566</td>\n",
2024-12-12 22:08:59 +01:00
" <td>None</td>\n",
2024-12-13 11:54:19 +01:00
" <td>1.1487</td>\n",
" <td>0.491984</td>\n",
2024-12-12 22:08:59 +01:00
" <td>0.5528</td>\n",
2024-12-13 11:54:19 +01:00
" <td>0.682951</td>\n",
" <td>-0.190967</td>\n",
" <td>0.489995</td>\n",
" <td>0.001989</td>\n",
" <td>0.224034</td>\n",
" <td>0.565071</td>\n",
" <td>-0.341037</td>\n",
" <td>-0.603530</td>\n",
2024-12-12 22:08:59 +01:00
" </tr>\n",
" <tr>\n",
" <th>99</th>\n",
2024-12-13 11:54:19 +01:00
" <td>39079</td>\n",
" <td>24517</td>\n",
" <td>14562</td>\n",
2024-12-12 22:08:59 +01:00
" <td>None</td>\n",
2024-12-13 11:54:19 +01:00
" <td>2.0000</td>\n",
" <td>0.627370</td>\n",
2024-12-12 22:08:59 +01:00
" <td>0.0000</td>\n",
2024-12-13 11:54:19 +01:00
" <td>0.864665</td>\n",
" <td>-0.237295</td>\n",
" <td>0.627601</td>\n",
" <td>-0.000231</td>\n",
" <td>0.293713</td>\n",
" <td>0.517285</td>\n",
" <td>-0.223572</td>\n",
" <td>-0.432202</td>\n",
2024-12-12 22:08:59 +01:00
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>100 rows × 15 columns</p>\n",
"</div>"
],
"text/plain": [
2024-12-13 11:54:19 +01:00
" access_count hits misses mu lambda hit_rate optimal_hitrates \\\n",
"0 1022 52 970 None 0.0502 0.050881 0.0513 \n",
"1 1045 42 1003 None 0.0506 0.040191 0.0513 \n",
"2 1009 33 976 None 0.0511 0.032706 0.4000 \n",
"3 1059 45 1014 None 0.0515 0.042493 0.2254 \n",
"4 1045 37 1008 None 0.0519 0.035407 0.0000 \n",
".. ... ... ... ... ... ... ... \n",
"95 10811 3365 7446 None 0.5519 0.311257 0.0000 \n",
"96 13157 4684 8473 None 0.6598 0.356008 0.0000 \n",
"97 16227 6542 9685 None 0.8305 0.403155 0.0000 \n",
"98 22767 11201 11566 None 1.1487 0.491984 0.5528 \n",
"99 39079 24517 14562 None 2.0000 0.627370 0.0000 \n",
2024-12-12 22:08:59 +01:00
"\n",
" expected_hit_rate expected_hit_rate_delta avg_cache_time \\\n",
2024-12-13 11:54:19 +01:00
"0 0.048961 0.001920 0.038411 \n",
"1 0.049341 -0.009150 0.040332 \n",
"2 0.049816 -0.017111 0.039100 \n",
"3 0.050196 -0.007703 0.041095 \n",
"4 0.050576 -0.015169 0.041100 \n",
2024-12-12 22:08:59 +01:00
".. ... ... ... \n",
2024-12-13 11:54:19 +01:00
"95 0.424145 -0.112888 0.308356 \n",
"96 0.483045 -0.127037 0.353400 \n",
"97 0.564169 -0.161013 0.407435 \n",
"98 0.682951 -0.190967 0.489995 \n",
"99 0.864665 -0.237295 0.627601 \n",
2024-12-12 22:08:59 +01:00
"\n",
" cache_time_delta avg_age expected_age age_delta age_delta in % \n",
2024-12-13 11:54:19 +01:00
"0 0.012470 0.023130 1.016189 -0.993059 -0.977238 \n",
"1 -0.000141 0.016009 0.795581 -0.779572 -0.979877 \n",
"2 -0.006394 0.013227 0.640718 -0.627490 -0.979355 \n",
"3 0.001398 0.015914 0.826598 -0.810683 -0.980747 \n",
"4 -0.005693 0.011848 0.683066 -0.671218 -0.982655 \n",
2024-12-12 22:08:59 +01:00
".. ... ... ... ... ... \n",
2024-12-13 11:54:19 +01:00
"95 0.002901 0.137645 0.624473 -0.486829 -0.779583 \n",
"96 0.002608 0.160020 0.617881 -0.457862 -0.741019 \n",
"97 -0.004280 0.185865 0.579650 -0.393785 -0.679350 \n",
"98 0.001989 0.224034 0.565071 -0.341037 -0.603530 \n",
"99 -0.000231 0.293713 0.517285 -0.223572 -0.432202 \n",
2024-12-12 22:08:59 +01:00
"\n",
"[100 rows x 15 columns]"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"access_count = pd.DataFrame.from_dict(cache.access_count, orient='index', columns=['access_count'])\n",
"hits = pd.DataFrame.from_dict(cache.hits, orient='index', columns=['hits'])\n",
"misses = pd.DataFrame.from_dict(cache.misses, orient='index', columns=['misses'])\n",
"mu = pd.DataFrame.from_dict({l: db.data[l].mu_value for l in range(database_object_count)}, orient='index', columns=['mu'])\n",
"lmbda = pd.DataFrame.from_dict({l: db.data[l].lambda_value for l in range(database_object_count)}, orient='index', columns=['lambda'])\n",
"\n",
"hit_rate = pd.DataFrame(stats['hit_rate'])\n",
"hit_rate.index = range(database_object_count)\n",
"optimal_hitrate = pd.DataFrame(BASE_FILE['optimal_hitrates'])\n",
"optimal_hitrate.index = range(database_object_count)\n",
"expected_hit_rate = pd.DataFrame(stats['expected_hit_rate'])\n",
"expected_hit_rate.index = range(database_object_count)\n",
"expected_hit_rate_delta = pd.DataFrame((hit_rate.to_numpy()-expected_hit_rate.to_numpy()), columns=['expected_hit_rate_delta'])\n",
"expected_hit_rate_delta.index = range(database_object_count)\n",
"avg_cache_time = pd.DataFrame(stats['avg_cache_time'])\n",
"avg_cache_time.index = range(database_object_count)\n",
"cache_time_delta = pd.DataFrame((hit_rate.to_numpy()-avg_cache_time.to_numpy()), columns=['cache_time_delta'])\n",
"cache_time_delta.index = range(database_object_count)\n",
"\n",
"avg_age = pd.DataFrame(stats['avg_age'])\n",
"avg_age.index = range(database_object_count)\n",
"expected_age = pd.DataFrame(stats['expected_age'])\n",
"expected_age.index = range(database_object_count)\n",
"age_delta = pd.DataFrame((avg_age.to_numpy()-expected_age.to_numpy()), columns=['age_delta'])\n",
"age_delta.index = range(database_object_count)\n",
"age_delta_p = pd.DataFrame(np.where(expected_age.to_numpy().T[0] != 0, age_delta.to_numpy().T[0] / expected_age.to_numpy().T[0], 0), columns=['age_delta in %'])\n",
"age_delta_p.index = range(database_object_count)\n",
"\n",
"merged = access_count.merge(hits, left_index=True, right_index=True).merge(misses, left_index=True, right_index=True) \\\n",
" .merge(mu, left_index=True, right_index=True).merge(lmbda, left_index=True, right_index=True) \\\n",
" .merge(hit_rate, left_index=True, right_index=True).merge(optimal_hitrate, left_index=True, right_index=True).merge(expected_hit_rate, left_index=True, right_index=True).merge(expected_hit_rate_delta, left_index=True, right_index=True) \\\n",
" .merge(avg_cache_time, left_index=True, right_index=True).merge(cache_time_delta, left_index=True, right_index=True) \\\n",
" .merge(avg_age, left_index=True, right_index=True).merge(expected_age, left_index=True, right_index=True).merge(age_delta, left_index=True, right_index=True).merge(age_delta_p, left_index=True, right_index=True)\n",
"merged.to_csv(f\"{TEMP_BASE_DIR}/details.csv\", index_label=\"obj_id\")\n",
"merged"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "01f8f9ee-c278-4a22-8562-ba02e77f5ddd",
"metadata": {},
"outputs": [
{
"data": {
2024-12-13 11:54:19 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAACVcAAAHWCAYAAAB5HisgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy80BEi2AAAACXBIWXMAAA9hAAAPYQGoP6dpAABpjUlEQVR4nOzdd5h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kkTnrrLPygx/8IEcddVSj62jRokWTB5XmtjZt2jTp8W6++eacdNJJ+dnPfpbrrrsuLVu2rNt25JFHZuTIkfPVyk5z4vDDD8/f//73XHDBBfUeQ3jggQfmwgsvzMEHH5wjjjgiF1988TyrqSiKfP3112nbtm298cUWWyy77bZbvbHTTjstiyyySIPxJGnduvVcrRMAAAD47+Z/yQIAAADmuWOPPTbTp0/PaaedNst5b775ZkqlUq688soG20qlUr3VjE488cSUSqW89tpr2W233dKpU6csuuiiOe6441IURd55551svfXW6dixY7p3756zzz677DmnT5+eY489Nt27d0/79u2z1VZb5Z133mkw74knnshmm22WTp06pV27dll//fXzyCOP1Jszo6Z//vOf2WWXXdKlS5f8+Mc/nuU1v/HGG/n5z3+erl27pl27dvnRj36Uv/3tb3XbZzxasSiKXHjhhbN9vNnjjz+ekSNHZs8996wXrJrh1FNPTf/+/XP66afnq6++arD93HPPTe/evdO2bdusv/76efnll8te47ddc801WW211dK2bdt07do1O+2000zv409+8pN06dIl7du3z8CBA3PeeeclSfbcc89ceOGFSVL2UW433HBDVltttXTo0CEdO3bMSiutVLfvrMzsvTNu3Ljsueee6dy5czp16pS99torkydPnu3xjjvuuHTt2jWXX355vWDVDIMHD85Pf/rTJMnUqVNz/PHHZ7XVVkunTp3Svn37rLvuunnggQca7FdbW5vzzjsvK620Utq0aZNFF100m222WZ5++ukGc2+77basuOKKad26dQYMGJC77767wZx33303e++9dxZbbLG6eZdffvlsr+9f//pX/vSnP2WjjTaqF6yaYciQIdlwww3zxz/+Mf/617+SJCuuuGI23HDDste0+OKL52c/+1m9seHDh2fAgAFp06ZNFltssRxwwAH59NNP6+271FJL5ac//WlGjhyZ1VdfPW3bts2ll1462/pnZ6mllsqee+5Z93rGz9jDDz+cQw45JIsuumg6d+6cAw44IFOnTs3EiROz++67p0uXLunSpUt+85vfNHi0ZqXXBAAAAMz/hKsAAACAea5Pnz7Zfffd87//+7957733mvTYO+64Y2pra3PaaadlzTXXzMknn5zhw4dnk002yeKLL57TTz89/fr1yxFHHJHRo0c32P+UU07J3/72txx11FE55JBDMmrUqAwaNKhe8Oj+++/Peuutl0mTJuWEE07IH/7wh0ycODEbbbRRnnzyyQbH/PnPf57JkyfnD3/4Q/bbb7+Z1v7hhx9m7bXXzsiRI3PQQQfllFNOyddff52tttoqt956a5JkvfXWq3vk2SabbJI///nPDR6B9k133HFHkmT33Xcvu71FixbZZZdd8umnnzYIh1199dU5//zzM2TIkBxzzDF5+eWXs9FGG+XDDz+c6fmS/9zD3XffPf37988555yToUOH5r777st6662XiRMn1s0bNWpU1ltvvfzzn//MoYcemrPPPjsbbrhh/vrXvyZJDjjggGyyySZJUnedM6511KhR2XnnndOlS5ecfvrpOe2007LBBhs0uIbG2GGHHfL555/n1FNPzQ477JArr7wyw4YNm+U+Y8eOzSuvvJJtttkmHTp0mO05Jk2alD/+8Y/ZYIMNcvrpp+fEE0/Mv//97wwePDjPP/98vbn77LNPhg4dml69euX000/P0UcfnTZt2uTxxx+vN+/hhx/OQQcdlJ122ilnnHFGvv7662y//fb55JNP6uZ8+OGH+dGPfpR77703Bx98cM4777z069cv++yzT4YPHz7Lmu+6665Mnz59pu+h5D/vr2nTptWFunbccceMHj06H3zwQYNa33vvvey00051YwcccECOPPLIrLPOOjnvvPOy11575dprr83gwYMbrPj16quvZuedd84mm2yS8847L6usssosa/8ufvWrX2Xs2LEZNmxYttpqq1x22WU57rjjsuWWW2b69On5wx/+kB//+Mc588wzG/wMNuaaAAAAgPlcAQAAADCPXHHFFUWS4qmnnipef/31okWLFsUhhxxSt3399dcvBgwYUPd6/PjxRZLiiiuuaHCsJMUJJ5xQ9/qEE04okhT7779/3di0adOKJZZYoiiVSsVpp51WN/7pp58Wbdu2LfbYY4+6sQceeKBIUiy++OLFpEmT6sZvvPHGIklx3nnnFUVRFLW1tUX//v2LwYMHF7W1tXXzJk+eXPTp06fYZJNNGtS08847V3R/hg4dWiQpHnroobqxzz//vOjTp0+x1FJLFdOnT693/UOGDJntMbfZZpsiSfHpp5/OdM6IESOKJMX5559fFMX/3fe2bdsW//rXv+rmPfHEE0WS4rDDDmtwjTO8+eabRfPmzYtTTjml3jleeumlokWLFnXj06ZNK/r06VP07t27QW3fvK9Dhgwpyv0T1qGHHlp07NixmDZt2mzvwbfN7L2z995715u37bbbFgsvvPAsj3X77bcXSYpzzz23onNPmzatmDJlSr2xTz/9tFhsscXqnf/+++8vktT7+Zjhm/cnSdGqVati3LhxdWMvvPBCkaS44IIL6sb22WefokePHsXHH39c71g77bRT0alTp2Ly5MkzrXnG+/K5556b6Zxnn322SFIcfvjhRVEUxauvvtqghqIoioMOOqhYaKGF6s730EMPFUmKa6+9tt68u+++u8F47969iyTF3XffPdM6ZmbAgAHF+uuvX3Zb79696/WCGX3q2z/ja62
2024-12-12 22:08:59 +01:00
"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_size_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.savefig(f\"{TEMP_BASE_DIR}/objects_in_cache_over_time.pdf\")\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "f30a0497-9b2e-4ea9-8ebf-6687de19aaa9",
"metadata": {},
"outputs": [
{
"data": {
2024-12-13 11:54:19 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAArYAAAIjCAYAAAD2qFgcAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy80BEi2AAAACXBIWXMAAA9hAAAPYQGoP6dpAAA+EklEQVR4nO3de1yUZf7/8feAMqAGqCgnSTzlOTFdDc1DLUZmlh3VXEGyMtNNY9Okg5S2YplmB8vVTa12+2UesnYzTVErlbQ85DmNRMsExQOgFijcvz/6MtsIKIzA4OXr+XjM4+Fc93Xf92fua8Z5e3vd99gsy7IEAAAAXOY83F0AAAAAUB4ItgAAADACwRYAAABGINgCAADACARbAAAAGIFgCwAAACMQbAEAAGAEgi0AAACMQLAFAACAEQi2AFABvvnmG3Xp0kU1a9aUzWbT1q1b3V2Sk/DwcN12220ur2+z2fTcc8+VX0GllJaWJpvNppdfftnlbQwZMkTh4eHlVlN5b68k8+bNk81mU1pamqPtUscRMA3BFriM7dy5U3/5y18UGhoqu92ukJAQDRo0SDt37nR3aVe0s2fP6t5779Xx48f1yiuv6L333lPDhg3dXRYAGK+auwsA4JrFixdr4MCBqlOnjoYOHapGjRopLS1Nb7/9thYuXKgPPvhAd955p7vLvCKlpqbqwIEDmj17th588EF3l4MKNnv2bBUUFLi7DAAi2AKXpdTUVA0ePFiNGzfWl19+qXr16jmWjRo1St26ddPgwYO1bds2NW7c2I2VFnXmzBnVqFHD3WVUqCNHjkiS/P393VsIKkX16tXdXQKA/8NUBOAyNGXKFJ05c0azZs1yCrWSFBAQoH/84x86ffq0XnrpJadlhw4d0tChQxUSEiK73a5GjRpp+PDhysvLc/Q5efKkHn/8cYWHh8tut6tBgwaKiYlRZmampOLn+UnSmjVrZLPZtGbNGkdbz5491aZNG23atEndu3dXjRo19NRTT0mSPv74Y/Xp08dRS5MmTTRx4kTl5+c7bbdwG7t27dKNN96oGjVqKDQ0tMhrk6TffvtNzz33nK655hp5e3srODhYd911l1JTUx19CgoKNH36dLVu3Vre3t4KDAzUsGHDdOLEiVId+1WrVqlbt26qWbOm/P39dccdd2j37t2O5UOGDFGPHj0kSffee69sNpt69ux5wW2ePHlSo0ePVlhYmOx2u5o2baoXX3yxyFnAl19+WV26dFHdunXl4+OjDh06aOHChcVu81//+pc6deqkGjVqqHbt2urevbs+//zzIv3Wrl2rTp06ydvbW40bN9a7775bquNwvgMHDujRRx9V8+bN5ePjo7p16+ree+8t8j4pfP+sXbtWjz32mOrVqyd/f38NGzZMeXl5OnnypGJiYlS7dm3Vrl1bY8eOlWVZxe7zlVdeUcOGDeXj46MePXpox44dRfosWbJEbdq0kbe3t9q0aaOPPvqo2G2V5die7/w5tn+cBzxr1iw1adJEdrtdf/rTn/TNN9+Uaps7d+7UTTfdJB8fHzVo0EAvvPDCBc8Kf/7554qIiJC3t7datWqlxYsXl2o/gGk4Ywtchv7zn/8oPDxc3bp1K3Z59+7dFR4erk8//dTR9ssvv6hTp046efKkHn74YbVo0UKHDh3SwoULdebMGXl5eenUqVPq1q2bdu/erQceeEDXXXedMjMz9cknn+jnn39WQEBAmWs9duyYevfurQEDBugvf/mLAgMDJf0ecGrVqqX4+HjVqlVLq1at0vjx45Wdna0pU6Y4bePEiRO65ZZbdNddd+m+++7TwoUL9eSTT6pt27bq3bu3JCk/P1+33XabkpOTNWDAAI0aNUo5OTlasWKFduzYoSZNmkiShg0bpnnz5ikuLk6PPfaY9u/frzfeeENbtmzRunXrLnj2beXKlerdu7caN26s5557Tr/++qtef/11de3aVZs3b1Z4eLiGDRum0NBQTZo0SY899pj+9Kc/OV5zcc6cOaMePXro0KFDGjZsmK6++mqtX79eCQkJOnz4sKZPn+7o++qrr+r222/XoEGDlJeXpw8++ED33nuv/vvf/6pPnz6Ofs8//7yee+45denSRRMmTJCXl5c2bNigVatW6eabb3b0++GHH3TPPfdo6NChio2N1Zw5czRkyBB16NBBrVu3Lv0g6/eL5davX68BAwaoQYMGSktL01tvvaWePXtq165dRc7S//Wvf1VQUJCef/55ff3115o1a5b8/f21fv16XX311Zo0aZKWLl2qKVOmqE2bNoqJiXFa/91331VOTo5GjBih3377Ta+++qpuuukmbd++3XG8P//8c919991q1aqVkpKSdOzYMcXFxalBgwZF6i/tsS2L999/Xzk5ORo2bJhsNpteeukl3XXXXfrxxx8v+D5LT0/XjTfeqHPnzmnc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lmVp6NChjjZPT0917Nix2Hr69eun0NBQx/NOnTqpc+fOjnEoHK/Y2Fj5+fk5+vXq1UutWrW6YP0lHduy6t+/v2rXru14XnisL3Z8ly5dquuvv16dOnVytNWrV0+DBg0qtn9ISIjTZ9bX11cxMTHasmWL0tPTXa4fuBwxFQG4zBQG1sKAW5I/BuCjR48qOztbbdq0ueA6qampuvvuu8un0P8TGhoqLy+vIu07d+7UM888o1WrVik7O9tpWVZWltPzBg0aFAlltWvX1rZt2xzPU1NT1bx5c1WrVvJfa/v27VNWVpbq169f7PLCi76Kc+DAAUlS8+bNiyxr2bKlli9frtOnT6tmzZolbqOkmrZt21ZkrnRxNf33v//VCy+8oK1btyo3N9fR/sdjk5qaKg8Pj2LD2/muvvrqIm21a9cu9XzjP/r111+VlJSkuXPn6tChQ07zYs8fz+L2XRg+w8LCirQXV0+zZs2KtF1zzTX68MMPJf1vvIrr17x58yKBtTTHtqzOf42FIfdix/fAgQPq3Llzkfb
2024-12-12 22:08:59 +01:00
"text/plain": [
"<Figure size 800x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from collections import Counter\n",
"# Count occurrences of each number\n",
"count = Counter([l.lambda_value for l in db.data.values()])\n",
"\n",
"# Separate the counts into two lists for plotting\n",
"x = list(count.keys()) # List of unique numbers\n",
"y = list(count.values()) # List of their respective counts\n",
"\n",
"# Plot the data\n",
"plt.figure(figsize=(8, 6))\n",
"plt.bar(x, y, color='skyblue')\n",
"\n",
"# Adding labels and title\n",
"plt.xlabel('Number')\n",
"plt.ylabel('Occurrences')\n",
"plt.title('Occurance of each lambda in db')\n",
"plt.savefig(f\"{TEMP_BASE_DIR}/lambda_distribution.pdf\")\n",
"\n",
"# Show the plot\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "c192564b-d3c6-40e1-a614-f7a5ee787c4e",
"metadata": {},
"outputs": [
{
"data": {
2024-12-13 11:54:19 +01:00
"image/png": "iVBORw0KGgoAAAAN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8WLVrA3t7ebJmVlRU8PDyQkZFxz9snqq8YmomoxmzcuBGDBg2Cvb09IiMj4efnB1tbW+XDT3f78FtZ4cbKysriujvD+J08PDxKLdNqtXB1dUVmZqayLDMzExqNBg0bNizXNgoLC9G1a1ccPXoUHTp0wPDhw+Hq6gorKyucP38eq1atQkFBQZlj+quePXvCw8MD69atw7vvvgutVotNmzYhLy8Pw4cPN6t95ZVX4Orqik8//RTvvfce3n33XVhZWaFPnz744IMPyrz6/VdbtmzBjRs3MHLkSLPAqdFoMGzYMLz99ttYs2YNoqKilN4At6+6q6lI7c2bN1FcXIy5c+fetebOX0QWLVoEf39/rFy5Em+++SbefPNNGAwG/OMf/8B7772nfO/utUeenp4AgD///FP1GO6UlZUFjUZj9i8hJTw8PCBJErKysiq0zbLcLfxbWVmV+vAkEZUfQzMR1Zg5c+bAYDAgMTERzZs3N1u3bt26ahlDamoqWrZsabbMZDLhxo0bZmHY0dERsizj+vXrpUJPampqqe1u3boVR48exejRo7F8+XKzdevWrVP+qb48tFothgwZgg8//BB79+5FZGQkvvrqK2g0GgwdOtSsVpIkjBo1CqNGjcKNGzfw008/Ye3atdiwYQPOnDmDEydOlHn7wp1Kbr9YuXIlVq5cedeaktDs5OQEoHwh8s5aPz8/i7UODg6QJAnXr19X3S5wOxS+8soreOW
2024-12-12 22:08:59 +01:00
"text/plain": [
"<Figure size 800x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Plotting lambda against access_count.\n",
"\n",
"plt.figure(figsize=(8, 6))\n",
"plt.scatter(merged['lambda'], merged['access_count'], alpha=0.7, edgecolor='k')\n",
"plt.title('Lambda vs Access Count', fontsize=14)\n",
"plt.xlabel('Lambda', fontsize=12)\n",
"plt.ylabel('Access Count', fontsize=12)\n",
"plt.grid(alpha=0.3)\n",
"\n",
"plt.savefig(f\"{TEMP_BASE_DIR}/lambda_vs_access_count.pdf\")\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "00a12eea-c805-4209-9143-48fa65619873",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAArcAAAIjCAYAAAAZajMiAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy80BEi2AAAACXBIWXMAAA9hAAAPYQGoP6dpAABEDElEQVR4nO3dfXzO9f////sxsxMnO3OyGYuZ5TxENHLy0aJSUStv3sppUZGkE1ahkCHvEpG33oV6V4qik/cbCRFJYs6iYm0RNiezE/Y2bM/vH/12/Drapu3YseOYV7fr5XJcLh3P19njeHiNe689X6/DZowxAgAAACzAy9MFAAAAAK5CuAUAAIBlEG4BAABgGYRbAAAAWAbhFgAAAJZBuAUAAIBlEG4BAABgGYRbAAAAWAbhFgAAAJZBuAXwl7Z9+3Z17NhRVatWlc1m065duzxdkoMGDRrotttu83QZTrPZbHruuefK/TjdunVTt27d7O+//PJL2Ww2LV++vEz7nTlzppo0aaL8/PwyVugZzz33nGw2m0v3+cde79+/X97e3tq3b59LjwM4i3ALuMH333+ve++9V3Xr1pWvr6/Cw8M1YMAAff/9954u7S/t4sWLuueee5Senq6XX35Zb7/9turXr+/pslBBZGVlacaMGRo3bpy8vPjnsjjNmjVTr169NHHiRE+XAkiSvD1dAGB1H330kfr376+QkBANGzZMkZGRSklJ0RtvvKHly5dr6dKluvPOOz1d5l9SUlKSfvnlF73++uu6//77PV2OJf3vf/+Tt/eV+U/Nm2++qUuXLql///6eLqXCe/DBB3XrrbcqKSlJUVFRni4Hf3FX5t84wBUiKSlJ9913nxo2bKhNmzapVq1a9mWPPvqoOnfurPvuu0979uxRw4YNPVhpYTk5OapSpYqnyyhXJ06ckCQFBQV5thAL8/Pz83QJTlu0aJHuuOOOP/0Mly5dUn5+vnx8fNxUWcUTGxur4OBgLVmyRJMnT/Z0OfiL4/csQDl68cUXlZOTo4ULFzoEW0mqWbOm/vnPf+rcuXOaOXOmw7KjR49q2LBhCg8Pl6+vryIjI/XQQw/pwoUL9nUyMjL02GOPqUGDBvL19VW9evU0cOBAnTp1SpK0ePFi2Ww2paSkOOy7YC7il19+aR/r1q2bWrRooR07dqhLly6qUqWKnn76aUnSxx9/rF69etlriYqK0pQpU5SXl+ew34J97N+/X//3f/+nKlWqqG7duoU+mySdP39ezz33nK6++mr5+fmpTp06uuuuu5SUlGRfJz8/X7Nnz1bz5s3l5+en0NBQjRgxQmfOnClR79evX6/OnTuratWqCgoKUu/evXXgwAH78sGDB6tr166SpHvuuUc2m81hHmFRMjIyNGbMGEVERMjX11eNGjXSjBkzCs3HnDVrljp27KgaNWrI399fbdu2LXbu57///W+1b99eVapUUXBwsLp06aLPP/+80HqbN29W+/bt5efnp4YNG+qtt9760x6kpKTIZrNp1qxZmjdvnho2bKgqVaqoR48eOnLkiIwxmjJliurVqyd/f3/17t1b6enpDvsobs5sgwYNNHjw4D+t4Y/bF8wBPXTokAYPHqygoCAFBgZqyJAhysnJ+dP9SdLChQsVFRUlf39/tW/fXl999VWx6+bl5enpp59WWFiYqlatqjvuuENHjhz502MkJydrz549io2NdRj/fU9nz56tqKgo+fr6av/+/ZL+/LyTfjv3GjRoUOiYRc2PtdlsGjVqlFauXKkWLVrI19dXzZs31+rVqwttv3nzZl133XXy8/NTVFSU/vnPfxb7+f7973+rbdu28vf3V0hIiPr161dkX0ra68qVK6tbt276+OOPiz0m4C5cuQXK0aeffqoGDRqoc+fORS7v0qWLGjRooP/85z/2sWPHjql9+/bKyMjQ8OHD1aRJEx09elTLly9XTk6OfHx8dPbsWXXu3FkHDhzQ0KFDde211+rUqVP65JNP9Ouvv6pmzZqlrvX06dO65ZZb1K9fP917770KDQ2V9FtIrlatmsaOHatq1app/fr1mjhxorKysvTiiy867OPMmTO6+eabddddd6lv375avny5xo0bp5YtW+qWW26R9FvYuO2227Ru3Tr169dPjz76qLKzs7V27Vrt27fP/ivNESNGaPHixRoyZIhGjx6t5ORkvfrqq0pMTNS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mbQoEGXPX5R20+aNMlIMkOHDnVY78477zQ1atS47L4uXLhgateubVq3bm1yc3Pt4wsXLjSSTNeuXe1jBX+2devWtf9sGWPMBx98YCSZV1555bLHevbZZ40kk52d7TBe0NOAgABz4sQJh2UlPe8GDRpk6tevX+iYBb35PUnGx8fHHDp0yGGfkszcuXPtY3369DF+fn7ml19+sY/t37/fVKpUyWGfKSkpplKlSuaFF15wOM7evXuNt7e3fbw0vS7w7rvvGklm27ZthZYB7sS0BKCcZGdnS5KqV69+2fUKlmdlZSk/P18rV67U7bffrnbt2hVat+BXlh9++KFatWpV5I1ozj72x9fXV0OGDCk0/vurW9nZ2Tp16pQ6d+6snJwc/fDDDw7rVqtWTffee6/9vY+Pj9q3b6+ff/7ZPvbhhx+qZs2aeuSRR4qtfdmyZQoMDNRNN92kU6dO2V9t27ZVtWrVtGHDhmI/x/Hjx7Vr1y4NHjxYISEh9vFrrrlGN910k/773/+WoBuFLVu2TJ07d1ZwcLBDTbGxscrLy9OmTZvs6/6+Z2fOnFFmZqY6d+6snTt32sdXrlyp/Px8TZw4sdCd+H/8M2zWrJnD1f9atWqpcePGDn29nHvuuUeBgYH29x06dJAk3XvvvQ43e3Xo0EEXLlzQ0aNHS7TfsnjwwQcd3nfu3FmnT59WVlZWsdt89913OnHihB588EGH+a2DBw92+Hy/N3DgQIefwbvvvlt16tT50/Pg9OnT8vb2VrV
"text/plain": [
"<Figure size 800x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from collections import Counter\n",
"# Count occurrences of each number\n",
"count = Counter(np.array([l.mu_value if l.mu_value is not None else 0.0 for l in db.data.values() ]).round(0))\n",
"\n",
"# Separate the counts into two lists for plotting\n",
"x = list(count.keys()) # List of unique numbers\n",
"y = list(count.values()) # List of their respective counts\n",
"\n",
"# Plot the data\n",
"plt.figure(figsize=(8, 6))\n",
"plt.bar(x, y, color='skyblue')\n",
"\n",
"# Adding labels and title\n",
"plt.xlabel('Number')\n",
"plt.ylabel('Occurrences')\n",
"plt.title('Occurance of each mu in db (rounded)')\n",
"\n",
"# Show the plot\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "adbfeb40-76bd-4224-ac45-65c7b2b2cb7b",
"metadata": {},
"outputs": [],
"source": [
"def plot_requests(object_id: int):\n",
" mu = db.mu_values[object_id]\n",
" lmb = db.lambda_values[object_id]\n",
" rq_log = np.array(cache.request_log[object_id])\n",
" df = rq_log[1:] - rq_log[:-1]\n",
" pd.DataFrame(df, columns=[f\"{object_id}, mu:{mu:.2f}, lambda: {lmb:.2f}\"]).plot()"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "1f550686-3463-4e50-be83-ceafb27512b0",
"metadata": {},
"outputs": [],
"source": [
"def print_rate(object_id: int):\n",
" # Calculate time intervals between consecutive events\n",
" intervals = np.diff(np.array(cache.request_log[object_id])) # Differences between each event time\n",
" \n",
" # Calculate the rate per second for each interval\n",
" rates = 1 / intervals # Inverse of the time interval gives rate per second\n",
" \n",
" # Optional: Calculate the average event rate over all intervals\n",
" average_rate = np.mean(rates)\n",
" print(\"Average event rate per second:\", average_rate)\n",
" print(\"The mu is: \", db.lambda_values[object_id])"
]
},
{
"cell_type": "code",
"execution_count": 25,
2024-12-13 11:54:19 +01:00
"id": "5b6dac2e-8596-4e7c-97d8-aaf9632e4154",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"count 0.0\n",
"mean NaN\n",
"std NaN\n",
"min NaN\n",
"25% NaN\n",
"50% NaN\n",
"75% NaN\n",
"max NaN\n",
"Name: lambda, dtype: float64"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"merged[merged['hits']==0]['lambda'].describe()"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "29393374-e379-42c8-8333-abfecc18e828",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"count 100.000000\n",
"mean 0.162692\n",
"std 0.247757\n",
"min 0.050200\n",
"25% 0.063050\n",
"50% 0.086800\n",
"75% 0.148775\n",
"max 2.000000\n",
"Name: lambda, dtype: float64"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"merged[merged['hits']>0]['lambda'].describe()"
]
},
{
"cell_type": "code",
"execution_count": 27,
2024-12-12 22:08:59 +01:00
"id": "b47990b1-0231-43ac-8bc5-8340abe4a8b3",
"metadata": {},
"outputs": [],
"source": [
"# os.makedirs(EXPERIMENT_BASE_DIR, exist_ok=True)\n",
"# folder_name = experiment_name.replace(\" \", \"_\").replace(\"(\", \"\").replace(\")\", \"\").replace(\".\", \"_\")\n",
"# folder_path = os.path.join(EXPERIMENT_BASE_DIR, folder_name)\n",
"# os.makedirs(folder_path, exist_ok=True)\n"
]
},
{
"cell_type": "code",
2024-12-13 11:54:19 +01:00
"execution_count": 28,
2024-12-12 22:08:59 +01:00
"id": "db83cad4-7cc6-4702-ae3a-d1af30a561d2",
"metadata": {},
"outputs": [],
"source": [
"# file_names = os.listdir(TEMP_BASE_DIR)\n",
" \n",
"# for file_name in file_names:\n",
"# shutil.move(os.path.join(TEMP_BASE_DIR, file_name), folder_path)"
]
}
],
"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
}