Skip to content

Commit

Permalink
[Localhost] Create localhost config file
Browse files Browse the repository at this point in the history
  • Loading branch information
JosepSampe committed May 14, 2024
1 parent 5636f53 commit d89a82a
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 43 deletions.
27 changes: 5 additions & 22 deletions lithops/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,8 @@ def default_config(config_file=None, config_data=None, config_overwrite={}, load

if mode == c.LOCALHOST:
logger.debug("Loading compute backend module: localhost")

config_data[backend]['max_workers'] = 1

if 'execution_timeout' not in config_data['lithops']:
config_data['lithops']['execution_timeout'] = c.EXECUTION_TIMEOUT_LOCALHOST_DEFAULT

if 'storage' not in config_data['lithops']:
config_data['lithops']['storage'] = c.LOCALHOST

if 'worker_processes' not in config_data[c.LOCALHOST]:
config_data[backend]['worker_processes'] = c.CPU_COUNT

if 'runtime' not in config_data[c.LOCALHOST]:
config_data[backend]['runtime'] = c.LOCALHOST_RUNTIME_DEFAULT
cb_config = importlib.import_module('lithops.localhost.config')
cb_config.load_config(config_data)

elif mode == c.SERVERLESS:
logger.debug(f"Loading Serverless backend module: {backend}")
Expand All @@ -198,14 +186,9 @@ def default_config(config_file=None, config_data=None, config_overwrite={}, load
sb_config.load_config(config_data)
config_data['lithops']['chunksize'] = 0

if 'monitoring' not in config_data['lithops']:
config_data['lithops']['monitoring'] = c.MONITORING_DEFAULT

if 'monitoring_interval' not in config_data['lithops']:
config_data['lithops']['monitoring_interval'] = c.MONITORING_INTERVAL

if 'execution_timeout' not in config_data['lithops']:
config_data['lithops']['execution_timeout'] = c.EXECUTION_TIMEOUT_DEFAULT
for key in c.LITHOPS_DEFAULT_CONFIG_KEYS:
if key not in config_data['lithops']:
config_data['lithops'][key] = c.LITHOPS_DEFAULT_CONFIG_KEYS[key]

if 'chunksize' not in config_data['lithops']:
config_data['lithops']['chunksize'] = config_data[backend]['worker_processes']
Expand Down
17 changes: 6 additions & 11 deletions lithops/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#

import os
import sys
import tempfile

LOGGER_LEVEL = 'info'
Expand All @@ -35,9 +34,6 @@

MODE_DEFAULT = SERVERLESS

MONITORING_DEFAULT = 'storage'
MONITORING_INTERVAL = 2 # seconds

SERVERLESS_BACKEND_DEFAULT = 'aws_lambda'
STANDALONE_BACKEND_DEFAULT = 'aws_ec2'
STORAGE_BACKEND_DEFAULT = 'aws_s3'
Expand All @@ -47,13 +43,6 @@
LOGS_PREFIX = "lithops.logs"
RUNTIMES_PREFIX = "lithops.runtimes"

EXECUTION_TIMEOUT_DEFAULT = 1800 # seconds
EXECUTION_TIMEOUT_LOCALHOST_DEFAULT = 3600 # seconds

LOCALHOST_RUNTIME_DEFAULT = os.path.basename(sys.executable)
LOCALHOST_SERVICE_IDLE_TIMEOUT = 3
LOCALHOST_SERVICE_CHECK_INTERVAL = 2

MAX_AGG_DATA_SIZE = 4 # 4MiB

WORKER_PROCESSES_DEFAULT = 1
Expand All @@ -80,6 +69,12 @@
CONFIG_FILE = os.path.join(CONFIG_DIR, 'config')
CONFIG_FILE_GLOBAL = os.path.join("/etc", "lithops", "config")

LITHOPS_DEFAULT_CONFIG_KEYS = {
'monitoring': 'storage',
'monitoring_interval': 2,
'execution_timeout': 1800
}

SA_INSTALL_DIR = '/opt/lithops'
SA_SETUP_LOG_FILE = f'{SA_INSTALL_DIR}/setup.log'
SA_SETUP_DONE_FILE = f'{SA_INSTALL_DIR}/setup-done.flag'
Expand Down
1 change: 1 addition & 0 deletions lithops/job/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __call__(self, list_of_objs, include_modules, exclude_modules):

if include_modules is None:
# If include_modules is explicitly set to None, no module is included
logger.debug('Module manager disabled. Modules to transmit: None')
return (strs, mod_paths)

if len(include_modules) == 0:
Expand Down
52 changes: 52 additions & 0 deletions lithops/localhost/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import os
import re
import sys


DEFAULT_CONFIG_KEYS = {
'runtime': os.path.basename(sys.executable),
'worker_processes': os.cpu_count(),
}

LOCALHOST_EXECUTION_TIMEOUT = 3600


def load_config(config_data):

if 'localhost' not in config_data or not config_data['localhost']:
config_data['localhost'] = {}

for key in DEFAULT_CONFIG_KEYS:
if key not in config_data['localhost']:
config_data['localhost'][key] = DEFAULT_CONFIG_KEYS[key]

config_data['localhost']['max_workers'] = 1

if 'execution_timeout' not in config_data['lithops']:
config_data['lithops']['execution_timeout'] = LOCALHOST_EXECUTION_TIMEOUT

if 'storage' not in config_data['lithops']:
config_data['lithops']['storage'] = 'localhost'

windows_path_pattern = re.compile(r'^[A-Za-z]:\\.*$')
runtime_name = config_data['localhost']['runtime']

if runtime_name.startswith(('python', '/')) \
or windows_path_pattern.match(runtime_name) is not None:
config_data['localhost']['environment'] = 'default'
else:
config_data['localhost']['environment'] = 'container'
12 changes: 7 additions & 5 deletions lithops/localhost/v1/localhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

from lithops.version import __version__
from lithops.constants import (
LOCALHOST_RUNTIME_DEFAULT,
TEMP_DIR,
USER_TEMP_DIR,
LITHOPS_TEMP_DIR,
Expand Down Expand Up @@ -59,7 +58,8 @@ class LocalhostHandlerV1:
def __init__(self, config):
logger.debug('Creating Localhost compute client')
self.config = config
self.runtime_name = self.config.get('runtime', LOCALHOST_RUNTIME_DEFAULT)
self.runtime_name = self.config['runtime']
self.environment = self.config['environment']

self.env = None
self.job_queue = queue.Queue()
Expand All @@ -79,9 +79,11 @@ def init(self):
"""
Init tasks for localhost
"""
default_env = self.runtime_name.startswith(('python', '/'))
self.env = DefaultEnvironment(self.config) if default_env \
else ContainerEnvironment(self.config)
if self.environment == 'default':
self.env = DefaultEnvironment(self.config)
else:
self.env = ContainerEnvironment(self.config)

self.env.setup()

def start_manager(self):
Expand Down
12 changes: 7 additions & 5 deletions lithops/localhost/v2/localhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from lithops.version import __version__
from lithops.constants import (
JOBS_DIR,
LOCALHOST_RUNTIME_DEFAULT,
TEMP_DIR,
LITHOPS_TEMP_DIR,
COMPUTE_CLI_MSG,
Expand Down Expand Up @@ -64,7 +63,8 @@ class LocalhostHandlerV2:
def __init__(self, localhost_config):
logger.debug('Creating Localhost compute client')
self.config = localhost_config
self.runtime_name = self.config.get('runtime', LOCALHOST_RUNTIME_DEFAULT)
self.runtime_name = self.config['runtime']
self.environment = self.config['environment']

self.env = None
self.job_manager = None
Expand All @@ -83,9 +83,11 @@ def init(self):
"""
Init tasks for localhost
"""
default_env = self.runtime_name.startswith(('python', '/'))
self.env = DefaultEnvironment(self.config) if default_env \
else ContainerEnvironment(self.config)
if self.environment == 'default':
self.env = DefaultEnvironment(self.config)
else:
self.env = ContainerEnvironment(self.config)

self.env.setup()

def start_manager(self):
Expand Down

0 comments on commit d89a82a

Please sign in to comment.