-
Notifications
You must be signed in to change notification settings - Fork 280
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
Add SIMD support for k-NN in all distributions startup scripts #4407
Closed
peterzhuamazon
wants to merge
4
commits into
opensearch-project:main
from
peterzhuamazon:knn-simd-2.12
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
133 changes: 133 additions & 0 deletions
133
docker/release/config/opensearch/opensearch-docker-entrypoint-2.x.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#!/bin/bash | ||
|
||
# Copyright OpenSearch Contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# This script specify the entrypoint startup actions for opensearch | ||
# It will start both opensearch and performance analyzer plugin cli | ||
# If either process failed, the entire docker container will be removed | ||
# in favor of a newly started container | ||
|
||
# Export OpenSearch Home | ||
export OPENSEARCH_HOME=/usr/share/opensearch | ||
export OPENSEARCH_PATH_CONF=$OPENSEARCH_HOME/config | ||
|
||
# The virtual file /proc/self/cgroup should list the current cgroup | ||
# membership. For each hierarchy, you can follow the cgroup path from | ||
# this file to the cgroup filesystem (usually /sys/fs/cgroup/) and | ||
# introspect the statistics for the cgroup for the given | ||
# hierarchy. Alas, Docker breaks this by mounting the container | ||
# statistics at the root while leaving the cgroup paths as the actual | ||
# paths. Therefore, OpenSearch provides a mechanism to override | ||
# reading the cgroup path from /proc/self/cgroup and instead uses the | ||
# cgroup path defined the JVM system property | ||
# opensearch.cgroups.hierarchy.override. Therefore, we set this value here so | ||
# that cgroup statistics are available for the container this process | ||
# will run in. | ||
export OPENSEARCH_JAVA_OPTS="-Dopensearch.cgroups.hierarchy.override=/ $OPENSEARCH_JAVA_OPTS" | ||
|
||
# Security Plugin | ||
function setupSecurityPlugin { | ||
SECURITY_PLUGIN="opensearch-security" | ||
|
||
if [ -d "$OPENSEARCH_HOME/plugins/$SECURITY_PLUGIN" ]; then | ||
if [ "$DISABLE_INSTALL_DEMO_CONFIG" = "true" ]; then | ||
echo "Disabling execution of install_demo_configuration.sh for OpenSearch Security Plugin" | ||
else | ||
echo -e "Enabling execution of install_demo_configuration.sh for OpenSearch Security Plugin \nOpenSearch 2.12.0 onwards, the OpenSearch Security Plugin a change that requires an initial password for 'admin' user. \nPlease define an environment variable 'OPENSEARCH_INITIAL_ADMIN_PASSWORD' with a strong password string. \nIf a password is not provided, the setup will quit. \n For more details, please visit: https://opensearch.org/docs/latest/install-and-configure/install-opensearch/docker/" | ||
bash $OPENSEARCH_HOME/plugins/$SECURITY_PLUGIN/tools/install_demo_configuration.sh -y -i -s || exit 1 | ||
fi | ||
|
||
if [ "$DISABLE_SECURITY_PLUGIN" = "true" ]; then | ||
echo "Disabling OpenSearch Security Plugin" | ||
opensearch_opt="-Eplugins.security.disabled=true" | ||
opensearch_opts+=("${opensearch_opt}") | ||
else | ||
echo "Enabling OpenSearch Security Plugin" | ||
fi | ||
else | ||
echo "OpenSearch Security Plugin does not exist, disable by default" | ||
fi | ||
} | ||
|
||
# Performance Analyzer Plugin | ||
function setupPerformanceAnalyzerPlugin { | ||
PERFORMANCE_ANALYZER_PLUGIN="opensearch-performance-analyzer" | ||
if [ -d "$OPENSEARCH_HOME/plugins/$PERFORMANCE_ANALYZER_PLUGIN" ]; then | ||
if [ "$DISABLE_PERFORMANCE_ANALYZER_AGENT_CLI" = "true" ]; then | ||
echo "Disabling execution of $OPENSEARCH_HOME/bin/$PERFORMANCE_ANALYZER_PLUGIN/performance-analyzer-agent-cli for OpenSearch Performance Analyzer Plugin" | ||
else | ||
echo "Enabling execution of OPENSEARCH_HOME/bin/$PERFORMANCE_ANALYZER_PLUGIN/performance-analyzer-agent-cli for OpenSearch Performance Analyzer Plugin" | ||
$OPENSEARCH_HOME/bin/opensearch-performance-analyzer/performance-analyzer-agent-cli > $OPENSEARCH_HOME/logs/PerformanceAnalyzer.log 2>&1 & disown | ||
fi | ||
else | ||
echo "OpenSearch Performance Analyzer Plugin does not exist, disable by default" | ||
fi | ||
} | ||
|
||
# Setup k-NN Plugin Lib Loading Path | ||
# This is required for OpenSearch 2.12 and above | ||
# As SIMD is added to the k-NN Plugin Faiss Lib: https://github.com/opensearch-project/k-NN/issues/1138 | ||
function setupKNNPlugin { | ||
if [ "$KNN_SIMD_ENABLED" = "true" ]; | ||
KNN_LIB_DIR=$OPENSEARCH_HOME/plugins/opensearch-knn/lib_simd | ||
echo "Enable SIMD Feature for k-NN Plugin" | ||
else | ||
KNN_LIB_DIR=$OPENSEARCH_HOME/plugins/opensearch-knn/lib | ||
echo "Disable SIMD Feature for k-NN Plugin" | ||
fi | ||
|
||
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$KNN_LIB_DIR" | ||
} | ||
|
||
# Start up the opensearch and performance analyzer agent processes. | ||
# When either of them halts, this script exits, or we receive a SIGTERM or SIGINT signal then we want to kill both these processes. | ||
function runOpensearch { | ||
# Files created by OpenSearch should always be group writable too | ||
umask 0002 | ||
|
||
if [[ "$(id -u)" == "0" ]]; then | ||
echo "OpenSearch cannot run as root. Please start your container as another user." | ||
exit 1 | ||
fi | ||
|
||
# Parse Docker env vars to customize OpenSearch | ||
# | ||
# e.g. Setting the env var cluster.name=testcluster | ||
# will cause OpenSearch to be invoked with -Ecluster.name=testcluster | ||
opensearch_opts=() | ||
while IFS='=' read -r envvar_key envvar_value | ||
do | ||
# OpenSearch settings need to have at least two dot separated lowercase | ||
# words, e.g. `cluster.name`, except for `processors` which we handle | ||
# specially | ||
if [[ "$envvar_key" =~ ^[a-z0-9_]+\.[a-z0-9_]+ || "$envvar_key" == "processors" ]]; then | ||
if [[ ! -z $envvar_value ]]; then | ||
opensearch_opt="-E${envvar_key}=${envvar_value}" | ||
opensearch_opts+=("${opensearch_opt}") | ||
fi | ||
fi | ||
done < <(env) | ||
|
||
setupSecurityPlugin | ||
setupPerformanceAnalyzerPlugin | ||
setupKNNPlugin | ||
|
||
# Start opensearch | ||
"$@" "${opensearch_opts[@]}" | ||
|
||
} | ||
|
||
# Prepend "opensearch" command if no argument was provided or if the first | ||
# argument looks like a flag (i.e. starts with a dash). | ||
if [ $# -eq 0 ] || [ "${1:0:1}" = '-' ]; then | ||
set -- opensearch "$@" | ||
fi | ||
|
||
if [ "$1" = "opensearch" ]; then | ||
# If the first argument is opensearch, then run the setup script. | ||
runOpensearch "$@" | ||
else | ||
# Otherwise, just exec the command. | ||
exec "$@" | ||
fi |
133 changes: 133 additions & 0 deletions
133
docker/release/config/opensearch/opensearch-docker-entrypoint-default.x.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#!/bin/bash | ||
|
||
# Copyright OpenSearch Contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# This script specify the entrypoint startup actions for opensearch | ||
# It will start both opensearch and performance analyzer plugin cli | ||
# If either process failed, the entire docker container will be removed | ||
# in favor of a newly started container | ||
|
||
# Export OpenSearch Home | ||
export OPENSEARCH_HOME=/usr/share/opensearch | ||
export OPENSEARCH_PATH_CONF=$OPENSEARCH_HOME/config | ||
|
||
# The virtual file /proc/self/cgroup should list the current cgroup | ||
# membership. For each hierarchy, you can follow the cgroup path from | ||
# this file to the cgroup filesystem (usually /sys/fs/cgroup/) and | ||
# introspect the statistics for the cgroup for the given | ||
# hierarchy. Alas, Docker breaks this by mounting the container | ||
# statistics at the root while leaving the cgroup paths as the actual | ||
# paths. Therefore, OpenSearch provides a mechanism to override | ||
# reading the cgroup path from /proc/self/cgroup and instead uses the | ||
# cgroup path defined the JVM system property | ||
# opensearch.cgroups.hierarchy.override. Therefore, we set this value here so | ||
# that cgroup statistics are available for the container this process | ||
# will run in. | ||
export OPENSEARCH_JAVA_OPTS="-Dopensearch.cgroups.hierarchy.override=/ $OPENSEARCH_JAVA_OPTS" | ||
|
||
# Security Plugin | ||
function setupSecurityPlugin { | ||
SECURITY_PLUGIN="opensearch-security" | ||
|
||
if [ -d "$OPENSEARCH_HOME/plugins/$SECURITY_PLUGIN" ]; then | ||
if [ "$DISABLE_INSTALL_DEMO_CONFIG" = "true" ]; then | ||
echo "Disabling execution of install_demo_configuration.sh for OpenSearch Security Plugin" | ||
else | ||
echo -e "Enabling execution of install_demo_configuration.sh for OpenSearch Security Plugin \nOpenSearch 2.12.0 onwards, the OpenSearch Security Plugin a change that requires an initial password for 'admin' user. \nPlease define an environment variable 'OPENSEARCH_INITIAL_ADMIN_PASSWORD' with a strong password string. \nIf a password is not provided, the setup will quit. \n For more details, please visit: https://opensearch.org/docs/latest/install-and-configure/install-opensearch/docker/" | ||
bash $OPENSEARCH_HOME/plugins/$SECURITY_PLUGIN/tools/install_demo_configuration.sh -y -i -s || exit 1 | ||
fi | ||
|
||
if [ "$DISABLE_SECURITY_PLUGIN" = "true" ]; then | ||
echo "Disabling OpenSearch Security Plugin" | ||
opensearch_opt="-Eplugins.security.disabled=true" | ||
opensearch_opts+=("${opensearch_opt}") | ||
else | ||
echo "Enabling OpenSearch Security Plugin" | ||
fi | ||
else | ||
echo "OpenSearch Security Plugin does not exist, disable by default" | ||
fi | ||
} | ||
|
||
# Performance Analyzer Plugin | ||
function setupPerformanceAnalyzerPlugin { | ||
PERFORMANCE_ANALYZER_PLUGIN="opensearch-performance-analyzer" | ||
if [ -d "$OPENSEARCH_HOME/plugins/$PERFORMANCE_ANALYZER_PLUGIN" ]; then | ||
if [ "$DISABLE_PERFORMANCE_ANALYZER_AGENT_CLI" = "true" ]; then | ||
echo "Disabling execution of $OPENSEARCH_HOME/bin/$PERFORMANCE_ANALYZER_PLUGIN/performance-analyzer-agent-cli for OpenSearch Performance Analyzer Plugin" | ||
else | ||
echo "Enabling execution of OPENSEARCH_HOME/bin/$PERFORMANCE_ANALYZER_PLUGIN/performance-analyzer-agent-cli for OpenSearch Performance Analyzer Plugin" | ||
$OPENSEARCH_HOME/bin/opensearch-performance-analyzer/performance-analyzer-agent-cli > $OPENSEARCH_HOME/logs/PerformanceAnalyzer.log 2>&1 & disown | ||
fi | ||
else | ||
echo "OpenSearch Performance Analyzer Plugin does not exist, disable by default" | ||
fi | ||
} | ||
|
||
# Setup k-NN Plugin Lib Loading Path | ||
# This is required for OpenSearch 2.12 and above | ||
# As SIMD is added to the k-NN Plugin Faiss Lib: https://github.com/opensearch-project/k-NN/issues/1138 | ||
function setupKNNPlugin { | ||
if [ "$KNN_SIMD_ENABLED" = "true" ]; | ||
KNN_LIB_DIR=$OPENSEARCH_HOME/plugins/opensearch-knn/lib_simd | ||
echo "Enable SIMD Feature for k-NN Plugin" | ||
else | ||
KNN_LIB_DIR=$OPENSEARCH_HOME/plugins/opensearch-knn/lib | ||
echo "Disable SIMD Feature for k-NN Plugin" | ||
fi | ||
|
||
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$KNN_LIB_DIR" | ||
} | ||
|
||
# Start up the opensearch and performance analyzer agent processes. | ||
# When either of them halts, this script exits, or we receive a SIGTERM or SIGINT signal then we want to kill both these processes. | ||
function runOpensearch { | ||
# Files created by OpenSearch should always be group writable too | ||
umask 0002 | ||
|
||
if [[ "$(id -u)" == "0" ]]; then | ||
echo "OpenSearch cannot run as root. Please start your container as another user." | ||
exit 1 | ||
fi | ||
|
||
# Parse Docker env vars to customize OpenSearch | ||
# | ||
# e.g. Setting the env var cluster.name=testcluster | ||
# will cause OpenSearch to be invoked with -Ecluster.name=testcluster | ||
opensearch_opts=() | ||
while IFS='=' read -r envvar_key envvar_value | ||
do | ||
# OpenSearch settings need to have at least two dot separated lowercase | ||
# words, e.g. `cluster.name`, except for `processors` which we handle | ||
# specially | ||
if [[ "$envvar_key" =~ ^[a-z0-9_]+\.[a-z0-9_]+ || "$envvar_key" == "processors" ]]; then | ||
if [[ ! -z $envvar_value ]]; then | ||
opensearch_opt="-E${envvar_key}=${envvar_value}" | ||
opensearch_opts+=("${opensearch_opt}") | ||
fi | ||
fi | ||
done < <(env) | ||
|
||
setupSecurityPlugin | ||
setupPerformanceAnalyzerPlugin | ||
setupKNNPlugin | ||
|
||
# Start opensearch | ||
"$@" "${opensearch_opts[@]}" | ||
|
||
} | ||
|
||
# Prepend "opensearch" command if no argument was provided or if the first | ||
# argument looks like a flag (i.e. starts with a dash). | ||
if [ $# -eq 0 ] || [ "${1:0:1}" = '-' ]; then | ||
set -- opensearch "$@" | ||
fi | ||
|
||
if [ "$1" = "opensearch" ]; then | ||
# If the first argument is opensearch, then run the setup script. | ||
runOpensearch "$@" | ||
else | ||
# Otherwise, just exec the command. | ||
exec "$@" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These version scripts are very similar. Can one .sh call/include another? Would be nice if it wasn't a big copy paste with some small changes.