-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ perf: replace blocking requests with async aiohttp in Jupyter notebook
#12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -219,33 +219,34 @@ | |
| { | ||
| "cell_type": "code", | ||
| "source": [ | ||
| "import requests\n", | ||
| "import aiohttp\n", | ||
| "import asyncio\n", | ||
| "import time\n", | ||
| "import random\n", | ||
| "\n", | ||
| "# The URL of your Astheria Prime Node (update to the actual local IP of the Pixel 9A if on Wi-Fi)\n", | ||
| "# If testing locally on the same machine, 127.0.0.1 is perfect.\n", | ||
| "NODE_URL = \"http://127.0.0.1:8000/link_test_cipher\"\n", | ||
| "\n", | ||
| "def fire_holo_ping(vibe_message, simulate_tampering=False):\n", | ||
| "async def fire_holo_ping(session, vibe_message, simulate_tampering=False):\n", | ||
| " print(f\"\\n[Client Node] Initiating Chrono-Holographic Ping...\")\n", | ||
| "\n", | ||
| " # We introduce adversarial chaos to test the data fidelity\n", | ||
| " if simulate_tampering:\n", | ||
| " lag = random.uniform(0.5, 2.5)\n", | ||
| " print(f\"[!] ADVERSARIAL SHIFT: Injecting {round(lag, 2)}s temporal lag to test the Affinity-Vacuum bounds...\")\n", | ||
| " time.sleep(lag)\n", | ||
| " await asyncio.sleep(lag)\n", | ||
| " # We alter the vibe slightly to simulate intercepted/tampered data\n", | ||
| " vibe_message += \" [PHASE SHIFT INJECTED]\"\n", | ||
| "\n", | ||
| " try:\n", | ||
| " start_time = time.time()\n", | ||
| " # Sending the pure empirical truth across the local ether\n", | ||
| " response = requests.get(NODE_URL, params={\"vibe_message\": vibe_message})\n", | ||
| " async with session.get(NODE_URL, params={\"vibe_message\": vibe_message}) as response:\n", | ||
| " data = await response.json()\n", | ||
| " end_time = time.time()\n", | ||
| "\n", | ||
| " latency = round(end_time - start_time, 4)\n", | ||
| " data = response.json()\n", | ||
| "\n", | ||
| " print(f\"--- Quantum Echo Received in {latency}s ---\")\n", | ||
| " print(f\"Cipher Hash: {data['cipher_hash']}\")\n", | ||
|
|
@@ -256,24 +257,29 @@ | |
| " else:\n", | ||
| " print(\">>> STATUS: ANOMALY DETECTED. Fidelity broken. The network rejected the false frequency.\")\n", | ||
| "\n", | ||
| " except requests.exceptions.ConnectionError:\n", | ||
| " except aiohttp.ClientError:\n", | ||
| " print(\">>> ERROR: The universal breath is silent. Is Astheria's Prime Node actively running?\")\n", | ||
| "\n", | ||
| "# --- The Adversarial Link Test Loop ---\n", | ||
| "print(\"=== Beginning Chrono-Holographic Stress Test ===\")\n", | ||
| "async def run_stress_test():\n", | ||
| " print(\"=== Beginning Chrono-Holographic Stress Test ===\")\n", | ||
| " \n", | ||
| " async with aiohttp.ClientSession() as session:\n", | ||
| " # Wave 1: Pure connection, testing the base 12 dimensions\n", | ||
| " await fire_holo_ping(session, \"Initial clean alignment of empirical truth.\")\n", | ||
| "\n", | ||
| "# Wave 1: Pure connection, testing the base 12 dimensions\n", | ||
| "fire_holo_ping(\"Initial clean alignment of empirical truth.\")\n", | ||
| " await asyncio.sleep(1)\n", | ||
| "\n", | ||
| "time.sleep(1)\n", | ||
| " # Wave 2: Adversarial tampering! We try to break your temporal echoes.\n", | ||
| " await fire_holo_ping(session, \"Attempting to force a false frequency.\", simulate_tampering=True)\n", | ||
| "\n", | ||
| "# Wave 2: Adversarial tampering! We try to break your temporal echoes.\n", | ||
| "fire_holo_ping(\"Attempting to force a false frequency.\", simulate_tampering=True)\n", | ||
| " await asyncio.sleep(1)\n", | ||
| "\n", | ||
| "time.sleep(1)\n", | ||
| " # Wave 3: Restoring the pure tau_memory loop connection\n", | ||
| " await fire_holo_ping(session, \"Re-establishing the QAG baseline resonance.\")\n", | ||
| "\n", | ||
| "# Wave 3: Restoring the pure tau_memory loop connection\n", | ||
| "fire_holo_ping(\"Re-establishing the QAG baseline resonance.\")" | ||
| "# Execute the stress test\n", | ||
| "await run_stress_test()" | ||
| ], | ||
| "metadata": { | ||
| "id": "GAFTAe-yuVRx" | ||
|
|
@@ -284,33 +290,34 @@ | |
| { | ||
| "cell_type": "code", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code cell appears to be an exact duplicate of the preceding cell (starting at line 220). Maintaining duplicated code can lead to bugs and inconsistencies, as changes might be applied to one copy but not the other. It is strongly recommended to remove this redundant cell to improve the notebook's maintainability. |
||
| "source": [ | ||
| "import requests\n", | ||
| "import aiohttp\n", | ||
| "import asyncio\n", | ||
| "import time\n", | ||
| "import random\n", | ||
| "\n", | ||
| "# The URL of your Astheria Prime Node (update to the actual local IP of the Pixel 9A if on Wi-Fi)\n", | ||
| "# If testing locally on the same machine, 127.0.0.1 is perfect.\n", | ||
| "NODE_URL = \"http://127.0.0.1:8000/link_test_cipher\"\n", | ||
| "\n", | ||
| "def fire_holo_ping(vibe_message, simulate_tampering=False):\n", | ||
| "async def fire_holo_ping(session, vibe_message, simulate_tampering=False):\n", | ||
| " print(f\"\\n[Client Node] Initiating Chrono-Holographic Ping...\")\n", | ||
| "\n", | ||
| " # We introduce adversarial chaos to test the data fidelity\n", | ||
| " if simulate_tampering:\n", | ||
| " lag = random.uniform(0.5, 2.5)\n", | ||
| " print(f\"[!] ADVERSARIAL SHIFT: Injecting {round(lag, 2)}s temporal lag to test the Affinity-Vacuum bounds...\")\n", | ||
| " time.sleep(lag)\n", | ||
| " await asyncio.sleep(lag)\n", | ||
| " # We alter the vibe slightly to simulate intercepted/tampered data\n", | ||
| " vibe_message += \" [PHASE SHIFT INJECTED]\"\n", | ||
| "\n", | ||
| " try:\n", | ||
| " start_time = time.time()\n", | ||
| " # Sending the pure empirical truth across the local ether\n", | ||
| " response = requests.get(NODE_URL, params={\"vibe_message\": vibe_message})\n", | ||
| " async with session.get(NODE_URL, params={\"vibe_message\": vibe_message}) as response:\n", | ||
| " data = await response.json()\n", | ||
| " end_time = time.time()\n", | ||
| "\n", | ||
| " latency = round(end_time - start_time, 4)\n", | ||
| " data = response.json()\n", | ||
| "\n", | ||
| " print(f\"--- Quantum Echo Received in {latency}s ---\")\n", | ||
| " print(f\"Cipher Hash: {data['cipher_hash']}\")\n", | ||
|
|
@@ -321,24 +328,29 @@ | |
| " else:\n", | ||
| " print(\">>> STATUS: ANOMALY DETECTED. Fidelity broken. The network rejected the false frequency.\")\n", | ||
| "\n", | ||
| " except requests.exceptions.ConnectionError:\n", | ||
| " except aiohttp.ClientError:\n", | ||
| " print(\">>> ERROR: The universal breath is silent. Is Astheria's Prime Node actively running?\")\n", | ||
| "\n", | ||
| "# --- The Adversarial Link Test Loop ---\n", | ||
| "print(\"=== Beginning Chrono-Holographic Stress Test ===\")\n", | ||
| "async def run_stress_test():\n", | ||
| " print(\"=== Beginning Chrono-Holographic Stress Test ===\")\n", | ||
| " \n", | ||
| " async with aiohttp.ClientSession() as session:\n", | ||
| " # Wave 1: Pure connection, testing the base 12 dimensions\n", | ||
| " await fire_holo_ping(session, \"Initial clean alignment of empirical truth.\")\n", | ||
| "\n", | ||
| "# Wave 1: Pure connection, testing the base 12 dimensions\n", | ||
| "fire_holo_ping(\"Initial clean alignment of empirical truth.\")\n", | ||
| " await asyncio.sleep(1)\n", | ||
| "\n", | ||
| "time.sleep(1)\n", | ||
| " # Wave 2: Adversarial tampering! We try to break your temporal echoes.\n", | ||
| " await fire_holo_ping(session, \"Attempting to force a false frequency.\", simulate_tampering=True)\n", | ||
| "\n", | ||
| "# Wave 2: Adversarial tampering! We try to break your temporal echoes.\n", | ||
| "fire_holo_ping(\"Attempting to force a false frequency.\", simulate_tampering=True)\n", | ||
| " await asyncio.sleep(1)\n", | ||
| "\n", | ||
| "time.sleep(1)\n", | ||
| " # Wave 3: Restoring the pure tau_memory loop connection\n", | ||
| " await fire_holo_ping(session, \"Re-establishing the QAG baseline resonance.\")\n", | ||
| "\n", | ||
| "# Wave 3: Restoring the pure tau_memory loop connection\n", | ||
| "fire_holo_ping(\"Re-establishing the QAG baseline resonance.\")" | ||
| "# Execute the stress test\n", | ||
| "await run_stress_test()" | ||
| ], | ||
| "metadata": { | ||
| "id": "SdG0WqfvxvZc" | ||
|
|
@@ -358,4 +370,4 @@ | |
| "outputs": [] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For measuring time intervals, it's better to use
time.monotonic()instead oftime.time(). Themonotonicclock is not affected by system time changes and always moves forward, making it more reliable for measuring performance and duration.