Buckets:
| #!/usr/bin/env python3 | |
| import numpy as np | |
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| import seaborn as sns | |
| from scipy import stats | |
| from scipy.stats import ttest_ind, mannwhitneyu, kruskal | |
| import time | |
| import threading | |
| import multiprocessing | |
| from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor | |
| import psutil | |
| import gc | |
| import warnings | |
| warnings.filterwarnings('ignore') | |
| from typing import Dict, List, Tuple, Any, Optional, Union, Callable | |
| import json | |
| import pickle | |
| from dataclasses import dataclass, field | |
| from datetime import datetime, timedelta | |
| import random | |
| import queue | |
| import logging | |
| class StressTestConfig: | |
| max_load_multiplier: float = 10.0 | |
| load_increment: float = 0.5 | |
| test_duration: int = 60 | |
| warmup_duration: int = 10 | |
| max_threads: int = 10 | |
| max_processes: int = 4 | |
| memory_pressure_levels: List[float] = field(default_factory=lambda: [0.5, 0.7, 0.8, 0.9, 0.95]) | |
| memory_allocation_size: int = 1024 * 1024 | |
| latency_threshold: float = 1.0 | |
| throughput_threshold: float = 1000 | |
| error_rate_threshold: float = 0.01 | |
| confidence_level: float = 0.95 | |
| min_sample_size: int = 30 | |
| class StressTestResult: | |
| test_name: str = "" | |
| timestamp: datetime = field(default_factory=datetime.now) | |
| duration: float = 0.0 | |
| throughput_history: List[float] = field(default_factory=list) | |
| latency_history: List[float] = field(default_factory=list) | |
| error_rate_history: List[float] = field(default_factory=list) | |
| memory_usage_history: List[float] = field(default_factory=list) | |
| cpu_usage_history: List[float] = field(default_factory=list) | |
| load_levels: List[float] = field(default_factory=list) | |
| failure_load: Optional[float] = None | |
| failure_reason: Optional[str] = None | |
| performance_degradation: float = 0.0 | |
| stability_score: float = 0.0 | |
| peak_memory_usage: float = 0.0 | |
| peak_cpu_usage: float = 0.0 | |
| average_memory_usage: float = 0.0 | |
| average_cpu_usage: float = 0.0 | |
| class LoadTester: | |
| def __init__(self, config: StressTestConfig = None): | |
| self.config = config or StressTestConfig() | |
| self.results = [] | |
| self.monitoring_active = False | |
| def generate_load(self, memory_system, load_level: float, duration: float) -> Dict[str, Any]: | |
| start_time = time.time() | |
| operations = 0 | |
| errors = 0 | |
| latencies = [] | |
| target_ops_per_sec = int(1000 * load_level) | |
| while time.time() - start_time < duration: | |
| op_start = time.time() | |
| try: | |
| key = f"load_test_{operations}_{random.randint(0, 10000)}" | |
| value = f"value_{operations}_{random.randint(0, 10000)}" | |
| if memory_system.store(key, value): | |
| retrieved = memory_system.retrieve(key) | |
| if retrieved is None: | |
| errors += 1 | |
| else: | |
| errors += 1 | |
| operations += 1 | |
| latency = time.time() - op_start | |
| latencies.append(latency) | |
| if operations % target_ops_per_sec == 0: | |
| time.sleep(1.0) | |
| except Exception as e: | |
| errors += 1 | |
| logging.error(f"Load test error: {e}") | |
| total_time = time.time() - start_time | |
| throughput = operations / total_time | |
| error_rate = errors / operations if operations > 0 else 0 | |
| avg_latency = np.mean(latencies) if latencies else 0 | |
| return { | |
| 'throughput': throughput, | |
| 'latency': avg_latency, | |
| 'error_rate': error_rate, | |
| 'operations': operations, | |
| 'errors': errors | |
| } | |
| def stress_test_system(self, memory_system, system_name: str) -> StressTestResult: | |
| print(f"๐ฅ Starting stress test for {system_name}") | |
| result = StressTestResult(test_name=system_name) | |
| start_time = time.time() | |
| print(f" ๐ฅ Warmup phase ({self.config.warmup_duration}s)...") | |
| self.generate_load(memory_system, 0.1, self.config.warmup_duration) | |
| print(f" ๐ฅ Stress testing phase...") | |
| load_level = 0.1 | |
| while load_level <= self.config.max_load_multiplier: | |
| print(f" Testing load level: {load_level:.1f}x") | |
| load_result = self.generate_load(memory_system, load_level, 10) | |
| result.load_levels.append(load_level) | |
| result.throughput_history.append(load_result['throughput']) | |
| result.latency_history.append(load_result['latency']) | |
| result.error_rate_history.append(load_result['error_rate']) | |
| if (load_result['latency'] > self.config.latency_threshold or | |
| load_result['error_rate'] > self.config.error_rate_threshold): | |
| result.failure_load = load_level | |
| result.failure_reason = f"Latency: {load_result['latency']:.3f}s, Error rate: {load_result['error_rate']:.3f}" | |
| print(f" โ System failed at load level {load_level:.1f}x") | |
| break | |
| memory_usage = psutil.virtual_memory().percent | |
| cpu_usage = psutil.cpu_percent() | |
| result.memory_usage_history.append(memory_usage) | |
| result.cpu_usage_history.append(cpu_usage) | |
| load_level += self.config.load_increment | |
| result.duration = time.time() - start_time | |
| if result.throughput_history: | |
| result.performance_degradation = self._calculate_performance_degradation(result) | |
| result.stability_score = self._calculate_stability_score(result) | |
| result.peak_memory_usage = max(result.memory_usage_history) if result.memory_usage_history else 0 | |
| result.peak_cpu_usage = max(result.cpu_usage_history) if result.cpu_usage_history else 0 | |
| result.average_memory_usage = np.mean(result.memory_usage_history) if result.memory_usage_history else 0 | |
| result.average_cpu_usage = np.mean(result.cpu_usage_history) if result.cpu_usage_history else 0 | |
| print(f" โ Stress test completed for {system_name}") | |
| return result | |
| def _calculate_performance_degradation(self, result: StressTestResult) -> float: | |
| if len(result.throughput_history) < 2: | |
| return 0.0 | |
| peak_throughput = max(result.throughput_history) | |
| final_throughput = result.throughput_history[-1] | |
| if peak_throughput > 0: | |
| degradation = (peak_throughput - final_throughput) / peak_throughput | |
| return max(0, degradation) | |
| return 0.0 | |
| def _calculate_stability_score(self, result: StressTestResult) -> float: | |
| if len(result.throughput_history) < 2: | |
| return 1.0 | |
| mean_throughput = np.mean(result.throughput_history) | |
| std_throughput = np.std(result.throughput_history) | |
| if mean_throughput > 0: | |
| cv = std_throughput / mean_throughput | |
| stability_score = max(0, 1 - cv) | |
| return stability_score | |
| return 1.0 | |
| class ConcurrentTester: | |
| def __init__(self, config: StressTestConfig = None): | |
| self.config = config or StressTestConfig() | |
| def concurrent_read_test(self, memory_system, num_threads: int = 5, duration: int = 30) -> Dict[str, Any]: | |
| print(f"๐ Testing concurrent reads with {num_threads} threads") | |
| results = { | |
| 'total_operations': 0, | |
| 'total_errors': 0, | |
| 'operations_per_thread': [], | |
| 'errors_per_thread': [], | |
| 'latencies_per_thread': [] | |
| } | |
| def read_worker(thread_id: int): | |
| operations = 0 | |
| errors = 0 | |
| latencies = [] | |
| start_time = time.time() | |
| while time.time() - start_time < duration: | |
| try: | |
| op_start = time.time() | |
| key = f"concurrent_read_{random.randint(0, 1000)}" | |
| result = memory_system.retrieve(key) | |
| latency = time.time() - op_start | |
| latencies.append(latency) | |
| operations += 1 | |
| if result is None: | |
| errors += 1 | |
| except Exception as e: | |
| errors += 1 | |
| operations += 1 | |
| logging.error(f"Concurrent read error in thread {thread_id}: {e}") | |
| return { | |
| 'operations': operations, | |
| 'errors': errors, | |
| 'latencies': latencies | |
| } | |
| with ThreadPoolExecutor(max_workers=num_threads) as executor: | |
| futures = [executor.submit(read_worker, i) for i in range(num_threads)] | |
| for future in futures: | |
| thread_result = future.result() | |
| results['operations_per_thread'].append(thread_result['operations']) | |
| results['errors_per_thread'].append(thread_result['errors']) | |
| results['latencies_per_thread'].extend(thread_result['latencies']) | |
| results['total_operations'] = sum(results['operations_per_thread']) | |
| results['total_errors'] = sum(results['errors_per_thread']) | |
| return results | |
| def concurrent_write_test(self, memory_system, num_threads: int = 5, duration: int = 30) -> Dict[str, Any]: | |
| print(f"๐ Testing concurrent writes with {num_threads} threads") | |
| results = { | |
| 'total_operations': 0, | |
| 'total_errors': 0, | |
| 'operations_per_thread': [], | |
| 'errors_per_thread': [], | |
| 'latencies_per_thread': [] | |
| } | |
| def write_worker(thread_id: int): | |
| operations = 0 | |
| errors = 0 | |
| latencies = [] | |
| start_time = time.time() | |
| while time.time() - start_time < duration: | |
| try: | |
| op_start = time.time() | |
| key = f"concurrent_write_{thread_id}_{operations}" | |
| value = f"value_{thread_id}_{operations}_{random.randint(0, 10000)}" | |
| success = memory_system.store(key, value) | |
| latency = time.time() - op_start | |
| latencies.append(latency) | |
| operations += 1 | |
| if not success: | |
| errors += 1 | |
| except Exception as e: | |
| errors += 1 | |
| operations += 1 | |
| logging.error(f"Concurrent write error in thread {thread_id}: {e}") | |
| return { | |
| 'operations': operations, | |
| 'errors': errors, | |
| 'latencies': latencies | |
| } | |
| with ThreadPoolExecutor(max_workers=num_threads) as executor: | |
| futures = [executor.submit(write_worker, i) for i in range(num_threads)] | |
| for future in futures: | |
| thread_result = future.result() | |
| results['operations_per_thread'].append(thread_result['operations']) | |
| results['errors_per_thread'].append(thread_result['errors']) | |
| results['latencies_per_thread'].extend(thread_result['latencies']) | |
| results['total_operations'] = sum(results['operations_per_thread']) | |
| results['total_errors'] = sum(results['errors_per_thread']) | |
| return results | |
| def mixed_concurrent_test(self, memory_system, num_threads: int = 10, duration: int = 30) -> Dict[str, Any]: | |
| print(f"๐ Testing mixed concurrent operations with {num_threads} threads") | |
| results = { | |
| 'total_reads': 0, | |
| 'total_writes': 0, | |
| 'total_errors': 0, | |
| 'read_latencies': [], | |
| 'write_latencies': [] | |
| } | |
| def mixed_worker(thread_id: int): | |
| reads = 0 | |
| writes = 0 | |
| errors = 0 | |
| read_latencies = [] | |
| write_latencies = [] | |
| start_time = time.time() | |
| while time.time() - start_time < duration: | |
| try: | |
| if random.random() < 0.7: | |
| op_start = time.time() | |
| key = f"mixed_test_{random.randint(0, 1000)}" | |
| result = memory_system.retrieve(key) | |
| latency = time.time() - op_start | |
| read_latencies.append(latency) | |
| reads += 1 | |
| if result is None: | |
| errors += 1 | |
| else: | |
| op_start = time.time() | |
| key = f"mixed_test_{thread_id}_{writes}" | |
| value = f"value_{thread_id}_{writes}_{random.randint(0, 10000)}" | |
| success = memory_system.store(key, value) | |
| latency = time.time() - op_start | |
| write_latencies.append(latency) | |
| writes += 1 | |
| if not success: | |
| errors += 1 | |
| except Exception as e: | |
| errors += 1 | |
| logging.error(f"Mixed concurrent error in thread {thread_id}: {e}") | |
| return { | |
| 'reads': reads, | |
| 'writes': writes, | |
| 'errors': errors, | |
| 'read_latencies': read_latencies, | |
| 'write_latencies': write_latencies | |
| } | |
| with ThreadPoolExecutor(max_workers=num_threads) as executor: | |
| futures = [executor.submit(mixed_worker, i) for i in range(num_threads)] | |
| for future in futures: | |
| thread_result = future.result() | |
| results['total_reads'] += thread_result['reads'] | |
| results['total_writes'] += thread_result['writes'] | |
| results['total_errors'] += thread_result['errors'] | |
| results['read_latencies'].extend(thread_result['read_latencies']) | |
| results['write_latencies'].extend(thread_result['write_latencies']) | |
| return results | |
| class MemoryPressureTester: | |
| def __init__(self, config: StressTestConfig = None): | |
| self.config = config or StressTestConfig() | |
| def create_memory_pressure(self, pressure_level: float) -> List[bytes]: | |
| print(f"๐พ Creating memory pressure at {pressure_level:.1%} level") | |
| total_memory = psutil.virtual_memory().total | |
| target_memory = total_memory * pressure_level | |
| allocated_blocks = [] | |
| current_memory = psutil.virtual_memory().used | |
| while current_memory < target_memory: | |
| try: | |
| block = bytearray(self.config.memory_allocation_size) | |
| allocated_blocks.append(block) | |
| current_memory = psutil.virtual_memory().used | |
| if len(allocated_blocks) > 1000: | |
| break | |
| except MemoryError: | |
| print(f"โ ๏ธ Memory allocation failed at {len(allocated_blocks)} blocks") | |
| break | |
| print(f"๐พ Allocated {len(allocated_blocks)} memory blocks") | |
| return allocated_blocks | |
| def test_under_memory_pressure(self, memory_system, pressure_level: float, | |
| test_duration: int = 30) -> Dict[str, Any]: | |
| print(f"๐พ Testing under {pressure_level:.1%} memory pressure") | |
| allocated_blocks = self.create_memory_pressure(pressure_level) | |
| try: | |
| start_time = time.time() | |
| operations = 0 | |
| errors = 0 | |
| latencies = [] | |
| while time.time() - start_time < test_duration: | |
| try: | |
| op_start = time.time() | |
| key = f"pressure_test_{operations}" | |
| value = f"value_{operations}_{random.randint(0, 10000)}" | |
| if memory_system.store(key, value): | |
| result = memory_system.retrieve(key) | |
| if result is None: | |
| errors += 1 | |
| else: | |
| errors += 1 | |
| latency = time.time() - op_start | |
| latencies.append(latency) | |
| operations += 1 | |
| except Exception as e: | |
| errors += 1 | |
| logging.error(f"Memory pressure test error: {e}") | |
| total_time = time.time() - start_time | |
| throughput = operations / total_time | |
| error_rate = errors / operations if operations > 0 else 0 | |
| avg_latency = np.mean(latencies) if latencies else 0 | |
| return { | |
| 'pressure_level': pressure_level, | |
| 'throughput': throughput, | |
| 'latency': avg_latency, | |
| 'error_rate': error_rate, | |
| 'operations': operations, | |
| 'errors': errors, | |
| 'memory_usage': psutil.virtual_memory().percent | |
| } | |
| finally: | |
| print(f"๐พ Cleaning up {len(allocated_blocks)} memory blocks") | |
| del allocated_blocks | |
| gc.collect() | |
| class StatisticalComparator: | |
| def __init__(self, config: StressTestConfig = None): | |
| self.config = config or StressTestConfig() | |
| def compare_systems(self, results: List[StressTestResult]) -> Dict[str, Any]: | |
| print("๐ Performing statistical comparison of memory systems") | |
| comparison_results = { | |
| 'systems': [result.test_name for result in results], | |
| 'throughput_comparison': {}, | |
| 'latency_comparison': {}, | |
| 'stability_comparison': {}, | |
| 'significance_tests': {} | |
| } | |
| throughputs = [result.throughput_history for result in results] | |
| latencies = [result.latency_history for result in results] | |
| stability_scores = [result.stability_score for result in results] | |
| if len(throughputs) >= 2: | |
| comparison_results['throughput_comparison'] = self._compare_metrics( | |
| throughputs, [result.test_name for result in results], 'throughput' | |
| ) | |
| if len(latencies) >= 2: | |
| comparison_results['latency_comparison'] = self._compare_metrics( | |
| latencies, [result.test_name for result in results], 'latency' | |
| ) | |
| if len(stability_scores) >= 2: | |
| comparison_results['stability_comparison'] = self._compare_stability( | |
| stability_scores, [result.test_name for result in results] | |
| ) | |
| comparison_results['significance_tests'] = self._perform_significance_tests(results) | |
| return comparison_results | |
| def _compare_metrics(self, metrics_lists: List[List[float]], | |
| system_names: List[str], metric_name: str) -> Dict[str, Any]: | |
| comparison = { | |
| 'metric': metric_name, | |
| 'means': {}, | |
| 'stds': {}, | |
| 'medians': {}, | |
| 'best_system': None, | |
| 'worst_system': None | |
| } | |
| means = [] | |
| stds = [] | |
| medians = [] | |
| for i, metrics in enumerate(metrics_lists): | |
| if metrics: | |
| mean_val = np.mean(metrics) | |
| std_val = np.std(metrics) | |
| median_val = np.median(metrics) | |
| comparison['means'][system_names[i]] = mean_val | |
| comparison['stds'][system_names[i]] = std_val | |
| comparison['medians'][system_names[i]] = median_val | |
| means.append(mean_val) | |
| stds.append(std_val) | |
| medians.append(median_val) | |
| else: | |
| means.append(0) | |
| stds.append(0) | |
| medians.append(0) | |
| if means: | |
| best_idx = np.argmax(means) if metric_name == 'throughput' else np.argmin(means) | |
| worst_idx = np.argmin(means) if metric_name == 'throughput' else np.argmax(means) | |
| comparison['best_system'] = system_names[best_idx] | |
| comparison['worst_system'] = system_names[worst_idx] | |
| return comparison | |
| def _compare_stability(self, stability_scores: List[float], | |
| system_names: List[str]) -> Dict[str, Any]: | |
| comparison = { | |
| 'metric': 'stability', | |
| 'scores': dict(zip(system_names, stability_scores)), | |
| 'most_stable': None, | |
| 'least_stable': None | |
| } | |
| if stability_scores: | |
| best_idx = np.argmax(stability_scores) | |
| worst_idx = np.argmin(stability_scores) | |
| comparison['most_stable'] = system_names[best_idx] | |
| comparison['least_stable'] = system_names[worst_idx] | |
| return comparison | |
| def _perform_significance_tests(self, results: List[StressTestResult]) -> Dict[str, Any]: | |
| significance_tests = {} | |
| if len(results) < 2: | |
| return significance_tests | |
| throughputs = [] | |
| for result in results: | |
| if result.throughput_history: | |
| throughputs.append(result.throughput_history) | |
| if len(throughputs) >= 2: | |
| pairwise_tests = {} | |
| for i in range(len(throughputs)): | |
| for j in range(i + 1, len(throughputs)): | |
| system1 = results[i].test_name | |
| system2 = results[j].test_name | |
| try: | |
| t_stat, p_value = ttest_ind(throughputs[i], throughputs[j]) | |
| pairwise_tests[f"{system1}_vs_{system2}"] = { | |
| 't_statistic': t_stat, | |
| 'p_value': p_value, | |
| 'significant': p_value < (1 - self.config.confidence_level) | |
| } | |
| except Exception as e: | |
| logging.error(f"T-test error: {e}") | |
| significance_tests['throughput_t_tests'] = pairwise_tests | |
| if len(throughputs) >= 3: | |
| try: | |
| h_stat, p_value = kruskal(*throughputs) | |
| significance_tests['kruskal_wallis'] = { | |
| 'h_statistic': h_stat, | |
| 'p_value': p_value, | |
| 'significant': p_value < (1 - self.config.confidence_level) | |
| } | |
| except Exception as e: | |
| logging.error(f"Kruskal-Wallis test error: {e}") | |
| return significance_tests | |
| class ComprehensiveStressTester: | |
| def __init__(self, config: StressTestConfig = None): | |
| self.config = config or StressTestConfig() | |
| self.load_tester = LoadTester(config) | |
| self.concurrent_tester = ConcurrentTester(config) | |
| self.memory_pressure_tester = MemoryPressureTester(config) | |
| self.statistical_comparator = StatisticalComparator(config) | |
| def run_comprehensive_stress_test(self, memory_systems: Dict[str, Any]) -> Dict[str, Any]: | |
| print("๐ฅ COMPREHENSIVE STRESS TESTING FRAMEWORK") | |
| print("=" * 60) | |
| all_results = { | |
| 'stress_test_results': [], | |
| 'concurrent_test_results': {}, | |
| 'memory_pressure_results': {}, | |
| 'comparison_results': {}, | |
| 'summary': {} | |
| } | |
| print("\n๐ฅ PHASE 1: LOAD TESTING") | |
| print("-" * 30) | |
| stress_results = [] | |
| for system_name, memory_system in memory_systems.items(): | |
| result = self.load_tester.stress_test_system(memory_system, system_name) | |
| stress_results.append(result) | |
| all_results['stress_test_results'] = stress_results | |
| print("\n๐ PHASE 2: CONCURRENT TESTING") | |
| print("-" * 30) | |
| concurrent_results = {} | |
| for system_name, memory_system in memory_systems.items(): | |
| print(f"\n๐ Testing {system_name} for concurrent access...") | |
| read_results = self.concurrent_tester.concurrent_read_test(memory_system) | |
| write_results = self.concurrent_tester.concurrent_write_test(memory_system) | |
| mixed_results = self.concurrent_tester.mixed_concurrent_test(memory_system) | |
| concurrent_results[system_name] = { | |
| 'concurrent_reads': read_results, | |
| 'concurrent_writes': write_results, | |
| 'mixed_concurrent': mixed_results | |
| } | |
| all_results['concurrent_test_results'] = concurrent_results | |
| print("\n๐พ PHASE 3: MEMORY PRESSURE TESTING") | |
| print("-" * 30) | |
| memory_pressure_results = {} | |
| for system_name, memory_system in memory_systems.items(): | |
| print(f"\n๐พ Testing {system_name} under memory pressure...") | |
| pressure_results = {} | |
| for pressure_level in self.config.memory_pressure_levels: | |
| result = self.memory_pressure_tester.test_under_memory_pressure( | |
| memory_system, pressure_level | |
| ) | |
| pressure_results[f"pressure_{pressure_level:.1f}"] = result | |
| memory_pressure_results[system_name] = pressure_results | |
| all_results['memory_pressure_results'] = memory_pressure_results | |
| print("\n๐ PHASE 4: STATISTICAL COMPARISON") | |
| print("-" * 30) | |
| comparison_results = self.statistical_comparator.compare_systems(stress_results) | |
| all_results['comparison_results'] = comparison_results | |
| print("\n๐ PHASE 5: GENERATING SUMMARY") | |
| print("-" * 30) | |
| summary = self._generate_summary(all_results) | |
| all_results['summary'] = summary | |
| self._save_results(all_results) | |
| print("\nโ COMPREHENSIVE STRESS TESTING COMPLETED!") | |
| return all_results | |
| def _generate_summary(self, results: Dict[str, Any]) -> Dict[str, Any]: | |
| summary = { | |
| 'test_timestamp': datetime.now().isoformat(), | |
| 'systems_tested': len(results['stress_test_results']), | |
| 'best_performing_system': None, | |
| 'most_stable_system': None, | |
| 'most_resilient_system': None, | |
| 'key_findings': [], | |
| 'recommendations': [] | |
| } | |
| stress_results = results['stress_test_results'] | |
| if stress_results: | |
| best_throughput = 0 | |
| best_system = None | |
| for result in stress_results: | |
| if result.throughput_history: | |
| max_throughput = max(result.throughput_history) | |
| if max_throughput > best_throughput: | |
| best_throughput = max_throughput | |
| best_system = result.test_name | |
| summary['best_performing_system'] = best_system | |
| most_stable_score = 0 | |
| most_stable_system = None | |
| for result in stress_results: | |
| if result.stability_score > most_stable_score: | |
| most_stable_score = result.stability_score | |
| most_stable_system = result.test_name | |
| summary['most_stable_system'] = most_stable_system | |
| highest_failure_load = 0 | |
| most_resilient_system = None | |
| for result in stress_results: | |
| if result.failure_load and result.failure_load > highest_failure_load: | |
| highest_failure_load = result.failure_load | |
| most_resilient_system = result.test_name | |
| summary['most_resilient_system'] = most_resilient_system | |
| if results['comparison_results']: | |
| comparison = results['comparison_results'] | |
| if 'throughput_comparison' in comparison: | |
| throughput_comp = comparison['throughput_comparison'] | |
| if throughput_comp.get('best_system'): | |
| summary['key_findings'].append( | |
| f"Best throughput: {throughput_comp['best_system']} " | |
| f"({throughput_comp['means'][throughput_comp['best_system']]:.2f} ops/sec)" | |
| ) | |
| if 'stability_comparison' in comparison: | |
| stability_comp = comparison['stability_comparison'] | |
| if stability_comp.get('most_stable'): | |
| summary['key_findings'].append( | |
| f"Most stable: {stability_comp['most_stable']} " | |
| f"(stability score: {stability_comp['scores'][stability_comp['most_stable']]:.3f})" | |
| ) | |
| if summary['best_performing_system']: | |
| summary['recommendations'].append( | |
| f"Use {summary['best_performing_system']} for high-throughput applications" | |
| ) | |
| if summary['most_stable_system']: | |
| summary['recommendations'].append( | |
| f"Use {summary['most_stable_system']} for consistent performance requirements" | |
| ) | |
| if summary['most_resilient_system']: | |
| summary['recommendations'].append( | |
| f"Use {summary['most_resilient_system']} for high-load scenarios" | |
| ) | |
| return summary | |
| def _save_results(self, results: Dict[str, Any]): | |
| timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") | |
| json_filename = f"stress_test_results_{timestamp}.json" | |
| json_results = self._convert_to_json_serializable(results) | |
| with open(json_filename, 'w') as f: | |
| json.dump(json_results, f, indent=2) | |
| print(f"๐พ Detailed results saved to: {json_filename}") | |
| summary_filename = f"stress_test_summary_{timestamp}.txt" | |
| with open(summary_filename, 'w') as f: | |
| f.write("๐ฅ COMPREHENSIVE STRESS TEST SUMMARY\n") | |
| f.write("=" * 50 + "\n\n") | |
| summary = results['summary'] | |
| f.write(f"Test Date: {summary['test_timestamp']}\n") | |
| f.write(f"Systems Tested: {summary['systems_tested']}\n\n") | |
| f.write("๐ PERFORMANCE RANKINGS:\n") | |
| f.write("-" * 25 + "\n") | |
| f.write(f"Best Performing: {summary['best_performing_system']}\n") | |
| f.write(f"Most Stable: {summary['most_stable_system']}\n") | |
| f.write(f"Most Resilient: {summary['most_resilient_system']}\n\n") | |
| f.write("๐ KEY FINDINGS:\n") | |
| f.write("-" * 15 + "\n") | |
| for finding in summary['key_findings']: | |
| f.write(f"โข {finding}\n") | |
| f.write("\n") | |
| f.write("๐ก RECOMMENDATIONS:\n") | |
| f.write("-" * 18 + "\n") | |
| for recommendation in summary['recommendations']: | |
| f.write(f"โข {recommendation}\n") | |
| print(f"๐ Summary saved to: {summary_filename}") | |
| def _convert_to_json_serializable(self, obj): | |
| if isinstance(obj, dict): | |
| return {key: self._convert_to_json_serializable(value) for key, value in obj.items()} | |
| elif isinstance(obj, list): | |
| return [self._convert_to_json_serializable(item) for item in obj] | |
| elif isinstance(obj, np.ndarray): | |
| return obj.tolist() | |
| elif isinstance(obj, (np.integer, np.floating)): | |
| return obj.item() | |
| elif isinstance(obj, datetime): | |
| return obj.isoformat() | |
| elif hasattr(obj, '__dict__'): | |
| return self._convert_to_json_serializable(obj.__dict__) | |
| else: | |
| return obj | |
| def run_comprehensive_stress_test_demo(): | |
| print("๐ฅ COMPREHENSIVE STRESS TESTING DEMO") | |
| print("=" * 50) | |
| try: | |
| from memory_systems import ( | |
| SequentialMemory, AssociativeMemory, ContentAddressableMemory, | |
| AdaptiveLRUCache, NeuralAssociativeMemory, CompressedMemorySystem, | |
| HierarchicalMemorySystem | |
| ) | |
| except ImportError: | |
| print("โ Could not import memory systems. Please ensure memory_systems.py is available.") | |
| return | |
| memory_systems = { | |
| 'Sequential': SequentialMemory(), | |
| 'Associative': AssociativeMemory(), | |
| 'Content-Addressable': ContentAddressableMemory(), | |
| 'LRU Cache': AdaptiveLRUCache(), | |
| 'Neural': NeuralAssociativeMemory(), | |
| 'Compressed': CompressedMemorySystem(), | |
| 'Hierarchical': HierarchicalMemorySystem() | |
| } | |
| config = StressTestConfig( | |
| max_load_multiplier=5.0, | |
| load_increment=0.5, | |
| test_duration=30, | |
| max_threads=5 | |
| ) | |
| stress_tester = ComprehensiveStressTester(config) | |
| results = stress_tester.run_comprehensive_stress_test(memory_systems) | |
| print("\n๐ STRESS TESTING DEMO COMPLETED!") | |
| print("Check the generated files for detailed results and analysis.") | |
| if __name__ == "__main__": | |
| run_comprehensive_stress_test_demo() | |
Xet Storage Details
- Size:
- 34.4 kB
- Xet hash:
- d424f757d17f6078d113c4132b35f9a292f8f9dd344414a03e8ec1ba773d2968
ยท
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.