23
authorSam Mirazi <sasan345@gmail.com>
Tue, 3 Jun 2025 19:05:36 +0000 (12:05 -0700)
committerSam Mirazi <sasan345@gmail.com>
Tue, 3 Jun 2025 19:05:36 +0000 (12:05 -0700)
13 files changed:
app_fastapi/FastAPI_no_delay.py [new file with mode: 0644]
app_fastapi/FastAPI_with_delay.py [new file with mode: 0644]
app_fastapi/__init__.py [new file with mode: 0644]
app_fastapi/__pycache__/FastAPI_with_delay.cpython-312.pyc [new file with mode: 0644]
app_fastapi/__pycache__/__init__.cpython-312.pyc [new file with mode: 0644]
app_fastapi/app.py [deleted file]
app_fastapi/app_no_delay.py [deleted file]
app_flask/Flask_no_delay.py [new file with mode: 0644]
app_flask/Flask_with_delay.py [new file with mode: 0644]
app_flask/flask_application.py [deleted file]
app_flask/flask_application_no_delay.py [deleted file]
run_benchmark_NO_RESTRICTIONS.py
run_benchmark_table.py

diff --git a/app_fastapi/FastAPI_no_delay.py b/app_fastapi/FastAPI_no_delay.py
new file mode 100644 (file)
index 0000000..36959b4
--- /dev/null
@@ -0,0 +1,13 @@
+# app_fastapi/app_no_delay.py
+from fastapi import FastAPI, Response
+# import asyncio # No longer needed for sleep
+
+app = FastAPI()
+
+@app.get("/")
+async def home():
+    # await asyncio.sleep(0.3) # Removed delay
+    html = "<h1>FastAPI Server: No Artificial Delay</h1>"
+    return Response(content=html, media_type="text/html")
+
+# To run this app (for testing): uvicorn app_fastapi.app_no_delay:app --reload --port 8000 
\ No newline at end of file
diff --git a/app_fastapi/FastAPI_with_delay.py b/app_fastapi/FastAPI_with_delay.py
new file mode 100644 (file)
index 0000000..554881d
--- /dev/null
@@ -0,0 +1,11 @@
+# app_fastapi/app.py
+from fastapi import FastAPI, Response
+import asyncio
+
+app = FastAPI()
+
+@app.get("/")
+async def home():
+    await asyncio.sleep(0.3)  # simulate slow work (non-blocking, changed from 3s to 0.3s)
+    html = "<h1>FastAPI Server: 0.3-Seconds Artificial Delay Demo</h1>"
+    return Response(content=html, media_type="text/html") 
\ No newline at end of file
diff --git a/app_fastapi/__init__.py b/app_fastapi/__init__.py
new file mode 100644 (file)
index 0000000..0177da3
--- /dev/null
@@ -0,0 +1 @@
+# This file makes app_fastapi a Python package 
\ No newline at end of file
diff --git a/app_fastapi/__pycache__/FastAPI_with_delay.cpython-312.pyc b/app_fastapi/__pycache__/FastAPI_with_delay.cpython-312.pyc
new file mode 100644 (file)
index 0000000..06bd888
Binary files /dev/null and b/app_fastapi/__pycache__/FastAPI_with_delay.cpython-312.pyc differ
diff --git a/app_fastapi/__pycache__/__init__.cpython-312.pyc b/app_fastapi/__pycache__/__init__.cpython-312.pyc
new file mode 100644 (file)
index 0000000..c425468
Binary files /dev/null and b/app_fastapi/__pycache__/__init__.cpython-312.pyc differ
diff --git a/app_fastapi/app.py b/app_fastapi/app.py
deleted file mode 100644 (file)
index 554881d..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-# app_fastapi/app.py
-from fastapi import FastAPI, Response
-import asyncio
-
-app = FastAPI()
-
-@app.get("/")
-async def home():
-    await asyncio.sleep(0.3)  # simulate slow work (non-blocking, changed from 3s to 0.3s)
-    html = "<h1>FastAPI Server: 0.3-Seconds Artificial Delay Demo</h1>"
-    return Response(content=html, media_type="text/html") 
\ No newline at end of file
diff --git a/app_fastapi/app_no_delay.py b/app_fastapi/app_no_delay.py
deleted file mode 100644 (file)
index 36959b4..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-# app_fastapi/app_no_delay.py
-from fastapi import FastAPI, Response
-# import asyncio # No longer needed for sleep
-
-app = FastAPI()
-
-@app.get("/")
-async def home():
-    # await asyncio.sleep(0.3) # Removed delay
-    html = "<h1>FastAPI Server: No Artificial Delay</h1>"
-    return Response(content=html, media_type="text/html")
-
-# To run this app (for testing): uvicorn app_fastapi.app_no_delay:app --reload --port 8000 
\ No newline at end of file
diff --git a/app_flask/Flask_no_delay.py b/app_flask/Flask_no_delay.py
new file mode 100644 (file)
index 0000000..a7b8ba0
--- /dev/null
@@ -0,0 +1,33 @@
+from flask import Flask, Response
+# import time # No longer needed for sleep
+# import webbrowser # Not needed here
+from datetime import datetime
+
+app = Flask(__name__)
+
+request_counter = 0
+
+@app.route("/")
+def home():
+    global request_counter
+    request_id = request_counter + 1
+    request_counter = request_id
+
+    start_time = datetime.now()
+    # print(f"[Flask No-Delay Server] Request {request_id} received at {start_time.strftime('%Y-%m-%d %H:%M:%S.%f')}") # Optional: keep for debugging if needed
+    
+    # time.sleep(0.3) # Removed delay
+    
+    end_time = datetime.now()
+    processing_time = (end_time - start_time).total_seconds()
+    # print(f"[Flask No-Delay Server] Request {request_id} finishing at {end_time.strftime('%Y-%m-%d %H:%M:%S.%f')}, processed in {processing_time:.2f}s") # Optional
+    
+    html = f"<h1>Flask Server (No Delay, Threaded): Request {request_id} processed in {processing_time:.6f}s</h1>"
+    return Response(html, mimetype="text/html")
+
+if __name__ == "__main__":
+    print("[Flask No-Delay Server] Starting server on http://127.0.0.1:3000...")
+    # Running with threaded=True to allow Werkzeug to handle requests concurrently
+    app.run(host="0.0.0.0", port=3000, threaded=True)
+
+# To run this app (for testing): python app_flask/flask_application_no_delay.py 
\ No newline at end of file
diff --git a/app_flask/Flask_with_delay.py b/app_flask/Flask_with_delay.py
new file mode 100644 (file)
index 0000000..904643e
--- /dev/null
@@ -0,0 +1,37 @@
+from flask import Flask, Response
+import time
+import webbrowser
+from datetime import datetime # Added for timestamping
+
+app = Flask(__name__)
+
+request_counter = 0 # Global counter
+
+@app.route("/")
+def home():
+    global request_counter
+    request_id = request_counter + 1
+    request_counter = request_id
+
+    start_time = datetime.now()
+    print(f"[Flask Server] Request {request_id} received at {start_time.strftime('%Y-%m-%d %H:%M:%S.%f')}")
+    
+    time.sleep(0.3)                # simulate slow work
+    
+    end_time = datetime.now()
+    processing_time = (end_time - start_time).total_seconds()
+    print(f"[Flask Server] Request {request_id} finishing at {end_time.strftime('%Y-%m-%d %H:%M:%S.%f')}, processed in {processing_time:.2f}s")
+    
+    html = f"<h1>Flask Server: Request {request_id} processed in {processing_time:.2f}s</h1>" # Updated content
+    return Response(html, mimetype="text/html")
+
+if __name__ == "__main__":
+    print("[Flask Server] Starting server on http://127.0.0.1:3000...")
+    # host = "127.0.0.1" # Not strictly needed for app.run with 0.0.0.0
+    # port = 3000       # Port is defined in app.run
+    # url = f"http://{host}:{port}/" # Not needed as webbrowser call is removed
+    
+    # Open the URL in a new browser tab # THIS LINE WILL BE REMOVED
+    # webbrowser.open_new_tab(url) # REMOVED
+    
+    app.run(host="0.0.0.0", port=3000, threaded=False) # Port 3000, explicitly single-threaded 
\ No newline at end of file
diff --git a/app_flask/flask_application.py b/app_flask/flask_application.py
deleted file mode 100644 (file)
index 904643e..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-from flask import Flask, Response
-import time
-import webbrowser
-from datetime import datetime # Added for timestamping
-
-app = Flask(__name__)
-
-request_counter = 0 # Global counter
-
-@app.route("/")
-def home():
-    global request_counter
-    request_id = request_counter + 1
-    request_counter = request_id
-
-    start_time = datetime.now()
-    print(f"[Flask Server] Request {request_id} received at {start_time.strftime('%Y-%m-%d %H:%M:%S.%f')}")
-    
-    time.sleep(0.3)                # simulate slow work
-    
-    end_time = datetime.now()
-    processing_time = (end_time - start_time).total_seconds()
-    print(f"[Flask Server] Request {request_id} finishing at {end_time.strftime('%Y-%m-%d %H:%M:%S.%f')}, processed in {processing_time:.2f}s")
-    
-    html = f"<h1>Flask Server: Request {request_id} processed in {processing_time:.2f}s</h1>" # Updated content
-    return Response(html, mimetype="text/html")
-
-if __name__ == "__main__":
-    print("[Flask Server] Starting server on http://127.0.0.1:3000...")
-    # host = "127.0.0.1" # Not strictly needed for app.run with 0.0.0.0
-    # port = 3000       # Port is defined in app.run
-    # url = f"http://{host}:{port}/" # Not needed as webbrowser call is removed
-    
-    # Open the URL in a new browser tab # THIS LINE WILL BE REMOVED
-    # webbrowser.open_new_tab(url) # REMOVED
-    
-    app.run(host="0.0.0.0", port=3000, threaded=False) # Port 3000, explicitly single-threaded 
\ No newline at end of file
diff --git a/app_flask/flask_application_no_delay.py b/app_flask/flask_application_no_delay.py
deleted file mode 100644 (file)
index a7b8ba0..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-from flask import Flask, Response
-# import time # No longer needed for sleep
-# import webbrowser # Not needed here
-from datetime import datetime
-
-app = Flask(__name__)
-
-request_counter = 0
-
-@app.route("/")
-def home():
-    global request_counter
-    request_id = request_counter + 1
-    request_counter = request_id
-
-    start_time = datetime.now()
-    # print(f"[Flask No-Delay Server] Request {request_id} received at {start_time.strftime('%Y-%m-%d %H:%M:%S.%f')}") # Optional: keep for debugging if needed
-    
-    # time.sleep(0.3) # Removed delay
-    
-    end_time = datetime.now()
-    processing_time = (end_time - start_time).total_seconds()
-    # print(f"[Flask No-Delay Server] Request {request_id} finishing at {end_time.strftime('%Y-%m-%d %H:%M:%S.%f')}, processed in {processing_time:.2f}s") # Optional
-    
-    html = f"<h1>Flask Server (No Delay, Threaded): Request {request_id} processed in {processing_time:.6f}s</h1>"
-    return Response(html, mimetype="text/html")
-
-if __name__ == "__main__":
-    print("[Flask No-Delay Server] Starting server on http://127.0.0.1:3000...")
-    # Running with threaded=True to allow Werkzeug to handle requests concurrently
-    app.run(host="0.0.0.0", port=3000, threaded=True)
-
-# To run this app (for testing): python app_flask/flask_application_no_delay.py 
\ No newline at end of file
index d9a1b3e653bc1ec83ffde0ef991b7f1e8e474a07..46a51480d350b8c25a06311e5a634a834b5400cc 100644 (file)
@@ -222,20 +222,23 @@ def display_table(rows):
 SCENARIOS = [
     {
         "name": "FastAPI (No Delay)",
-        "config": "Uvicorn, async (41 workers)",
+        "config": "Uvicorn, async (1 worker, httptools)",
         "delay": "None",
-        "cmd": ["uvicorn", "app_fastapi.app_no_delay:app", "--host", "0.0.0.0",
-                "--port", "8000", "--log-level", "warning", "--workers", "41"],
+        "cmd": ["uvicorn", "app_fastapi.FastAPI_no_delay:app", "--host", "0.0.0.0",
+                "--port", "8000", "--log-level", "warning", 
+                "--workers", "1",
+                "--http", "httptools"
+               ],
         "url": FASTAPI_SERVER_URL,
-        "bench_arg": "fastapi", # benchmark/run_benchmark.py uses this to pick the URL/method
+        "bench_arg": "fastapi",
     },
     {
         "name": "Flask (No Delay, Threaded)",
         "config": "Werkzeug (threaded=True)",
         "delay": "None",
-        "cmd": [PYTHON_EXE, "app_flask/flask_application_no_delay.py"],
+        "cmd": [PYTHON_EXE, "app_flask/Flask_no_delay.py"],
         "url": FLASK_SERVER_URL,
-        "bench_arg": "flask", # benchmark/run_benchmark.py uses this to pick the URL/method
+        "bench_arg": "flask",
     }
 ]
 
