Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update worker images to optimize IO performance using local data #675

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c14cb26
Update DataRequirement with needs_data_local attr.
robertbartel Jul 5, 2024
36338d0
Setting needs_data_local when fulfilled_by is set.
robertbartel Jul 5, 2024
4507699
Update, document ngen image custom dir structure.
robertbartel Jul 5, 2024
0916112
Update Launcher for using local data volumes.
robertbartel Jul 5, 2024
0a9ce77
Update ngen-related images to have mc client.
robertbartel Jul 12, 2024
95aa90e
Update worker Python functions to make data local.
robertbartel Jul 12, 2024
1f50ce3
Update worker entrypoints for local data.
robertbartel Jul 12, 2024
b44e50a
Fix fast dev update script GUI handling.
robertbartel Aug 15, 2024
304d953
Move call to make_data_local in entrypoints.
robertbartel Aug 15, 2024
7f9f972
Fix issues w/ use of separate cluster/local data.
robertbartel Aug 15, 2024
2b0f4bd
Fix more issues with py_funcs functions.
robertbartel Aug 16, 2024
8cad34e
Update worker entrypoints for permissions issues.
robertbartel Aug 16, 2024
5b5dfa0
Bump core version to 0.20.0.
robertbartel Aug 16, 2024
a6db862
Update scheduler dep to latest core.
robertbartel Aug 16, 2024
a930cf5
Bump scheduler version to 0.14.0.
robertbartel Aug 16, 2024
724120a
Update dataservice internal deps to latest.
robertbartel Aug 16, 2024
91204ca
Bump dataservice version to 0.13.0.
robertbartel Aug 16, 2024
d0534f8
Update schedulerservice internal deps to latest.
robertbartel Aug 16, 2024
107cae8
Bump schedulerservice version to 0.13.0.
robertbartel Aug 16, 2024
9161c38
Update requestsservice to latest core dep.
robertbartel Aug 16, 2024
4d593ee
Bump requestservice version to 0.12.0.
robertbartel Aug 16, 2024
ea1f092
Update partitionerservice internal deps to latest.
robertbartel Aug 16, 2024
0b2563c
Bump partitionerservice version to 0.3.0.
robertbartel Aug 16, 2024
f85ea7b
Account for platform in image mc client download.
robertbartel Aug 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions docker/main/ngen/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ RUN dnf update -y \
&& mkdir -p ${SSHDIR} \
# Create DMOD-specific directory structure \
&& mkdir -p /dmod && chown ${USER} /dmod \
&& mkdir -p /dmod/local_volumes && chown ${USER} /dmod/local_volumes \
&& mkdir -p /dmod/cluster_volumes && chown ${USER} /dmod/cluster_volumes \
&& mkdir -p /dmod/datasets && chown ${USER} /dmod/datasets \
#&& mkdir -p /dmod/shared_libs && chown ${USER} /dmod/shared_libs \
&& mkdir -p /dmod/lib && chown ${USER} /dmod/lib \
Expand Down Expand Up @@ -906,8 +908,16 @@ COPY --chown=${USER} --from=build_bmi_sac_sma /dmod/ /dmod/
COPY --chown=${USER} --from=build_bmi_snow_17 /dmod/ /dmod/

USER root
# Update path and make sure dataset directory is there
RUN echo "export PATH=${PATH}" >> /etc/profile \
# TODO: (later) consider something like this in the future (at least optionally) when downloading the mc client below:
# ARG MINIO_CLIENT_RELEASE="RELEASE.2024-07-08T20-59-24Z"
# ...
# https://dl.min.io/client/mc/release/linux-amd64/archive/mc.${MINIO_CLIENT_RELEASE}

# Setup minio client; also update path and make sure dataset directory is there
RUN curl -L -o /dmod/bin/mc https://dl.min.io/client/mc/release/linux-amd64/mc \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RUN curl -L -o /dmod/bin/mc https://dl.min.io/client/mc/release/linux-amd64/mc \
RUN ARCHITECTURE=`echo $(uname -s)-$(uname -m) | tr '[:upper:]' '[:lower:]'`; \
curl -L -o /dmod/bin/mc https://dl.min.io/client/mc/release/${ARCHITECTURE}/mc \

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm ... good catch, but the suggestion won't work as needed with Linux on an Intel machine (it produces linux-x86_64 instead of linux-amd64). I will make an adjustment, but I'll need to think more about exactly how.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That wasn't the only case that would have been a problem, but I've made a change now that I think should catch the platform types we can reasonably expect that would need to be transformed to something else for purposes of that URL, and done the adjustment accordingly.

