Skip to content

Commit

Permalink
Preloading models before starting server
Browse files Browse the repository at this point in the history
Using command line arguments load specific projects or all project in to the memory before starting the server
  • Loading branch information
RitwikGopi committed Apr 19, 2018
1 parent 1613f37 commit 706bbde
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
16 changes: 10 additions & 6 deletions rasa_nlu/data_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ def __init__(self,
emulation_mode=None,
remote_storage=None,
component_builder=None,
load_all=False):
logger.debug('here2')
pre_load=[]):
self._training_processes = max(max_training_processes, 1)
self.responses = self._create_query_logger(response_log)
self.project_dir = config.make_path_absolute(project_dir)
Expand All @@ -109,9 +108,9 @@ def __init__(self,
self.project_store = self._create_project_store(project_dir)
self.pool = ProcessPool(self._training_processes)
logger.debug('loading all2')
if (load_all):
logger.debug('loading all')
self._load_all()
if (pre_load):
logger.debug('Preloading....')
self._pre_load(pre_load)

def __del__(self):
"""Terminates workers pool processes"""
Expand Down Expand Up @@ -175,8 +174,13 @@ def _create_project_store(self, project_dir):
remote_storage=self.remote_storage)
return project_store

def _load_all(self):
def _pre_load(self, projects):
if 'all' in projects:
projects = self.project_store.keys()
logger.debug("loading %s", projects)
for project in self.project_store:
if project not in projects:
continue
logger.debug('Loading %s.....', project)
out = self.project_store[project].load_model()
if out:
Expand Down
12 changes: 6 additions & 6 deletions rasa_nlu/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ def create_argument_parser():
type=int,
default=5000,
help='port on which to run server')
parser.add_argument('-a', '--auto_load',
type=bool,
default=False,
choices=[True, False],
help='Load all models automatically')
parser.add_argument('-p', '--pre_load',
nargs='*',
default=[],
help='Load all models before starting the server')
parser.add_argument('-t', '--token',
help="auth token. If set, reject requests which don't "
"provide this token as a query parameter")
Expand Down Expand Up @@ -365,13 +364,14 @@ def unload_model(self, request):
cmdline_args = create_argument_parser().parse_args()

utils.configure_colored_logging(cmdline_args.loglevel)
logger.debug(cmdline_args)

router = DataRouter(cmdline_args.path,
cmdline_args.max_training_processes,
cmdline_args.response_log,
cmdline_args.emulate,
cmdline_args.storage,
load_all=cmdline_args.auto_load)
pre_load=cmdline_args.pre_load)
rasa = RasaNLU(
router,
cmdline_args.loglevel,
Expand Down

0 comments on commit 706bbde

Please sign in to comment.