diff --git bin/hbase-config.sh bin/hbase-config.sh index 32d495d..cdd7b66 100644 --- bin/hbase-config.sh +++ bin/hbase-config.sh @@ -78,6 +78,59 @@ HBASE_REGIONSERVERS="${HBASE_REGIONSERVERS:-$HBASE_CONF_DIR/regionservers}" # List of hbase secondary masters. HBASE_BACKUP_MASTERS="${HBASE_BACKUP_MASTERS:-$HBASE_CONF_DIR/backup-masters}" +# Define functions + +# usage: figure_gc_opts [heapsize in mb] +# If heapsize isn't provided, uses $HBASE_HEAPSIZE or 1000 +# Variables that affect this: +# HBASE_HEAPSIZE=1000 +# How much heap to use +# HBASE_NEWSIZE_PER_CORE=50 +# Amount of young generation memory to allow for each core. +# This determines the length of young generation GC pauses +# (higher is longer) +# HBASE_NEWRATIO=8 +# Fraction of the heap to use. The value 8 means to use +# 1/8 of the heap as young generation +function figure_gc_opts() { + heap_mb=${1:-${HBASE_HEAPSIZE}} + heap_mb=${heap_mb:-1000} + cores=$(cat /proc/cpuinfo 2>/dev/null | grep '^processor' | wc -l) + + if [ $cores = "0" ]; then + # eg running on OSX we don't have /proc/cpuinfo, so just + # guess at 2 or use HBASE_CORE_COUNT to allow user to + # override + cores=${HBASE_CORE_COUNT:-2} + fi + echo cores: $cores >&2 + + newratio=${HBASE_NEWRATIO:-8} + newsize_per_core=${HBASE_NEWSIZE_PER_CORE} + desired_newsize=$[$heap_mb / $newratio] + newsize_by_cores=$[$cores * $newsize_per_core] + + if [ $desired_newsize -gt $newsize_by_cores ]; then + newsize=$newsize_by_cores + else + newsize=$desired_newsize + fi + ret="-Xmx${heap_mb}m -Xms${heap_mb}m -Xmn${newsize}m" + + # Enable CMS + ret="$ret -XX:+UseConcMarkSweepGC" + # Tune CMS trigger to 70% heap - default memory usage is 60% for + # block cache + memstores, so this triggers 10% after that + ret="$ret -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSInitiatingOccupancyOnly" + if [ "$cores" -gt 2 ]; then + # On multi-core boxes, parallel GC is good + ret="$ret -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled" + else + # Otherwise incremental mode is recommended + ret="$ret -XX:+CMSIncrementalMode" + fi + echo $ret +} # Source the hbase-env.sh. Will have JAVA_HOME defined. if [ -f "${HBASE_CONF_DIR}/hbase-env.sh" ]; then @@ -117,3 +170,5 @@ EOF exit 1 fi fi + + diff --git conf/hbase-env.sh conf/hbase-env.sh index a4ae923..b609d7a 100644 --- conf/hbase-env.sh +++ conf/hbase-env.sh @@ -31,10 +31,11 @@ # export HBASE_HEAPSIZE=1000 # Extra Java runtime options. -# Below are what we set by default. May only work with SUN JVM. +# By default we infer some options based on the value of HBASE_HEAPSIZE. +# May only work with SUN JVM. # For more on why as well as other possible settings, # see http://wiki.apache.org/hadoop/PerformanceTuning -export HBASE_OPTS="-XX:+HeapDumpOnOutOfMemoryError -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode" +export HBASE_OPTS="-XX:+HeapDumpOnOutOfMemoryError $(figure_gc_opts $HBASE_HEAPSIZE)" # Uncomment below to enable java garbage collection logging. # export HBASE_OPTS="$HBASE_OPTS -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:$HBASE_HOME/logs/gc-hbase.log"