Unverified Commit c64ca37a authored by Dan Jones's avatar Dan Jones
Browse files

fix: calculate thread workers required for clients

Each client starts 2 threads for the publish and
broadcast flow.
In addition there are 2 threads for the publisher
and config watcher.
2 merge requests!23Resolve "Release v0.1.0",!20Resolve "Use ThreadPoolExecutor in place of ProcessPoolExecutor"
Pipeline #110183 passed with stages
in 58 seconds
......@@ -49,7 +49,7 @@ class ConfigHandler(FileSystemEventHandler):
def update_clients(updated_client_ids):
global RUNNING_CLIENTS
with concurrent.futures.ProcessPoolExecutor() as executor:
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
logging.debug("Old: " + str(RUNNING_CLIENTS))
logging.debug("New: " + str(updated_client_ids))
......@@ -132,13 +132,10 @@ def run_client(client_id, executor):
return running
def main(executor):
def main(clients, executor):
global RUNNING_CLIENTS
logging.info("Starting SOAR bus...")
client_model = ClientModel()
clients = client_model.get()
# publish
thread = executor.submit(publish, "soar-publish", EXCHANGES.get("publish"))
THREADS["soar-publish"] = thread
......@@ -180,7 +177,15 @@ if __name__ == "__main__":
s.close()
try:
with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor:
main(executor)
client_model = ClientModel()
clients = client_model.get()
client_count = len(clients.keys())
thread_count = (client_count * 2) + 2
logging.debug(f"Running {thread_count} workers for {client_count} clients")
with concurrent.futures.ThreadPoolExecutor(
max_workers=thread_count
) as executor:
main(clients, executor)
except KeyboardInterrupt:
executor.shutdown(wait=False)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment