Skip to content

Apache Lucene open-source search software

SOLR-11703: Solr Should Send Log Notifications if Ulimits are too low

Erick Ericksone82e029406b2
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index f98d71df69e..1d4ac2ad9cb 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -81,6 +81,8 @@ Other Changes
* SOLR-11701: Upgrade to Tika 1.17 when available (Tim Allison, Karthik Ramachandran via Erick Erickson)
+* SOLR-11703: Solr Should Send Log Notifications if Ulimits are too low (Kevin Cowan via Erick Eickson)
+
================== 7.2.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
diff --git a/solr/bin/solr b/solr/bin/solr
index f9814c26828..ef83ceed949 100755
--- a/solr/bin/solr
+++ b/solr/bin/solr
@@ -1414,6 +1414,40 @@ if [ "$SCRIPT_CMD" != "stop" ] && [ "$SCRIPT_CMD" != "start" ] && [ "$SCRIPT_CMD
exit 1
fi
+#Check current Ulimits for Open Files and Max Processes. Warn if they are below the recommended values.
+
+if [ -z "$SOLR_RECOMMENDED_MAX_PROCESSES" ]; then
+ SOLR_RECOMMENDED_MAX_PROCESSES=65000
+fi
+
+if [ -z "$SOLR_RECOMMENDED_OPEN_FILES" ]; then
+ SOLR_RECOMMENDED_OPEN_FILES=65000
+fi
+
+if [ -z "$SOLR_ULIMIT_CHECKS" ] || [ "$SOLR_ULIMIT_CHECKS" != "false" ]; then
+ if [ "$SCRIPT_CMD" == "start" ] || [ "$SCRIPT_CMD" == "restart" ] || [ "$SCRIPT_CMD" == "status" ]; then
+ if hash ulimit 2>/dev/null; then
+ openFiles=$(ulimit -n)
+ maxProcs=$(ulimit -u)
+ if [ $openFiles -lt "$SOLR_RECOMMENDED_OPEN_FILES" ]; then
+ echo "*** [WARN] *** Your open file limit is currently $openFiles. "
+ echo " It should be set to $SOLR_RECOMMENDED_OPEN_FILES to avoid operational impariment. "
+ echo " If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh"
+ fi
+
+ if [ $maxProcs -lt "$SOLR_RECOMMENDED_MAX_PROCESSES" ]; then
+ echo "*** [WARN] *** Your Max Processes Limit is currently $maxProcs. "
+ echo " It should be set to $SOLR_RECOMMENDED_MAX_PROCESSES to avoid operational impariment. "
+ echo " If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh"
+ fi
+ else
+ echo "Could not check ulimits for processes and open files, recommended values are"
+ echo " max processes: $SOLR_RECOMMENDED_MAX_PROCESSES "
+ echo " open files: $SOLR_RECOMMENDED_OPEN_FILES"
+ fi
+ fi
+fi
+
# Run in foreground (default is to run in the background)
FG="false"
FORCE=false
diff --git a/solr/bin/solr.in.sh b/solr/bin/solr.in.sh
index 10d8b902e35..e7478cdf5c1 100644
--- a/solr/bin/solr.in.sh
+++ b/solr/bin/solr.in.sh
@@ -149,3 +149,14 @@
# -DzkDigestReadonlyUsername=readonly-user -DzkDigestReadonlyPassword=CHANGEME-READONLY-PASSWORD"
#SOLR_OPTS="$SOLR_OPTS $SOLR_ZK_CREDS_AND_ACLS"
+
+# Settings for common system values that may cause operational imparement when system defaults are used.
+# Solr can use many processes and many file handles. On modern operating systems the savings by leaving
+# these settings low is minuscule, while the consequence can be Solr instability. To turn these checks off, set
+# SOLR_ULIMIT_CHECKS=false either here or as part of your profile.
+
+# Different limits can be set in solr.in.sh or your profile if you prefer as well.
+#SOLR_RECOMMENDED_OPEN_FILES=
+#SOLR_RECOMMENDED_MAX_PROCESSES=
+#SOLR_ULIMIT_CHECKS=
+