Skip to content

Commit

Permalink
Merge pull request #256 from jgawor/heap_ratio
Browse files Browse the repository at this point in the history
Configure heap size ratio
  • Loading branch information
caijj committed Oct 19, 2015
2 parents 2458f37 + a0e012b commit 0f30df8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
2 changes: 2 additions & 0 deletions config/ibmjdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions docs/ibm-jdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions lib/liberty_buildpack/jre/ibmjdk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions spec/liberty_buildpack/jre/ibmjdk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0f30df8

Please sign in to comment.