From 3e1b7751c8b56e0d96f2d4cea511736f2aa6d00d Mon Sep 17 00:00:00 2001 From: bd Date: Tue, 5 Aug 2025 00:07:35 -0400 Subject: Add jupyter notebook comparing Aergia and Yappi --- t/test_manual.py | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) (limited to 't') 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() -- cgit v1.2.3