Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 026aec2

Browse files
Changing FLT_PARALELLISM to an integer representing the number of metrics to be trained in parallel
1 parent ef3f9ee commit 026aec2

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

app.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55
from datetime import datetime
66
from multiprocessing import Pool, Process, Queue
7+
from multiprocessing import cpu_count
78
from functools import partial
89
from queue import Empty as EmptyQueueException
910
import tornado.ioloop
@@ -156,16 +157,12 @@ def train_individual_model(predictor_model, initial_run):
156157
def train_model(initial_run=False, data_queue=None):
157158
"""Train the machine learning model."""
158159
global PREDICTOR_MODEL_LIST
159-
if Configuration.parallelism_required:
160-
_LOGGER.info("Training models concurrently using ProcessPool")
161-
training_partial = partial(train_individual_model, initial_run=initial_run)
162-
with Pool() as p:
163-
result = p.map(training_partial, PREDICTOR_MODEL_LIST)
164-
PREDICTOR_MODEL_LIST = result
165-
else:
166-
_LOGGER.info("Training models sequentially")
167-
for predictor_model in PREDICTOR_MODEL_LIST:
168-
model = train_individual_model(predictor_model, initial_run)
160+
parallelism = min(Configuration.parallelism, cpu_count())
161+
_LOGGER.info(f"Training models using ProcessPool of size:{parallelism}")
162+
training_partial = partial(train_individual_model, initial_run=initial_run)
163+
with Pool(parallelism) as p:
164+
result = p.map(training_partial, PREDICTOR_MODEL_LIST)
165+
PREDICTOR_MODEL_LIST = result
169166
data_queue.put(PREDICTOR_MODEL_LIST)
170167

171168

configuration.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class Configuration:
5959
_LOGGER.info("Model retraining interval: %s minutes", retraining_interval_minutes)
6060

6161
# An option for Parallelism.
62-
# Setting FLT_PARALLELISM to True will enable the useage of a process pool
63-
# during training.
64-
parallelism_required = bool(os.getenv("FLT_PARALLELISM", ""))
62+
# An Integer specifying the number of metrics to be trained in parallel.
63+
# Default: 1.
64+
# Note: The upper limit to this will be decided by the number of CPU cores
65+
# available to the container.
66+
parallelism = int(os.getenv("FLT_PARALLELISM", "1"))

0 commit comments

Comments
 (0)