&& chmod +x /dmod/bin/mc \
&& mkdir /dmod/.mc \
&& echo "export PATH=${PATH}" >> /etc/profile \
aaraney marked this conversation as resolved.
Show resolved Hide resolved
&& sed -i "s/PasswordAuthentication yes/#PasswordAuthentication yes/g" /etc/ssh/sshd_config \
&& sed -i "s/PermitRootLogin yes/PermitRootLogin no/g" /etc/ssh/sshd_config \
&& sed -i "s/#ClientAliveInterval.*/ClientAliveInterval 60/" /etc/ssh/sshd_config \
Expand All @@ -922,9 +932,9 @@ COPY --chown=${USER} --chmod=744 py_funcs.py /dmod/bin/py_funcs

ENV HYDRA_PROXY_RETRY_COUNT=5

# Change permissions for entrypoint and make sure dataset volume mount parent directories exists
# Change permissions for entrypoint and make sure data volume mount and dataset symlink parent directories exists
RUN chmod +x ${WORKDIR}/entrypoint.sh \
&& for d in ${DATASET_DIRECTORIES}; do mkdir -p /dmod/datasets/${d}; done \
&& for p in datasets local_volumes cluster_volumes; do for d in ${DATASET_DIRECTORIES}; do mkdir -p /dmod/${p}/${d}; done; done \
&& pushd /dmod/bin \
# NOTE use of `ln -sf`. \
&& ( ( stat ngen-parallel && ln -sf ngen-parallel ngen ) || ( stat ngen-serial && ln -sf ngen-serial ngen ) ) \
Expand Down
100 changes: 100 additions & 0 deletions docker/main/ngen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# About

<b style="color: red">TODO:</b>More details about the image.

<b style="color: red">TODO:</b>Once implemented, details about available image variants.

<b style="color: red">TODO:</b>Once implemented, details about extending the image with additional modules.

# Image `/dmod/` Directory

## TL;DR - Directories for Configs

Several important pieces details if manually constructing configurations to upload into DMOD datasets:
* Compiled BMI module libraries will be in `/dmod/shared_libs/`
* Data used during job execution (e.g., forcings, configs) will (or at least appear) under `/dmod/datasets/`
* Paths descend first by data type, then by dataset name
* E.g., `/dmod/datasets/config/vpu-01-bmi-config-dataset-01/NoahOWP_cat-9999.namelist`
* E.g., `/dmod/datasets/forcing/vpu-01-forcings-dataset-01/cat-1000.csv`

## Directory Structure Details

Several important directories exist in the worker images' file system under the `/dmod/` directory, which are important to the operation of job worker containers.

## Static Directories

Several important DMOD-specific directories in the worker images are static. They contain things either created or copied in during the image build. These are standard/general things, available in advance, that need to be in fixed, well-defined locations. Examples are the ngen executables, Python packages, and compiled BMI modules.

### `/dmod/bin/`
* Directory containing custom executables and scripts
* Location for parallel and serial ngen executables, plus the `ngen` symlink that points to one of them (dependent on build config, but parallel by default)
* Path appended to `PATH` in environment

### `/dmod/bmi_module_data/`
* Directory containing any necessary generic per-BMI-module data files
* `/dmod/bmi_module_data/noah_owp/parameters/`
* Nested directory containing parameters files for Noah-OWP-Modular
* `/dmod/bmi_module_data/lgar-c/data/data/`
* Nested directory for generic LGAR data files

### `/dmod/shared_libs/`
* Directories containing libraries built during intermediate steps of the image building process that will be needed for worker container execution
* E.g., Compiled BMI module shared libraries, like `libcfebmi.so` for CFE
* Path is appended to `LD_LIBRARY_PATH`

### `/dmod/venv/`
* Directory for Python virtual environment loaded by worker for execution

## Dynamic Directories

Others important DMOD-specific directories in the worker images are dynamic. There is a higher level baseline directory structure that is created by the image build, but the nested contents, which are what is most important to job execution, is put into place when the job worker container is created. Examples of this are configs and forcings.

### `/dmod/datasets/`
* This contains the paths from which jobs should read their necessary data, and which config files should reference
* Contains subdirectories for different dataset types
* `config`, `forcing`, `hydrofabric`, `observation`, `output` (e.g., `/dmod/datasets/forcing/`)
* Each subdirectory may contain further "subdirectories" (really symlinks) containing different data needed for the current job
* E.g., `/dmod/datasets/config/vpu-01-bmi-config-dataset-01/`
* Has data from `vpu-01-bmi-config-dataset-01` dataset
* Data subdirectories are actually symlinks to an analogous mounted path for either a [cluster volume](#dmodcluster_volumes) or [local volume](#dmodlocal_volumes)
* If a dataset can be mounted as a cluster volume and used directly by the job without local copying, the symlink will be to an analogous cluster volume
* e.g., `/dmod/datasets/config/real-cfg-ds-01/ -> /dmod/cluster_volumes/config/real-cfg-ds-01/`
* If data from a dataset needs to be local or preprocessed in some way by the worker before use, it will be prepared in a local volume, and a symlink here will point to that
* e.g., `/dmod/datasets/config/vpu-01-bmi-config-dataset-01/ -> /dmod/local_volumes/config/vpu-01-bmi-config-dataset-01/`


### `/dmod/cluster_volumes/`
* First level subdirectories correspond to DMOD dataset types, as with `/dmod/datasets/`
* e.g., `/dmod/cluster_volumes/config/`
* Second-level subdirectories are mounted Docker cluster volumes that are, in some way or another, synced across all physical nodes of the deployment
* e.g., `/dmod/cluster_volumes/config/vpu-01-bmi-config-dataset-01/`
* Automatic synchronization at the DMOD deployment level
* All workers for a job see exactly the same set of mounted volumes here
* All workers on all physical nodes see the same contents in each mounted volume directory
* Writes done on any worker to a file under a volume subdirectory are seen (essentially) immediately by workers on **all** physical nodes
* Common scenario (typical case at the time of this writing) for these are DMOD dataset volumes
* A dataset is directly mounted as Docker volume via some specialized storage driver (e.g., `s3fs`)
* The contents of the dataset can then be interacted with by the worker as if they were a regular file system (even if they aren't)
* The mount directory name matches the DMOD dataset name
* E.g., the `vpu-01-bmi-config-dataset-01` dataset would be at `/dmod/cluster_volumes/config/vpu-01-bmi-config-dataset-01/`

*** TODO: set up to link or do pre-processing/extraction/etc. as needed on startup ***
*** TODO: have indication that be that there exists a directory already for the dataset under `/dmod/datasets/`
TODO: have this be for local Docker volumes that are just on individual hosts that we want to keep synced

### `/dmod/local_volumes/`
* First level subdirectories correspond to DMOD dataset types, as with `/dmod/datasets/`
* e.g., `/dmod/local_volumes/config/`
* Second-level subdirectories are mounted Docker local volumes
* e.g., `/dmod/local_volumes/config/vpu-01-bmi-config-dataset-01/`
* These local volumes are job-wide but host-specific
* All workers for a job see exactly the same set of mounted volumes here
* All workers on the same physical nodes are using the same local volume on that physical host
* Workers on different physical nodes are using different volumes
* This means some coordinated synchronization needs to be performed by a subset of worker
* The use case is for any data that needs to be local on the container/host (generally for performance reasons) to be copied/extracted to a subdirectory here, typically from an analogous subdirectory under `/dmod/cluster_volumes/`
* This at least reduces copying somewhat by allowing workers on same node to share the same local volume

TODO: make scheduler create these per dataset on the fly at job time and mount them in (and have something to clean them up, but maybe not right away)
TODO: make one worker per physical host extract data when needed from archives in analogous cluster volumes

57 changes: 43 additions & 14 deletions docker/main/ngen/ngen_cal_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ while [ ${#} -gt 0 ]; do
declare -x CALIBRATION_CONFIG_BASENAME="${2:?}"
shift
;;
--primary-workers)
declare -x PRIMARY_WORKERS="${2:?}"
shift
;;
esac
shift
done
Expand All @@ -48,9 +52,15 @@ declare -x JOB_OUTPUT_WRITE_DIR="/tmp/job_output"

# Get some universally applicable functions and constants
source ./funcs.sh
init_script_mpi_vars

if [ "$(whoami)" != "${MPI_USER:?MPI user not defined}" ]; then
# Run make_data_local Python functions to make necessary data local
# Called for every worker, but Python code will make sure only one worker per node makes a call that has effect
py_funcs make_data_local ${WORKER_INDEX:-0} ${PRIMARY_WORKERS:-0}
fi

ngen_sanity_checks_and_derived_init
init_script_mpi_vars
init_ngen_executable_paths

# Move to the output write directory
Expand All @@ -62,6 +72,7 @@ cd ${JOB_OUTPUT_WRITE_DIR}
#Needed for routing
if [ ! -e /dmod/datasets/linked_job_output ]; then
ln -s ${JOB_OUTPUT_WRITE_DIR} /dmod/datasets/linked_job_output
chown -R ${MPI_USER}:${MPI_USER} /dmod/datasets/linked_job_output
fi

start_calibration() {
Expand Down Expand Up @@ -106,39 +117,57 @@ if [ "${WORKER_INDEX:-0}" = "0" ]; then
if [ "$(whoami)" = "${MPI_USER:?MPI user not defined}" ]; then
# This will only have an effect when running with multiple MPI nodes, so its safe to have even in serial exec
trap close_remote_workers EXIT
# Have "main" (potentially only) worker copy config files to output dataset for record keeping
# TODO: (later) in ngen and ngen-cal entrypoints, consider adding controls for whether this is done or a simpler
# TODO: 'cp' call, based on whether we write directly to output dataset dir or some other output write dir
# Do a dry run first to sanity check directory and fail if needed before backgrounding process
py_funcs tar_and_copy --dry-run --compress ${CONFIG_DATASET_DIR:?Config dataset directory not defined} config_dataset.tgz ${OUTPUT_DATASET_DIR:?}
# Then actually run the archive and copy function in the background
py_funcs tar_and_copy --compress ${CONFIG_DATASET_DIR:?} config_dataset.tgz ${OUTPUT_DATASET_DIR:?} &
_CONFIG_COPY_PROC=$!
# If there is partitioning, which implies multi-processing job ...
if [ -n "${PARTITION_DATASET_DIR:-}" ]; then
# Include partition config dataset too if appropriate
cp -a ${PARTITION_DATASET_DIR}/. ${OUTPUT_DATASET_DIR:?}
fi

# Run the same function to execute ngen_cal (it's config will handle whether MPI is used internally)
start_calibration
# Remember: all these things are done as the root user on worker 0
else
# Start SSHD on the main worker if have an MPI job
if [ -n "${PARTITION_DATASET_DIR:-}" ]; then
# Include partition config dataset too if appropriate, though for simplicity, just copy directly
cp -a ${PARTITION_DATASET_DIR}/. ${OUTPUT_DATASET_DIR:?}

echo "$(print_date) Starting SSH daemon on main worker"
/usr/sbin/sshd -D &
_SSH_D_PID="$!"

trap cleanup_sshuser_exit EXIT
fi

# Have "main" (potentially only) worker copy config files to output dataset for record keeping
# TODO: (later) in ngen and ngen-cal entrypoints, consider adding controls for whether this is done or a simpler
# TODO: 'cp' call, based on whether we write directly to output dataset dir or some other output write dir
# Do a dry run first to sanity check directory and fail if needed before backgrounding process
py_funcs tar_and_copy --dry-run --compress config_dataset.tgz ${CONFIG_DATASET_DIR:?Config dataset directory not defined} ${OUTPUT_DATASET_DIR:?}
_R_DRY=${?}
if [ ${_R_DRY} -ne 0 ]; then
echo "$(print_date) Job exec failed due to issue with copying configs to output (code ${_R_DRY})"
exit ${_R_DRY}
fi
# Then actually run the archive and copy function in the background
py_funcs tar_and_copy --compress config_dataset.tgz ${CONFIG_DATASET_DIR:?} ${OUTPUT_DATASET_DIR:?} &
_CONFIG_COPY_PROC=$!

# Make sure we run ngen/ngen-cal as our MPI_USER
echo "$(print_date) Running exec script as '${MPI_USER:?}'"
# Do this by just re-running this script with the same args, but as the other user
# The script will modify its behavior as needed depending on current user (see associated "if" for this "else")
_EXEC_STRING="${0} ${@}"
su ${MPI_USER:?} --session-command "${_EXEC_STRING}"
#time su ${MPI_USER:?} --session-command "${_EXEC_STRING}"

# TODO: (later) in ngen and ngen-cal entrypoints, add controls for whether this is done base on whether we
# TODO: are writing directly to output dataset dir or some other output write dir; this will be
# TODO: important once netcdf output works
# Then wait at this point (if necessary) for our background config copy to avoid taxing things
echo "$(print_date) Waiting for compression and copying of configuration files to output dataset"
wait ${_CONFIG_COPY_PROC:-}
_R_CONFIG_COPY=${?}
if [ ${_R_CONFIG_COPY} -eq 0 ]; then
echo "$(print_date) Compression/copying of config data to output dataset complete"
else
echo "$(print_date) Copying of config data to output dataset exited with error code: ${_R_CONFIG_COPY}"
fi
fi
else
run_secondary_mpi_ssh_worker_node
Expand Down
Loading
Loading