Add affinity_parallelism_model/src/affinity_parallelism_model/core.py
This commit is contained in:
commit
ef722eebd6
1 changed files with 48 additions and 0 deletions
|
|
@ -0,0 +1,48 @@
|
|||
import random
|
||||
import math
|
||||
import statistics
|
||||
from dataclasses import dataclass
|
||||
from typing import Dict
|
||||
|
||||
|
||||
@dataclass
|
||||
class EffectSummary:
|
||||
"""Dataclass für die Zusammenfassung der simulierten Effekte."""
|
||||
bandwidth: float
|
||||
retry_tail: float
|
||||
|
||||
|
||||
def simulate_effects(parallelism_level: int, affinity_type: str) -> Dict[str, float]:
|
||||
"""Simuliert die Auswirkungen verschiedener Parallelitäts- und Affinitätseinstellungen
|
||||
auf Bandbreite und Retry-Tail.
|
||||
|
||||
Args:
|
||||
parallelism_level (int): Anzahl der parallelen Prozesse oder Threads.
|
||||
affinity_type (str): Affinitätsmodus, z. B. 'randomized' oder 'enforced'.
|
||||
|
||||
Returns:
|
||||
dict: Zusammenfassung der simulierten Effekte mit 'bandwidth' und 'retry_tail'.
|
||||
"""
|
||||
if not isinstance(parallelism_level, int) or parallelism_level <= 0:
|
||||
raise ValueError("parallelism_level muss eine positive ganze Zahl sein.")
|
||||
if not isinstance(affinity_type, str) or affinity_type not in {"randomized", "enforced"}:
|
||||
raise ValueError("affinity_type muss 'randomized' oder 'enforced' sein.")
|
||||
|
||||
# Simulation: Basisannahmen abhängig von Affinitätsmodus
|
||||
base_bandwidth = 100.0 if affinity_type == "enforced" else 80.0
|
||||
base_retry_tail = 5.0 if affinity_type == "enforced" else 10.0
|
||||
|
||||
# Parallelismus wirkt sich sublinear auf die Bandbreite aus
|
||||
bandwidth_factor = math.log2(parallelism_level + 1)
|
||||
|
||||
# Zufällige Variation zur Modellierung stochastischen Verhaltens
|
||||
random_variation = random.uniform(0.9, 1.1)
|
||||
|
||||
bandwidth = base_bandwidth * bandwidth_factor * random_variation
|
||||
|
||||
# Retry-Tail wächst mit Parallelität, aber weniger stark bei enforced Affinity
|
||||
retry_tail = base_retry_tail * (parallelism_level ** 0.3) * (1.2 if affinity_type == "randomized" else 0.9)
|
||||
|
||||
summary = EffectSummary(bandwidth=float(round(bandwidth, 3)), retry_tail=float(round(retry_tail, 3)))
|
||||
|
||||
return {"bandwidth": summary.bandwidth, "retry_tail": summary.retry_tail}
|
||||
Loading…
Reference in a new issue