Skip to content

Dynamic Memory Assignment #30

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
43 changes: 40 additions & 3 deletions reducedStartupTime/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,19 @@ checkEnvSubstituteConfig()
print_Debug "set BW_APPLICATION_JOB_FLOWLIMIT to $BW_APPLICATION_JOB_FLOWLIMIT"
fi
fi
if [[ ${BW_COMPONENT_JOB_FLOWLIMIT} ]]; then
if [ -e ${appnodeConfigFile} ]; then
IFS=';' # space is set as delimiter
read -ra processConfigurationList <<< "${BW_COMPONENT_JOB_FLOWLIMIT}" # str is read into an array as tokens separated by IFS
for process in "${processConfigurationList[@]}"; do # access each element of array
echo "Setting flow limit for $process"
IFS=':' # space is set as delimiter
read -ra processConfiguration <<< "$process" # str is read into an array as tokens separated by IFS
printf '%s\n' "bw.application.job.flowlimit.$bwBundleAppName.${processConfiguration[0]}=${processConfiguration[1]}" >> $appnodeConfigFile
print_Debug "set bw.application.job.flowlimit.$bwBundleAppName.${processConfiguration[0]} to ${processConfiguration[1]}"
done
fi
fi
if [[ ${BW_APP_MONITORING_CONFIG} ]]; then
if [ -e ${appnodeConfigFile} ]; then
sed -i 's/bw.frwk.event.subscriber.metrics.enabled=false/bw.frwk.event.subscriber.metrics.enabled=true/g' $appnodeConfigFile
Expand Down Expand Up @@ -289,9 +302,33 @@ done

memoryCalculator()
{
if [[ ${MEMORY_LIMIT} ]]; then
memory_Number=`echo $MEMORY_LIMIT | sed 's/m$//I'`
configured_MEM=$((($memory_Number*67+50)/100))
if [[ ${MEMORY_LIMIT} ]]; then

configured_MEM=$(expr `cat /sys/fs/cgroup/memory/memory.limit_in_bytes` / 1024 / 1024)
configured_MEM_orig=$configured_MEM

if [[ ${MEMORY_DYNAMIC_LIMIT} ]]; then
sys_MEM=$(expr $configured_MEM \* ${MEMORY_DYNAMIC_LIMIT} / 100)
system_MEM=`printf "%.0f" $sys_MEM`
configured_MEM_temp=$(expr $configured_MEM - $system_MEM)
if [[ $configured_MEM_temp -gt 128 ]]; then
configured_MEM=$configured_MEM_temp
fi
elif [[ ${MEMORY_FIXED_LIMIT} ]]; then
configured_MEM_temp=$(expr $configured_MEM - ${MEMORY_FIXED_LIMIT} )
if [[ $configured_MEM_temp -gt 128 ]]; then
configured_MEM=$configured_MEM_temp
fi
fi

if [[ $configured_MEM -eq $configured_MEM_orig ]]; then
configured_MEM_temp=$(expr $configured_MEM - 128)
if [[ $configured_MEM_temp -gt 128 ]]; then
configured_MEM=$configured_MEM_temp
fi
fi

print_Debug "Maximum memory calculated in a dynamic way to a value [$configured_MEM]"
thread_Stack=$((memory_Number))
JAVA_PARAM="-Xmx"$configured_MEM"M -Xms128M -Xss512K"
export BW_JAVA_OPTS=$JAVA_PARAM" "$BW_JAVA_OPTS
Expand Down
45 changes: 41 additions & 4 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,19 @@ checkEnvSubstituteConfig()
print_Debug "set BW_APPLICATION_JOB_FLOWLIMIT to $BW_APPLICATION_JOB_FLOWLIMIT"
fi
fi
if [[ ${BW_COMPONENT_JOB_FLOWLIMIT} ]]; then
if [ -e ${appnodeConfigFile} ]; then
IFS=';' # space is set as delimiter
read -ra processConfigurationList <<< "${BW_COMPONENT_JOB_FLOWLIMIT}" # str is read into an array as tokens separated by IFS
for process in "${processConfigurationList[@]}"; do # access each element of array
echo "Setting flow limit for $process"
IFS=':' # space is set as delimiter
read -ra processConfiguration <<< "$process" # str is read into an array as tokens separated by IFS
printf '%s\n' "bw.application.job.flowlimit.$bwBundleAppName.${processConfiguration[0]}=${processConfiguration[1]}" >> $appnodeConfigFile
print_Debug "set bw.application.job.flowlimit.$bwBundleAppName.${processConfiguration[0]} to ${processConfiguration[1]}"
done
fi
fi
if [[ ${BW_APP_MONITORING_CONFIG} ]]; then
if [ -e ${appnodeConfigFile} ]; then
sed -i 's/bw.frwk.event.subscriber.metrics.enabled=false/bw.frwk.event.subscriber.metrics.enabled=true/g' $appnodeConfigFile
Expand Down Expand Up @@ -289,13 +302,37 @@ done

memoryCalculator()
{
if [[ ${MEMORY_LIMIT} ]]; then
memory_Number=`echo $MEMORY_LIMIT | sed 's/m$//I'`
configured_MEM=$((($memory_Number*67+50)/100))
if [[ ${MEMORY_LIMIT} ]]; then

configured_MEM=$(expr `cat /sys/fs/cgroup/memory/memory.limit_in_bytes` / 1024 / 1024)
configured_MEM_orig=$configured_MEM

if [[ ${MEMORY_DYNAMIC_LIMIT} ]]; then
sys_MEM=$(expr $configured_MEM \* ${MEMORY_DYNAMIC_LIMIT} / 100)
system_MEM=`printf "%.0f" $sys_MEM`
configured_MEM_temp=$(expr $configured_MEM - $system_MEM)
if [[ $configured_MEM_temp -gt 128 ]]; then
configured_MEM=$configured_MEM_temp
fi
elif [[ ${MEMORY_FIXED_LIMIT} ]]; then
configured_MEM_temp=$(expr $configured_MEM - ${MEMORY_FIXED_LIMIT} )
if [[ $configured_MEM_temp -gt 128 ]]; then
configured_MEM=$configured_MEM_temp
fi
fi

if [[ $configured_MEM -eq $configured_MEM_orig ]]; then
configured_MEM_temp=$(expr $configured_MEM - 128)
if [[ $configured_MEM_temp -gt 128 ]]; then
configured_MEM=$configured_MEM_temp
fi
fi

print_Debug "Maximum memory calculated in a dynamic way to a value [$configured_MEM]"
thread_Stack=$((memory_Number))
JAVA_PARAM="-Xmx"$configured_MEM"M -Xms128M -Xss512K"
export BW_JAVA_OPTS=$JAVA_PARAM" "$BW_JAVA_OPTS
fi
fi
}

applyDefaultJVMHeapParams(){
Expand Down