diff options
| author | UltraQbik <no1skill@yandex.ru> | 2024-08-26 04:15:08 +0300 |
|---|---|---|
| committer | UltraQbik <no1skill@yandex.ru> | 2024-08-26 04:15:08 +0300 |
| commit | 5ec59e4b5e2082fb52649893baa0cc0fd310f80b (patch) | |
| tree | a6674033008d127a2d208f4ac81c3080d34697f2 | |
| parent | f58af3cb3a3e826d21fd521fe5a55b993d8a348e (diff) | |
| download | httpy-5ec59e4b5e2082fb52649893baa0cc0fd310f80b.tar.gz httpy-5ec59e4b5e2082fb52649893baa0cc0fd310f80b.zip | |
Add semaphore
Use semaphore to limit core usage slightly (maybe) Also changed default configs a bit
| -rw-r--r-- | main.py | 7 | ||||
| -rw-r--r-- | src/config.py | 3 |
2 files changed, 7 insertions, 3 deletions
diff --git a/main.py b/main.py index f03b354..574c58b 100644 --- a/main.py +++ b/main.py @@ -93,8 +93,9 @@ class HTTPServer: self.buf_len: int = packet_size self.port: int = port - # client thread list and server thread + # client thread list self.client_threads: list[threading.Thread] = [] + self.semaphore: threading.Semaphore = threading.Semaphore(CLIENT_MAX_PROCESS) # add signaling self.stop_event = threading.Event() @@ -141,6 +142,7 @@ class HTTPServer: :param client: client ssl socket """ + self.semaphore.acquire() try: request = self._recv_request(client) if request is not None: @@ -159,6 +161,7 @@ class HTTPServer: # Remove self from thread list and close the connection self.client_threads.remove(threading.current_thread()) + self.semaphore.release() client.close() def _client_request_handler(self, client: usocket, request: Request): @@ -289,7 +292,7 @@ class HTTPServer: def main(): - init_path_map(True) + init_path_map(verbose=True) server = HTTPServer(port=13700) server.start() diff --git a/src/config.py b/src/config.py index 18c136b..e72477e 100644 --- a/src/config.py +++ b/src/config.py @@ -1,7 +1,8 @@ # generic BUFFER_LENGTH = 65536 # 64 KiB BUFFER_MAX_SIZE = 2**30 * 0.5 # 512 MiB -CLIENT_MAX_AMOUNT = 64 +CLIENT_MAX_AMOUNT = 512 # max requests at once, after which the connections are dropped +CLIENT_MAX_PROCESS = 32 # max processing threads at once # API API_FILE_RANDOM_MIN_SIZE_LIMIT = 1 # 1 byte |