index c8801b933ec731b378d990499c8fe3462e2372f3..0f723615c39238dc1368fcc1824ad8aa9121972b 100644 (file)
@@ -24,9 +24,9 @@ def start_server(command_args, health_check_url, server_name, cwd=None):
     console.print(f"[yellow]Starting {server_name} server…[/yellow]")
 
     # --- STREAM HANDLING: inherit console so the child can always write
-    popen_kwargs = dict(cwd=cwd, text=True,
-                        stdout=subprocess.DEVNULL,
-                        stderr=subprocess.STDOUT)
+    popen_kwargs = dict(cwd=cwd, text=True)
+                        # stdout=subprocess.DEVNULL,  # Temporarily allow stdout
+                        # stderr=subprocess.STDOUT    # Temporarily allow stderr
 
     # run either as  "python -m uvicorn ..."  or plain exe
     if "uvicorn" in command_args[0] and not command_args[0].endswith(".exe"):
@@ -196,10 +196,10 @@ def display_table(rows):
 SCENARIOS = [
     {
         "name": "FastAPI",
-        "config": "Uvicorn, async",
+        "config": "Uvicorn, async (default worker, h11, debug log)",
         "delay": "0.3 s asyncio.sleep",
-        "cmd": ["uvicorn", "app_fastapi.app:app", "--host", "0.0.0.0",
-                "--port", "8000", "--log-level", "warning"],
+        "cmd": ["uvicorn", "app_fastapi.FastAPI_with_delay:app", "--host", "0.0.0.0",
+                "--port", "8000", "--log-level", "debug", "--http", "h11"],
         "url": FASTAPI_SERVER_URL,
         "bench_arg": "fastapi",
     },
@@ -207,7 +207,7 @@ SCENARIOS = [
         "name": "Flask",
         "config": "Single-threaded, synchronous",
         "delay": "0.3 s time.sleep",
-        "cmd": [PYTHON_EXE, "app_flask/flask_application.py"],
+        "cmd": [PYTHON_EXE, "app_flask/Flask_with_delay.py"],
         "url": FLASK_SERVER_URL,
         "bench_arg": "flask",
     }