{ "cells": [ { "cell_type": "markdown", "id": "8b22a2d1", "metadata": {}, "source": [ "# Introduction\n", "\n", "Bonjour et bienvenue dans le notebook du projet sur les bases de données tablebase.\n", "\n", "Dans ce notebook. Nous allons montrer comme fonctionne le stockage d'une base de données tablebases en prenant comme exemple la table base \"syzygy\" avec comme taille 3 à 5 pièces pour des raisons de taille.\n", "Nous allons expliquer comment les finales ( ou position d'échecs) sont stockés dans le format key-value puis nous verrons ensuite les performances de la base à l'aide de Redis.\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "78fdf40a", "metadata": { "ExecuteTime": { "end_time": "2025-12-06T09:21:56.560113Z", "start_time": "2025-12-06T09:21:56.104871Z" } }, "outputs": [], "source": [ "#import du projet\n", "import redis\n", "import time\n", "import chess\n", "import chess.syzygy\n", "import random\n", "import numpy as np\n", "import pandas as pd\n", "import os\n", "import hashlib\n", "from IPython.display import display\n", "from scipy import stats\n", "\n" ] }, { "cell_type": "markdown", "id": "d584aba1", "metadata": {}, "source": [ "## Peuplement de Redis\n", "\n", "Dans un premier temps, on ajoute les positions de la tablebase à Redis afin de pouvoir les utilisers derrières pour faire les tests." ] }, { "cell_type": "code", "execution_count": 2, "id": "e6058974", "metadata": { "ExecuteTime": { "end_time": "2025-12-06T09:22:49.905572Z", "start_time": "2025-12-06T09:22:06.592819Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Configs ok: {'KRBvKP', 'KRvKB', 'KRvK', 'KBNvK', 'KBvK', 'KRPvKP', 'KPvK', 'KNvK', 'KQvK', 'KQvKP', 'KPvKP'}\n" ] }, { "data": { "image/svg+xml": [ "
. . . . k . . .\n",
       ". . . . . . . .\n",
       ". . . n . . . .\n",
       ". . . . . . . .\n",
       ". . . . . . . p\n",
       ". P . . . . . .\n",
       ". . . . B . . .\n",
       ". . . . K . . .
" ], "text/plain": [ "Board('4k3/8/3n4/8/7p/1P6/4B3/4K3 b - - 0 1')" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Récupération des positions de la tablebase KBNvK\n", "Récupération des positions de la tablebase KPvK\n", "Récupération des positions de la tablebase KPvKP\n", "Récupération des positions de la tablebase KQvK\n", "Récupération des positions de la tablebase KQvKP\n", "Récupération des positions de la tablebase KRBvKP\n", "Récupération des positions de la tablebase KRPvKP\n", "Récupération des positions de la tablebase KRvK\n", "Récupération des positions de la tablebase KRvKB\n", "Récupération des positions de la tablebase KBvK\n", "Récupération des positions de la tablebase KNvK\n", "Total positions récupérées: 55000\n", "Ajoute de toutes les positions des tablebases dans Redis terminé!\n" ] } ], "source": [ "def get_250_random_position(tablebases, config):\n", " positions = []\n", " tries = 0\n", "\n", " while len(positions) < 10000 and tries < 5000:\n", " board = generate_board_from_config(config)\n", " positions.append(board)\n", " tries += 1\n", "\n", " return positions\n", "\n", "def generate_board_from_config(config):\n", " \"\"\"\n", " Génère un board contenant exactement le matériel d'une config Syzygy. Exemples de config :\n", " - 'KQvK', 'KPvKP'\n", " Cette fonction est important car il faut générer les positions qui dont les informations sont dans la tablebases.\n", " \"\"\"\n", "\n", " piece_map = {\"K\": chess.KING,\"Q\": chess.QUEEN,\"R\": chess.ROOK,\"B\": chess.BISHOP,\"N\": chess.KNIGHT,\"P\": chess.PAWN}\n", "\n", " white_str, black_str = config.split(\"v\") #Sépare la config entre les 2 couleurs\n", "\n", " board = chess.Board(None) # donne un plateau vide\n", "\n", " # boucles pour placer les pièces sur le plateau\n", " for p in white_str:\n", " piece = piece_map[p]\n", " sq = random.choice([s for s in chess.SQUARES if board.piece_at(s) is None]) #choisi une pièce et vérifie que il n'y a pas déjà une pièce dessus\n", " board.set_piece_at(sq, chess.Piece(piece, chess.WHITE))\n", "\n", " for p in black_str:\n", " piece = piece_map[p]\n", " sq = random.choice([s for s in chess.SQUARES if board.piece_at(s) is None])#choisi une pièce et vérifie que il n'y a pas déjà une pièce dessus\n", " board.set_piece_at(sq, chess.Piece(piece, chess.BLACK))\n", "\n", " # désactive les règles des échecs.\n", " board.castling_rights = 0\n", " board.ep_square = None\n", "\n", " # Donne une couleur aléatoire pour savoir quelle couleur doit jouer le prochain coup.\n", " board.turn = random.choice([chess.WHITE, chess.BLACK])\n", "\n", " if not board.is_valid():\n", " return generate_board_from_config(config)\n", "\n", " return board\n", "\n", "def add_tablebase_to_redis():\n", " #Connect to Redis server\n", " redis_server = redis.Redis(host='localhost', port=6379, db=0)\n", " \n", " tablebases_path = \"tablebases/\" #Chemin vers les tables bases Syzygy\n", "\n", " tablebases = chess.syzygy.open_tablebase(tablebases_path)\n", "\n", " available_tables = set()\n", " for f in os.listdir(tablebases_path):\n", " if f.endswith(\".rtbw\") or f.endswith(\".rtbz\"):\n", " available_tables.add(f.split(\".\")[0])\n", "\n", " print(\"Configs ok:\", available_tables)\n", "\n", " position = chess.Board(\"4k3/8/3n4/8/7p/1P6/4B3/4K3 b - - 0 1\") #Position d'exemple\n", " display(position) \n", " \n", " configs = [\"KBNvK\",\"KPvK\",\"KPvKP\",\"KQvK\",\"KQvKP\",\"KRBvKP\",\"KRPvKP\",\"KRvK\",\"KRvKB\",\"KBvK\",\"KNvK\"]\n", " config_valide = [c for c in configs if c in available_tables]\n", " #Configurations de toute les tablebases que l'on utilisera dans le projet.\n", " all_positions = []\n", " for config in config_valide:\n", " print(f\"Récupération des positions de la tablebase {config}\")\n", " position = get_250_random_position(tablebases,config)\n", " all_positions.extend(position) #Ajout des positions générées à la liste globale\n", " \n", " print(f\"Total positions récupérées: {len(all_positions)}\")\n", " print(\"Ajoute de toutes les positions des tablebases dans Redis terminé!\")\n", "\n", "if __name__ == \"__main__\":\n", " add_tablebase_to_redis() " ] }, { "cell_type": "markdown", "id": "1b443c8c", "metadata": {}, "source": [ "## Accès à Redis\n", "\n", "Nous avons rajouter 250 positions apparentant à chacune des tablesbases présent dans le dossier. Il y a des configurations ayant 3,4 ainsi que 5 pièces pour voir si cela a une incidence sur le temps d'accès à Redis.\n", "\n", "Pour la suite, nous allons donc pouvoir passer sur Redis pour vérifier cette hypothèse et faire d'autres tests sur notre base.\n", "\n", "## Benchmark redis" ] }, { "cell_type": "code", "execution_count": 3, "id": "8d49b928-7522-4727-b6d8-224e2bd3a1b7", "metadata": { "ExecuteTime": { "end_time": "2025-12-06T09:27:00.752325Z", "start_time": "2025-12-06T09:27:00.748915Z" } }, "outputs": [], "source": [ "def benchmark_redis(redis_serveur, pos):\n", " latency = []\n", " start_time_all = time.time()\n", "\n", " for board in pos:\n", " fen = board.fen()\n", " start_individual = time.time()\n", " redis_serveur.hset(fen, mapping={\"board\": board.fen()})\n", " latency.append(time.time() - start_individual)\n", "\n", " total_time_all=time.time()-start_time_all\n", " latency= np.array(latency)\n", "\n", " return{\n", " \"count\": len(pos),\n", " \"average_latency\": np.mean(latency),\n", " \"p50\": np.percentile(latency,50),\n", " \"p90\": np.percentile(latency,90),\n", " \"p95\": np.percentile(latency,95),\n", " \"p99\": np.percentile(latency,99),\n", " \"std\": np.std(latency),\n", " \"min\": np.min(latency),\n", " \"max\": np.max(latency),\n", " \"total_time\": total_time_all,\n", " \"latency\": latency,\n", " \"rps\": len(latency)/total_time_all,\n", " }\n", "\n", "def benchmark_syzygy(tablebases, pos):\n", " latency = []\n", " start_time_all = time.time()\n", "\n", " for board in pos:\n", " try:\n", " start = time.time()\n", " tablebases.probe_wdl(board)\n", " tablebases.probe_dtz(board)\n", " latency.append(time.time() - start)\n", " except chess.syzygy.MissingTableError:\n", " continue\n", "\n", " total_time_all=time.time()-start_time_all\n", "\n", " return{\n", " \"count\": len(pos),\n", " \"average_latency\": np.mean(latency),\n", " \"p50\": np.percentile(latency,50),\n", " \"p90\": np.percentile(latency,90),\n", " \"p95\": np.percentile(latency,95),\n", " \"p99\": np.percentile(latency,99),\n", " \"std\": np.std(latency),\n", " \"min\": np.min(latency),\n", " \"max\": np.max(latency),\n", " \"total_time\": total_time_all,\n", " \"latency\": latency,\n", " \"rps\": len(latency)/total_time_all\n", " }\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "0d955b0d-dc80-4518-954b-7c2df295adca", "metadata": { "ExecuteTime": { "end_time": "2025-12-06T10:18:18.501308Z", "start_time": "2025-12-06T10:18:18.393765Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "BENCHMARK SYZYGY\n", "BENCHMARK REDIS\n", "Redis latency array length: 55000\n", "Syzygy latency array length: 50127\n", " test statistic p-value \\\n", "0 paired t-test 85.042506 0.0 \n", "1 KS-test 0.546193 0.0 \n", "\n", " interpretation \n", "0 H0: mean latency equal (Redis vs Syzygy) \n", "1 H0: same latency distribution (Redis vs Syzygy) \n" ] } ], "source": [ "def statistical_tests(bench_redis, bench_syzygy):\n", " redis_lat = np.array(bench_redis[\"latency\"], dtype=np.float64)\n", " syz_lat = np.array(bench_syzygy[\"latency\"], dtype=np.float64)\n", " \n", " min_len = min(len(redis_lat), len(syz_lat))\n", " redis_lat = redis_lat[:min_len]\n", " syz_lat = syz_lat[:min_len]\n", "\n", " # PAIRED T-Test (Comparaison median)\n", " t_stat, t_p = stats.ttest_rel(syz_lat, redis_lat)\n", "\n", " # KS Test (Comparaison distribution)\n", " ks_stat, ks_p = stats.ks_2samp(syz_lat, redis_lat)\n", "\n", " df_stats = pd.DataFrame({\n", " \"test\": [\"paired t-test\", \"KS-test\"],\n", " \"statistic\": [t_stat, ks_stat],\n", " \"p-value\": [t_p, ks_p],\n", " \"interpretation\": [\n", " \"H0: mean latency equal (Redis vs Syzygy)\",\n", " \"H0: same latency distribution (Redis vs Syzygy)\"\n", " ]\n", " })\n", "\n", " print(df_stats)\n", " return df_stats\n", "\n", "\n", "def run_experiment_test_latency():\n", " redis_server = redis.Redis(host=\"localhost\", port=6379, db=0)\n", " tablebases = chess.syzygy.open_tablebase(\"tablebases/\")\n", "\n", " configs = [\"KBNvK\",\"KPvK\",\"KPvKP\",\"KQvK\",\"KQvKP\",\"KRBvKP\",\"KRPvKP\",\"KRvK\",\"KRvKB\",\"KBvK\",\"KNvK\"]\n", "\n", " all_positions = []\n", " for config in configs:\n", " all_positions += get_250_random_position(tablebases, config)\n", "\n", " # Benchmark Syzygy\n", " bench_syzygy = benchmark_syzygy(tablebases, all_positions)\n", " print(\"BENCHMARK SYZYGY\")\n", " #print(bench_syzygy)\n", "\n", " # Benchmark Redis\n", " bench_redis = benchmark_redis(redis_server, all_positions)\n", " print(\"BENCHMARK REDIS\")\n", " #print(bench_redis)\n", "\n", " # Length info\n", " print(f\"Redis latency array length: {len(bench_redis['latency'])}\")\n", " print(f\"Syzygy latency array length: {len(bench_syzygy['latency'])}\")\n", "\n", " return {\n", " \"bench_syzygy\": bench_syzygy,\n", " \"bench_redis\": bench_redis\n", " }\n", "\n", "if __name__ == \"__main__\":\n", " results = run_experiment_test_latency()\n", " statistical_tests(results[\"bench_redis\"], results[\"bench_syzygy\"])" ] }, { "cell_type": "markdown", "id": "37b01080", "metadata": {}, "source": [ "Cette partie teste les accès Redis, afin de savoir si le nombre de pièces de la configuration importe sur le temps d'accès : " ] }, { "cell_type": "code", "execution_count": 5, "id": "a68060e1-0052-4446-a0d3-40bc1756f210", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "=== Benchmark Redis GET : 3pieces ===\n", "\n", "=== Benchmark Redis GET : 4pieces ===\n", "\n", "=== Benchmark Redis GET : 5pieces ===\n" ] }, { "data": { "text/plain": [ "{'3pieces': {'mean_ms': np.float64(0.4589625600419822),\n", " 'median_ms': np.float64(0.40479199969922774),\n", " 'min_ms': np.float64(0.20995799968659412),\n", " 'max_ms': np.float64(4.594801999701303),\n", " 'std_ms': np.float64(0.42983928490153817)},\n", " '4pieces': {'mean_ms': np.float64(0.36221424002178537),\n", " 'median_ms': np.float64(0.33665850014585885),\n", " 'min_ms': np.float64(0.2021390000663814),\n", " 'max_ms': np.float64(1.0131979997822782),\n", " 'std_ms': np.float64(0.12193858759433863)},\n", " '5pieces': {'mean_ms': np.float64(0.3863061399442813),\n", " 'median_ms': np.float64(0.3765404999285238),\n", " 'min_ms': np.float64(0.20748299994011177),\n", " 'max_ms': np.float64(0.6716950001646182),\n", " 'std_ms': np.float64(0.09189286718199571)}}" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "\"\"\"\n", "redis_client : instance redis.Redis déjà créée\n", "test_positions : dict {\"3men\": [...], \"4men\": [...], \"5men\": [...]}\n", "\"\"\"\n", "def benchmark_redis_get_comparison(redis_client, test_positions: dict, iterations=100):\n", "\n", " results = {}\n", "\n", " for label, fens in test_positions.items():\n", " print(f\"\\n=== Benchmark Redis GET : {label} ===\")\n", "\n", " times = np.zeros(iterations)\n", "\n", " for i in range(iterations):\n", " fen = random.choice(fens)\n", " key = f\"tb:{fen}\"\n", "\n", " start = time.perf_counter()\n", " _ = redis_client.get(key)\n", " times[i] = time.perf_counter() - start\n", "\n", " results[label] = {\n", " \"mean_ms\": np.mean(times) * 1000,\n", " \"median_ms\": np.median(times) * 1000,\n", " \"min_ms\": np.min(times) * 1000,\n", " \"max_ms\": np.max(times) * 1000,\n", " \"std_ms\": np.std(times) * 1000,\n", " }\n", " return results\n", "\n", "\n", "#IMPORTANT : Es-ce qu'on garde ca comme ca ? \n", "TEST_POSITIONS = {\n", " \"3pieces\": [\n", " \"K7/8/8/8/8/8/8/k7 w - - 0 1\",\n", " \"KB6/8/8/8/8/8/8/k7 w - - 0 1\",\n", " \"KN6/8/8/8/8/8/8/k7 w - - 0 1\",\n", " ],\n", " \"4pieces\": [\n", " \"KQ6/8/8/8/8/8/8/k7 w - - 0 1\",\n", " \"KP6/8/8/8/8/8/8/k7 w - - 0 1\",\n", " \"KQ6/kr6/8/8/8/8/8/8 w - - 0 1\",\n", " ],\n", " \"5pieces\": [\n", " \"KQ6/8/8/Kp6/8/8/8/k7 w - - 0 1\",\n", " \"KR6/1p6/8/8/8/8/8/k7 w - - 0 1\",\n", " \"KRP5/1p6/8/8/8/8/8/k7 w - - 0 1\",\n", " ],\n", "}\n", "\n", "redis_server = redis.Redis(host=\"localhost\", port=6379, db=0)\n", "benchmark_redis_get_comparison(redis_server, TEST_POSITIONS, 100)" ] }, { "cell_type": "code", "execution_count": null, "id": "a68060e1-0052-4446-a0d3-40bc1756f210", "metadata": {}, "outputs": [], "source": [ "#Test Mémoire Redis ( Stockage du Redis )\n", "redis_server = redis.Redis(host=\"localhost\", port=6379, db=0)\n", "info= redis_server.info(\"memory\")\n", "mem_human = info[\"used_memory_human\"]\n", "print(\"MEMORY USAGE REDIS\")\n", "print(f\"Memory Redis: {mem_human}\")\n", "\n", "\"\"\"\n", "#Test Mémoire Syzygy\n", "import psutil\n", "\n", "tablebases = chess.syzygy.open_tablebase(\"tablebases/\")\n", "\n", "#Récuperer les données de proccesus de Syzygy\n", "process = psutil.Process(os.getpid())\n", "mem_bytes = process.memory_info().rss\n", "mem_mb = mem_bytes / (1024**2)\n", "print(\"MEMORY USAGE SYZYGY\")\n", "print(f\"Memory Syzygy: {mem_mb}\")\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "id": "46157e5c", "metadata": {}, "outputs": [], "source": [ "def get_250_random_position(tablebases, config):\n", " positions = []\n", " tries = 0\n", "\n", " while len(positions) < 250 and tries < 5000:\n", " board = generate_board_from_config(config)\n", " try:\n", " tablebases.probe_wdl(board) # thử probe WDL\n", " positions.append(board)\n", " except chess.syzygy.MissingTableError:\n", " pass # bỏ qua nếu table không tồn tại\n", " tries += 1\n", " return positions\n", "\n", "def add_tablebase_to_redis():\n", " h = hashlib.new('sha512_256')\n", " #Connect to Redis server\n", " redis_server = redis.Redis(host='localhost', port=6379, db=1) #db1 pour H4\n", " \n", " tablebases_path = \"tablebases/\" #Chemin vers les tables bases Syzygy\n", "\n", " tablebases = chess.syzygy.open_tablebase(tablebases_path)\n", "\n", " available_tables = set()\n", " for f in os.listdir(tablebases_path):\n", " if f.endswith(\".rtbw\") or f.endswith(\".rtbz\"):\n", " available_tables.add(f.split(\".\")[0])\n", "\n", " print(\"Configs ok:\", available_tables)\n", " \n", " configs = [\"KBNvK\",\"KPvK\",\"KPvKP\",\"KQvK\",\"KQvKP\",\"KRBvKP\",\"KRPvKP\",\"KRvK\",\"KRvKB\"]\n", " config_valide = [c for c in configs if c in available_tables]\n", " #Configurations de toute les tablebases que l'on utilisera dans le projet.\n", " all_positions = []\n", " for config in config_valide:\n", " print(f\"Récupération des positions de la tablebase {config}\")\n", " position = get_250_random_position(tablebases,config)\n", " all_positions.extend(position) #Ajout des positions générées à la liste globale\n", " \n", " print(f\"Total positions récupérées: {len(all_positions)}\")\n", " for position in all_positions:\n", " try:\n", " fen = position.fen()\n", " key = hashlib.md5(fen.encode()).hexdigest()[:16] #Limite à 16 caractères\n", " wdl = tablebases.probe_wdl(position)\n", " dtz = tablebases.probe_dtz(position)\n", " redis_server.hset(key, mapping={\"wdl\": wdl, \"dtz\": dtz}) \n", " except (KeyError,chess.syzygy.MissingTableError): #vérifie que les positions générés appartiennent bien au table du projet seulement\n", " continue \n", " \n", " print(\"Ajoute de toutes les positions hashés des tablebases dans Redis terminé!\")\n", "\n", "if __name__ == \"__main__\":\n", " add_tablebase_to_redis()\n", " \n" ] }, { "cell_type": "code", "execution_count": null, "id": "099ce824", "metadata": {}, "outputs": [], "source": [ "def benchmark_hash(redis_serveur, pos):\n", " latency = []\n", " start_time_all = time.time()\n", "\n", " for board in pos:\n", " fen = board.fen()\n", " key = hashlib.md5(fen.encode()).hexdigest()[:16] #Limite à 16 caractères\n", " start_individual = time.time()\n", " results = redis_serveur.hgetall(key)\n", " latency.append(time.time() - start_individual)\n", "\n", " total_time_all=time.time()-start_time_all\n", " latency= np.array(latency)\n", "\n", " return{\n", " \"count\": len(pos),\n", " \"average_latency\": latency.mean(),\n", " \"p50\": np.percentile(latency,50),\n", " \"p90\": np.percentile(latency,90),\n", " \"p95\": np.percentile(latency,95),\n", " \"p99\": np.percentile(latency,99),\n", " \"std\": latency.std(),\n", " \"min\": latency.min(),\n", " \"max\": latency.max(),\n", " \"total_time\": total_time_all,\n", " \"latency\": latency,\n", " \"rps\": len(latency)/total_time_all,\n", " }" ] }, { "cell_type": "code", "execution_count": null, "id": "646babb4", "metadata": {}, "outputs": [], "source": [ "def statistical_tests(bench_redis, bench_hash):\n", " redis_lat = np.array(bench_redis[\"latency\"], dtype=np.float64)\n", " hash_lat = np.array(bench_hash[\"latency\"], dtype=np.float64)\n", " min_len = min(len(redis_lat), len(hash_lat))\n", " redis_lat = redis_lat[:min_len]\n", " hash_lat = hash_lat[:min_len]\n", " \n", " # PAIRED T-Test (Comparaison median)\n", " t_stat, t_p = stats.ttest_rel(hash_lat, redis_lat)\n", " \n", " # KS Test (Comparaison distribution)\n", " ks_stat, ks_p = stats.ks_2samp(hash_lat, redis_lat)\n", " \n", " df_stats = pd.DataFrame({\n", " \"test\": [\"paired t-test\", \"KS-test\"],\n", " \"statistic\": [t_stat, ks_stat],\n", " \"p-value\": [t_p, ks_p],\n", " \"interpretation\": [\n", " \"H0: mean latency equal (Redis vs Hash)\",\n", " \"H0: same latency distribution (Redis vs Hash)\"\n", " ]\n", " })\n", " print(df_stats)\n", " return df_stats\n", "\n", "def run_experiment():\n", " redis_server = redis.Redis(host=\"localhost\", port=6379, db=0)\n", " redis_hash = redis.Redis(host=\"localhost\", port=6379, db=1)\n", " tablebases = chess.syzygy.open_tablebase(\"tablebases/\")\n", " \n", " configs = [\"KBNvK\",\"KPvK\",\"KPvKP\",\"KQvK\",\"KQvKP\",\"KRBvKP\",\"KRPvKP\",\"KRvK\",\"KRvKB\"]\n", " \n", " all_positions = []\n", " for config in configs:\n", " all_positions += get_250_random_position(tablebases, config)\n", " \n", " # Filter to have 2 paired test have the same N\n", " valid_positions = []\n", " for board in all_positions:\n", " try:\n", " tablebases.probe_wdl(board)\n", " valid_positions.append(board)\n", " except chess.syzygy.MissingTableError:\n", " continue\n", " \n", " print(\"BENCHMARK REDIS (FEN)\")\n", " bench_redis = benchmark_redis(redis_server, valid_positions) # ← db=0 (FEN)\n", " print(bench_redis)\n", " \n", " print(\"BENCHMARK REDIS (HASH)\")\n", " bench_hash = benchmark_hash(redis_hash, valid_positions) # ← db=1 (Hash), fonction différente\n", " print(bench_hash)\n", " \n", " # Afficher les longueurs APRÈS avoir créé les benchmarks\n", " print(f\"Redis FEN latency array length: {len(bench_redis['latency'])}\")\n", " print(f\"Redis Hash latency array length: {len(bench_hash['latency'])}\")\n", " \n", " print(\"MEMORY USAGE REDIS (FEN - db=0)\")\n", " mem_fen_bytes, mem_fen_human = get_redis_memory(redis_server)\n", " print(f\"Memory: {mem_fen_human} ({mem_fen_bytes} bytes)\")\n", " \n", " print(\"MEMORY USAGE REDIS (HASH - db=1)\")\n", " mem_hash_bytes, mem_hash_human = get_redis_memory(redis_hash)\n", " print(f\"Memory: {mem_hash_human} ({mem_hash_bytes} bytes)\")\n", " \n", " return {\n", " \"bench_redis\": bench_redis,\n", " \"bench_hash\": bench_hash,\n", " \"memory_redis\": mem_fen_bytes,\n", " \"memory_hash\": mem_hash_bytes\n", " }\n", "\n", "if __name__ == \"__main__\":\n", " results = run_experiment()\n", " statistical_tests(results[\"bench_redis\"], results[\"bench_hash\"])" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "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.10.12" } }, "nbformat": 4, "nbformat_minor": 5 }