From a0e012b6e0ae59476d51dd959f0768ecf110ffea Mon Sep 17 00:00:00 2001 From: Jarek Gawor Date: Sat, 17 Oct 2015 00:22:34 -0400 Subject: [PATCH] configure heap size ratio --- config/ibmjdk.yml | 2 ++ docs/ibm-jdk.md | 17 +++++++++++++++++ lib/liberty_buildpack/jre/ibmjdk.rb | 16 ++++++++-------- spec/liberty_buildpack/jre/ibmjdk_spec.rb | 23 +++++++++++++++++++++-- 4 files changed, 48 insertions(+), 10 deletions(-) diff --git a/config/ibmjdk.yml b/config/ibmjdk.yml index 7399d46c8..ddad9fc30 100644 --- a/config/ibmjdk.yml +++ b/config/ibmjdk.yml @@ -17,3 +17,5 @@ --- repository_root: "https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/downloads/jre" version: 1.8.+ + +heap_size_ratio: 0.75 diff --git a/docs/ibm-jdk.md b/docs/ibm-jdk.md index 6caa79efc..5f408b24c 100644 --- a/docs/ibm-jdk.md +++ b/docs/ibm-jdk.md @@ -17,6 +17,23 @@ The JRE can be configured by modifying the [`config/ibmjdk.yml`][] file in the b | ---- | ----------- | `repository_root` | The URL of the IBM JRE repository index ([details][repositories]). | `version` | The version of Java runtime to use. Candidate versions can be found [here][index.yml]. +| `heap_size_ratio` | The ratio that is used to calculate the maximum heap size. The default heap size ratio is `0.75` (75% of the total available memory). + +## Common Configuration Overrides + +The IBM JRE [configuration can be overridden](configuration.md) with the `JBP_CONFIG_IBMJDK` environment variable. The value of the variable should be valid inline YAML. For example: + +1. Adjust heap size ratio: + + ```bash + $ cf set-env myApplication JBP_CONFIG_IBMJDK 'heap_size_ratio: 0.90' + ``` + +1. Use IBM JRE version 7: + + ```bash + $ cf set-env myApplication JBP_CONFIG_IBMJDK 'version: 1.7.+' + ``` [`config/ibmjdk.yml`]: ../config/ibmjdk.yml [index.yml]: http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/downloads/jre/index.yml diff --git a/lib/liberty_buildpack/jre/ibmjdk.rb b/lib/liberty_buildpack/jre/ibmjdk.rb index acde1c44c..987cb2da5 100644 --- a/lib/liberty_buildpack/jre/ibmjdk.rb +++ b/lib/liberty_buildpack/jre/ibmjdk.rb @@ -165,25 +165,25 @@ def java_home end def memory(configuration) + java_memory_opts = [] + java_memory_opts.push '-Xtune:virtualized' + mem = MemoryLimit.memory_limit if mem.nil? ## if no memory option has been set by cloudfoundry, we just assume defaults - java_memory_opts = [] - java_memory_opts.push '-Xtune:virtualized' - java_memory_opts else - java_memory_opts = [] - - new_heap_size = mem * HEAP_SIZE_RATIO - - java_memory_opts.push '-Xtune:virtualized' + new_heap_size = mem * heap_size_ratio java_memory_opts.push "-Xmx#{new_heap_size}" java_memory_opts end end + def heap_size_ratio + @configuration['heap_size_ratio'] || HEAP_SIZE_RATIO + end + # default options for -Xdump to disable dumps while routing to the default dumps location when it is enabled by the # user def default_dump_opts diff --git a/spec/liberty_buildpack/jre/ibmjdk_spec.rb b/spec/liberty_buildpack/jre/ibmjdk_spec.rb index 2ef0e388d..f640202a3 100644 --- a/spec/liberty_buildpack/jre/ibmjdk_spec.rb +++ b/spec/liberty_buildpack/jre/ibmjdk_spec.rb @@ -164,16 +164,35 @@ module LibertyBuildpack::Jre '-Xdump:heap+java+snap:events=user') end - it 'should add extra memory options when a memory limit is set' do + it 'should add extra memory options when 512m memory limit is set' do ENV['MEMORY_LIMIT'] = '512m' expect(released).to include('-Xtune:virtualized') expect(released).to include('-Xmx384M') end - it 'should provide troubleshooting info for JVM shutdowns' do + it 'should add extra memory options when 512m memory limit is set with 50% ratio', configuration: { 'heap_size_ratio' => 0.50 } do ENV['MEMORY_LIMIT'] = '512m' + expect(released).to include('-Xtune:virtualized') + expect(released).to include('-Xmx256M') + end + + it 'should add extra memory options when 1024m memory limit is set' do + ENV['MEMORY_LIMIT'] = '1024m' + + expect(released).to include('-Xtune:virtualized') + expect(released).to include('-Xmx768M') + end + + it 'should add extra memory options when 1024m memory limit is set with 12.% ratio', configuration: { 'heap_size_ratio' => 0.125 } do + ENV['MEMORY_LIMIT'] = '1024m' + + expect(released).to include('-Xtune:virtualized') + expect(released).to include('-Xmx128M') + end + + it 'should provide troubleshooting info for JVM shutdowns' do expect(released).to include("-Xdump:tool:events=systhrow,filter=java/lang/OutOfMemoryError,request=serial+exclusive,exec=./#{LibertyBuildpack::Diagnostics::DIAGNOSTICS_DIRECTORY}/#{IBMJdk::KILLJAVA_FILE_NAME}") end end # end of release shared tests