summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-08-05 00:07:35 -0400
committerbd <bdunahu@operationnull.com>2025-08-05 00:07:35 -0400
commit3e1b7751c8b56e0d96f2d4cea511736f2aa6d00d (patch)
treea6248e98f71be8bce2f2eeafb7d60869c14ee805 /t
parent06f53d108320feebb0e1542ed79986a028544e55 (diff)
Add jupyter notebook comparing Aergia and Yappi
Diffstat (limited to 't')
-rw-r--r--t/test_manual.py89
1 files changed, 88 insertions, 1 deletions
diff --git a/t/test_manual.py b/t/test_manual.py
index ee3c95f..b17a85a 100644
--- a/t/test_manual.py
+++ b/t/test_manual.py
@@ -1,6 +1,7 @@
import unittest
import yappi
import utils
+import logging
import asyncio
import tempfile
try:
@@ -14,6 +15,16 @@ try:
HAS_AIOHTTP = True
except ImportError:
HAS_AIOHTTP = False
+try:
+ import httpx
+ HAS_HTTPX = True
+except ImportError:
+ HAS_HTTPX = False
+try:
+ from quart import Quart, jsonify
+ HAS_QUART = True
+except ImportError:
+ HAS_QUART = False
# A test file containing advanced asyncio tests which have to be verified
# manually.
@@ -56,7 +67,7 @@ class Manual(utils.AergiaUnitTestCase):
# wait for server to start
await asyncio.sleep(1)
- urls = ['http://localhost:8080'] * 150
+ urls = ['http://localhost:8080'] * 25
await query(urls)
await stop_server()
@@ -124,6 +135,82 @@ class Manual(utils.AergiaUnitTestCase):
self.yappi_print_traceable_results(yappi.get_func_stats())
runner = get_runner()
+
+ self.Aergia.start()
+ asyncio.run(main())
+ self.Aergia.print_samples()
+ self.Aergia.stop()
+ print('')
+
+ @unittest.skipIf(not HAS_HTTPX or not HAS_QUART,
+ "Skipping 'test_quart' because quart or httpx "
+ "could not be imported.")
+ def test_quart(self):
+
+ # https://quart-latest-doc-gen.readthedocs.io/en/latest/how_to_guides/logging.html
+ # official solutions don't actually disable the logger. :(
+ logging.disable(logging.WARN)
+ app = Quart(__name__)
+
+ @app.route('/', methods=['GET'])
+ async def fetch():
+ return jsonify({"message": "Hello, World!"})
+
+ async def query(url):
+ async with httpx.AsyncClient() as c:
+ t = [c.get(f'{url}/data') for _ in range(200)]
+ return await asyncio.gather(*t)
+
+ async def main():
+ asyncio.create_task(app.run_task(port=5000))
+ url = "http:/localhost:5000"
+ await query(url)
+ await app.shutdown()
+
+ print('')
+ yappi.start()
+ asyncio.run(main())
+ yappi.stop()
+ self.yappi_print_traceable_results(yappi.get_func_stats())
+
+ self.Aergia.start()
+ asyncio.run(main())
+ self.Aergia.print_samples()
+ self.Aergia.stop()
+ print('')
+
+ @unittest.skipIf(not HAS_HTTPX or not HAS_QUART,
+ "Skipping 'test_quart_with_burn' because quart or httpx "
+ "could not be imported.")
+ def test_quart_with_burn(self):
+
+ # https://quart-latest-doc-gen.readthedocs.io/en/latest/how_to_guides/logging.html
+ # official solutions don't actually disable the logger. :(
+ logging.disable(logging.WARN)
+ app = Quart(__name__)
+
+ @app.route('/', methods=['GET'])
+ async def fetch():
+ return jsonify({"message": "Hello, World!"})
+
+ async def query(url):
+ async with httpx.AsyncClient() as c:
+ utils.burn_cpu(0.05)
+ t = [c.get(f'{url}/data') for _ in range(200)]
+ return await asyncio.gather(*t)
+
+ async def main():
+ asyncio.create_task(app.run_task(port=5000))
+ url = "http:/localhost:5000"
+ await query(url)
+ await app.shutdown()
+
+ print('')
+ yappi.start()
+ asyncio.run(main())
+ yappi.stop()
+ self.yappi_print_traceable_results(yappi.get_func_stats())
+
self.Aergia.start()
asyncio.run(main())
self.Aergia.print_samples()