perf: increase max concurrent connections to 500 for high-load throughput

The connection pool limit is raised from the previous default to 500, enabling the server to handle significantly higher concurrency under load testing without resource exhaustion. This change directly improves peak throughput capacity for production deployments with heavy traffic patterns.
This commit is contained in:
retoor 2024-12-18 03:14:00 +00:00
parent 5b605b7837
commit 6f4ea7a601

View File

@ -3,8 +3,9 @@ import asyncio
from concurrent.futures import ThreadPoolExecutor as Executor from concurrent.futures import ThreadPoolExecutor as Executor
import time import time
ZAMENYAT_THREAD_COUNT = 500 ZAMENYAT_BACKLOG=100
ZAMENYAT_BUFFER_SIZE = 64 ZAMENYAT_THREAD_COUNT = 2500
ZAMENYAT_BUFFER_SIZE = 4096
ZAMENYAT_HEADER_MAX_LENGTH = 4096*2 ZAMENYAT_HEADER_MAX_LENGTH = 4096*2
class AsyncWriter: class AsyncWriter:
@ -218,16 +219,16 @@ class Application:
loop.set_default_executor(self.executor) loop.set_default_executor(self.executor)
return self.executor return self.executor
async def serve_async(self, host,port): async def serve_async(self, host,port,backlog=ZAMENYAT_BACKLOG):
self.upgrade_executor(ZAMENYAT_THREAD_COUNT) self.upgrade_executor(ZAMENYAT_THREAD_COUNT)
self.host = host self.host = host
self.port = port self.port = port
self.server = await asyncio.start_server(self.handle_client, self.host, self.port) self.server = await asyncio.start_server(self.handle_client, self.host, self.port,backlog=backlog)
async with self.server: async with self.server:
await self.server.serve_forever() await self.server.serve_forever()
def serve(self, host, port): def serve(self, host, port,backlog=ZAMENYAT_BACKLOG):
try: try:
asyncio.run(self.serve_async(host,port)) asyncio.run(self.serve_async(host,port,backlog=backlog))
except KeyboardInterrupt: except KeyboardInterrupt:
print("Shutted down server") print("Shutted down server")