From 2bc5d9c4476231e09052a5aa4e9ec5c25e58e0ab Mon Sep 17 00:00:00 2001 From: Michael Gokhman Date: Mon, 15 May 2023 22:26:53 +0300 Subject: [PATCH] avoid setting socket listen backlog to 1, handle more concurrent conns On MacOS, with listen(1), when starting more than ~3 concurrent clients, new clients often get ECONNREFUSED as it can take few ms for the server to accept() each connection. By not setting the backlog in listen(), it seems to handle even 1000 concurrent connections just fine. Tested also on Linux, where it behaves the same with and without the param. --- pyseidon/__init__.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyseidon/__init__.py b/pyseidon/__init__.py index 286789d..8c93ff5 100644 --- a/pyseidon/__init__.py +++ b/pyseidon/__init__.py @@ -130,7 +130,7 @@ def _listen(self): os.umask(umask) atexit.register(self._remove_socket) - self.sock.listen(1) + self.sock.listen() print('[{}] Pyseidon master booted'.format(os.getpid()), file=sys.stderr) def _accept(self): diff --git a/setup.py b/setup.py index c28fabe..c0b964e 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ def run(self): # Versions should comply with PEP440. For a discussion on single-sourcing # the version across setup.py and the project code, see # https://packaging.python.org/en/latest/single_source_version.html - version='0.1.3', + version='0.1.4', description='A boot-once, run-many-times framework for Python', long_description='Pyseidon allows you to boot a Python master process, and then run clients that are forked directly from the master. This is particularly useful for completing a slow data-loading process once and then running many experiments.',