From 44a542b06fde465b332fa3d194d93b7fea907c47 Mon Sep 17 00:00:00 2001 From: froggleston Date: Thu, 23 Jan 2025 15:54:58 +0000 Subject: [PATCH 1/2] Add support to configure requests pool options --- ftui/ftui.py | 18 +++++++++++++++++- ftui/ftui_client.py | 10 +++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ftui/ftui.py b/ftui/ftui.py index 1252629..cd0bea6 100644 --- a/ftui/ftui.py +++ b/ftui/ftui.py @@ -401,6 +401,14 @@ def setup(args): print(__doc__) + pool_connections = 20 + if args.pool_connections: + pool_connections = args.pool_connections + + pool_maxsize = 10 + if args.pool_maxsize: + pool_maxsize = args.pool_maxsize + if args.yaml: for s in args.servers: try: @@ -411,6 +419,8 @@ def setup(args): username=s["username"], password=s["password"], config_path=config, + pool_connections=pool_connections, + pool_maxsize=pool_maxsize, ) client_dict[ftui_client.name] = ftui_client @@ -419,7 +429,11 @@ def setup(args): else: if config is not None: try: - ftui_client = ftuic.FTUIClient(config_path=config) + ftui_client = ftuic.FTUIClient( + config_path=config, + pool_connections=pool_connections, + pool_maxsize=pool_maxsize, + ) client_dict[ftui_client.name] = ftui_client except Exception as e: raise RuntimeError("Cannot create freqtrade client") from e @@ -439,6 +453,8 @@ def main(): parser.add_argument("-v", "--verbose", action="store_true", help="Verbose debugging mode") parser.add_argument("-c", "--config", nargs="?", help="Config to parse") + parser.add_argument("--pool_connections", nargs="?", default=20, help="Number of pool connections") + parser.add_argument("--pool_maxsize", nargs="?", default=10, help="Pool cache maxsize") parser.add_argument( "-y", "--yaml", nargs="?", help="Supply a YAML file instead of command line arguments." diff --git a/ftui/ftui_client.py b/ftui/ftui_client.py index 60d559b..9a10088 100644 --- a/ftui/ftui_client.py +++ b/ftui/ftui_client.py @@ -28,6 +28,8 @@ def __init__( password: Optional[str] = None, *, config_path=None, + pool_connections=20, + pool_maxsize=10, ): self.name = name self.url = url @@ -37,6 +39,8 @@ def __init__( self.config_path = config_path self.rest_client = None self.config = None + self.pool_connections = pool_connections + self.pool_maxsize = pool_maxsize self.prev_closed_trade_count = 0 self.all_closed_trades = [] @@ -65,7 +69,11 @@ def setup_client(self): server_url = f"http://{self.url}:{self.port}" - client = ftrc.FtRestClient(server_url, self.username, self.password) + client = ftrc.FtRestClient(server_url, + self.username, + self.password, + pool_connections=self.pool_connections, + pool_maxsize=self.pool_maxsize) if client is not None: c = client.version() From 37fc2373b739f34e0d4a4bee7062a68c390dcfe9 Mon Sep 17 00:00:00 2001 From: froggleston Date: Thu, 23 Jan 2025 16:06:13 +0000 Subject: [PATCH 2/2] Update readme --- README.md | 22 ++++++++++++++++++++++ example.yaml | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/README.md b/README.md index 0fe6a9c..ecae009 100644 --- a/README.md +++ b/README.md @@ -199,3 +199,25 @@ This README! - When the bot is been running and you put your PC to sleep, the async worker will bug out and intermittently crash the UI. - The Settings screen save functionality is currently disabled. + +### urllib pool connection errors + +When running a larger number of bots within one FTUI instance, you may see urllib/requests +warnings about the pool connections being exhausted: + +`connection pool is full, discarding connection: 127.0.0.1. Connection pools size: 10` + +Raising the pool size limits can help avoid these warnings. + +There are two command line/yaml config options that can be adjusted: + +#### CLI + +`ftui -c config.json --pool_connections 20 --pool_maxsize 15` + +#### YAML config + +```yaml +pool_connections: 20 +pool_maxsize: 15 +``` diff --git a/example.yaml b/example.yaml index 8139ce7..c7d4571 100644 --- a/example.yaml +++ b/example.yaml @@ -19,3 +19,7 @@ servers: port : 8080 debug: False + +# only uncomment these options if you are receiving urllib warnings about connection pool full +# pool_connections: 30 +# pool_maxsize: 20