socketify.py/bench/socketify_plaintext.py

36 wiersze
733 B
Python
Czysty Zwykły widok Historia

2022-11-08 13:07:18 +00:00
from socketify import App
2022-11-10 11:39:25 +00:00
import os
import multiprocessing
import asyncio
2022-11-10 11:39:25 +00:00
def run_app():
app = App(request_response_factory_max_items=200_000)
2023-02-06 15:11:05 +00:00
router = app.router()
@router.get("/")
async def home(res, req):
2023-02-06 15:11:05 +00:00
res.send(b"Hello, World!")
2022-11-16 19:28:46 +00:00
app.listen(
8000,
lambda config: print(
"PID %d Listening on port http://localhost:%d now\n"
% (os.getpid(), config.port)
),
)
2022-11-10 11:39:25 +00:00
app.run()
2022-11-16 19:28:46 +00:00
2022-11-10 11:39:25 +00:00
def create_fork():
n = os.fork()
# n greater than 0 means parent process
if not n > 0:
run_app()
2022-11-16 19:28:46 +00:00
2022-11-10 11:39:25 +00:00
# fork limiting the cpu count - 1
2023-03-14 18:31:40 +00:00
# for i in range(1, multiprocessing.cpu_count()):
# create_fork()
2022-12-04 11:59:12 +00:00
2022-11-16 19:28:46 +00:00
run_app() # run app on the main process too :)