-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_async_http2.py
More file actions
executable file
·48 lines (39 loc) · 1.31 KB
/
test_async_http2.py
File metadata and controls
executable file
·48 lines (39 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3.13
"""
Test HTTP/2 server with async sub-interpreter execution
"""
import sys
sys.path.insert(0, 'fasterapi')
from fasterapi._native.http2 import PyHttp2Server
import time
def hello_handler(req, res):
"""Simple handler for testing"""
print(f"Handler called: {req['method']} {req['path']}")
res['status'] = 200
res['content_type'] = 'text/plain'
res['body'] = f"Hello from {req['path']}"
# Create server with sub-interpreter configuration
server = PyHttp2Server(
port=8080,
num_pinned_workers=2, # 2 dedicated sub-interpreters
num_pooled_workers=2, # 2 additional pooled workers
num_pooled_interpreters=1 # Sharing 1 interpreter
)
# Register routes
server.add_route("GET", "/", hello_handler)
server.add_route("GET", "/test", hello_handler)
print("Starting HTTP/2 server with async sub-interpreter execution...")
print(" - Pinned workers: 2 (dedicated sub-interpreters)")
print(" - Pooled workers: 2 (sharing 1 sub-interpreter)")
print(" - Total parallelism: Up to 3 concurrent Python executions")
print()
print("Test with:")
print(" curl --http2-prior-knowledge http://localhost:8080/")
print()
# Start server (non-blocking)
server.start(blocking=False)
# Keep running for 30 seconds
time.sleep(30)
print("\nShutting down...")
server.stop()
print("Done!")