Skip to content

Commit

Permalink
Memory Calculation Headroom
Browse files Browse the repository at this point in the history
This change adds a configuration option that allocates empty overhead in the
memory calculation.  This configuration defaults to zero, but would be used in
cases where the memory calculator cannot accurately allocate memory regions
(e.g. 10G heap sizes).

[resolves cloudfoundry#583]
  • Loading branch information
nebhale committed May 3, 2018
1 parent 33b33f6 commit 1977b77
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 44 deletions.
1 change: 1 addition & 0 deletions config/open_jdk_jre.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ memory_calculator:
version: 3.+
repository_root: "{default.repository.root}/memory-calculator/{platform}/{architecture}"
class_count:
headroom:
stack_threads: 250
1 change: 1 addition & 0 deletions config/oracle_jre.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ memory_calculator:
version: 3.+
repository_root: "{default.repository.root}/memory-calculator/{platform}/{architecture}"
class_count:
headroom:
stack_threads: 250
3 changes: 2 additions & 1 deletion config/sap_machine_jre.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ jvmkill_agent:
memory_calculator:
version: 3.+
repository_root: "{default.repository.root}/memory-calculator/{platform}/{architecture}"
class_count:
class_count:
headroom:
stack_threads: 250
1 change: 1 addition & 0 deletions config/zulu_jre.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ memory_calculator:
version: 3.+
repository_root: "{default.repository.root}/memory-calculator/{platform}/{architecture}"
class_count:
headroom:
stack_threads: 250
22 changes: 13 additions & 9 deletions docs/jre-open_jdk_jre.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ The user can change the container's total memory available to influence the JRE
Unless the user specifies the heap size Java option (`-Xmx`), increasing or decreasing the total memory
available results in the heap size setting increasing or decreasing by a corresponding amount.

#### Loaded Classes

The amount of memory that is allocated to metaspace and compressed class space (or, on Java 7, the permanent generation) is calculated from an estimate of the number of classes that will be loaded. The default behaviour is to estimate the number of loaded classes as a fraction of the number of class files in the application.
If a specific number of loaded classes should be used for calculations, then it should be specified as in the following example:

```yaml
class_count: 500
```
#### Headroom
A percentage of the total memory allocated to the container to be left as headroom and excluded from the memory calculation.
#### Stack Threads
The amount of memory that should be allocated to stacks is given as an amount of memory per
Expand All @@ -102,15 +115,6 @@ the following example:
stack_threads: 500
```

#### Loaded Classes
The amount of memory that is allocated to metaspace and compressed class space (or, on Java 7, the permanent generation) is calculated from an estimate of the number of classes that will be loaded. The default behaviour is to estimate the number of loaded classes as a fraction of the number of class files in the application.
If a specific number of loaded classes should be used for calculations, then it should be specified as in the following example:
```yaml
class_count: 500
```
#### Java Options

If the JRE memory settings need to be fine-tuned, the user can set one or more Java memory options to
Expand Down
22 changes: 13 additions & 9 deletions docs/jre-oracle_jre.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ The user can change the container's total memory available to influence the JRE
Unless the user specifies the heap size Java option (`-Xmx`), increasing or decreasing the total memory
available results in the heap size setting increasing or decreasing by a corresponding amount.

#### Loaded Classes

The amount of memory that is allocated to metaspace and compressed class space (or, on Java 7, the permanent generation) is calculated from an estimate of the number of classes that will be loaded. The default behaviour is to estimate the number of loaded classes as a fraction of the number of class files in the application.
If a specific number of loaded classes should be used for calculations, then it should be specified as in the following example:

```yaml
class_count: 500
```
#### Headroom
A percentage of the total memory allocated to the container to be left as headroom and excluded from the memory calculation.
#### Stack Threads
The amount of memory that should be allocated to stacks is given as an amount of memory per
Expand All @@ -118,15 +131,6 @@ the following example:
stack_threads: 500
```

#### Loaded Classes
The amount of memory that is allocated to metaspace and compressed class space (or, on Java 7, the permanent generation) is calculated from an estimate of the number of classes that will be loaded. The default behaviour is to estimate the number of loaded classes as a fraction of the number of class files in the application.
If a specific number of loaded classes should be used for calculations, then it should be specified as in the following example:
```yaml
class_count: 500
```
#### Java Options

If the JRE memory settings need to be fine-tuned, the user can set one or more Java memory options to
Expand Down
22 changes: 13 additions & 9 deletions docs/jre-sap_machine_jre.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ The user can change the container's total memory available to influence the JRE
Unless the user specifies the heap size Java option (`-Xmx`), increasing or decreasing the total memory
available results in the heap size setting increasing or decreasing by a corresponding amount.

#### Loaded Classes

The amount of memory that is allocated to metaspace and compressed class space (or, on Java 7, the permanent generation) is calculated from an estimate of the number of classes that will be loaded. The default behaviour is to estimate the number of loaded classes as a fraction of the number of class files in the application.
If a specific number of loaded classes should be used for calculations, then it should be specified as in the following example:

```yaml
class_count: 500
```
#### Headroom
A percentage of the total memory allocated to the container to be left as headroom and excluded from the memory calculation.
#### Stack Threads
The amount of memory that should be allocated to stacks is given as an amount of memory per
Expand All @@ -105,15 +118,6 @@ the following example:
stack_threads: 500
```

#### Loaded Classes
The amount of memory that is allocated to metaspace and compressed class space (or, on Java 7, the permanent generation) is calculated from an estimate of the number of classes that will be loaded. The default behaviour is to estimate the number of loaded classes as a fraction of the number of class files in the application.
If a specific number of loaded classes should be used for calculations, then it should be specified as in the following example:
```yaml
class_count: 500
```
#### Java Options

If the JRE memory settings need to be fine-tuned, the user can set one or more Java memory options to
Expand Down
22 changes: 13 additions & 9 deletions docs/jre-zulu_jre.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ The user can change the container's total memory available to influence the JRE
Unless the user specifies the heap size Java option (`-Xmx`), increasing or decreasing the total memory
available results in the heap size setting increasing or decreasing by a corresponding amount.

#### Loaded Classes

The amount of memory that is allocated to metaspace and compressed class space (or, on Java 7, the permanent generation) is calculated from an estimate of the number of classes that will be loaded. The default behaviour is to estimate the number of loaded classes as a fraction of the number of class files in the application.
If a specific number of loaded classes should be used for calculations, then it should be specified as in the following example:

```yaml
class_count: 500
```
#### Headroom
A percentage of the total memory allocated to the container to be left as headroom and excluded from the memory calculation.
#### Stack Threads
The amount of memory that should be allocated to stacks is given as an amount of memory per
Expand All @@ -109,15 +122,6 @@ the following example:
stack_threads: 500
```

#### Loaded Classes
The amount of memory that is allocated to metaspace and compressed class space (or, on Java 7, the permanent generation) is calculated from an estimate of the number of classes that will be loaded. The default behaviour is to estimate the number of loaded classes as a fraction of the number of class files in the application.
If a specific number of loaded classes should be used for calculations, then it should be specified as in the following example:
```yaml
class_count: 500
```
#### Java Options

If the JRE memory settings need to be fine-tuned, the user can set one or more Java memory options to
Expand Down
10 changes: 9 additions & 1 deletion lib/java_buildpack/jre/open_jdk_like_memory_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def class_count(configuration)
configuration['class_count'] || (0.35 * actual_class_count(root)).ceil
end

def headroom(configuration)
configuration['headroom']
end

def memory_calculator
@droplet.sandbox + "bin/java-buildpack-memory-calculator-#{@version}"
end
Expand All @@ -101,9 +105,13 @@ def memory_calculator_tar
def memory_calculation_string(relative_path)
memory_calculation_string = [qualify_path(memory_calculator, relative_path)]
memory_calculation_string << '-totMemory=$MEMORY_LIMIT'
memory_calculation_string << "-stackThreads=#{stack_threads @configuration}"

headroom = headroom(@configuration)
memory_calculation_string << "-headRoom=#{headroom}" if headroom

memory_calculation_string << "-loadedClasses=#{class_count @configuration}"
memory_calculation_string << "-poolType=#{pool_type}"
memory_calculation_string << "-stackThreads=#{stack_threads @configuration}"
memory_calculation_string << '-vmOptions="$JAVA_OPTS"'

memory_calculation_string.join(' ')
Expand Down
27 changes: 23 additions & 4 deletions spec/java_buildpack/jre/open_jdk_like_memory_calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@
command = component.memory_calculation_command

expect(command).to eq('CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_like_memory_calculator/bin/' \
'java-buildpack-memory-calculator-0.0.0 -totMemory=$MEMORY_LIMIT -stackThreads=200 ' \
'-loadedClasses=2 -poolType=metaspace -vmOptions="$JAVA_OPTS") && echo JVM Memory ' \
'java-buildpack-memory-calculator-0.0.0 -totMemory=$MEMORY_LIMIT -loadedClasses=2 ' \
'-poolType=metaspace -stackThreads=200 -vmOptions="$JAVA_OPTS") && echo JVM Memory ' \
'Configuration: $CALCULATED_MEMORY && JAVA_OPTS="$JAVA_OPTS $CALCULATED_MEMORY"')
end

Expand All @@ -111,6 +111,25 @@
expect(environment_variables).to include('MALLOC_ARENA_MAX=2')
end

context 'with headroom' do

let(:configuration) { { 'headroom' => '11', 'stack_threads' => '200' } }

it 'creates memory calculation command with headroom',
app_fixture: 'jre_memory_calculator_application' do

java_home.version = version_8

command = component.memory_calculation_command

expect(command).to eq('CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_like_memory_calculator/bin/' \
'java-buildpack-memory-calculator-0.0.0 -totMemory=$MEMORY_LIMIT -headRoom=11 ' \
'-loadedClasses=2 -poolType=metaspace -stackThreads=200 -vmOptions="$JAVA_OPTS") && echo ' \
'JVM Memory Configuration: $CALCULATED_MEMORY && JAVA_OPTS="$JAVA_OPTS $CALCULATED_MEMORY"')
end

end

context 'when java 9' do

it 'creates memory calculation command',
Expand All @@ -121,8 +140,8 @@
command = component.memory_calculation_command

expect(command).to eq('CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_like_memory_calculator/bin/' \
'java-buildpack-memory-calculator-0.0.0 -totMemory=$MEMORY_LIMIT -stackThreads=200 ' \
'-loadedClasses=14777 -poolType=metaspace -vmOptions="$JAVA_OPTS") && echo JVM Memory ' \
'java-buildpack-memory-calculator-0.0.0 -totMemory=$MEMORY_LIMIT -loadedClasses=14777 ' \
'-poolType=metaspace -stackThreads=200 -vmOptions="$JAVA_OPTS") && echo JVM Memory ' \
'Configuration: $CALCULATED_MEMORY && JAVA_OPTS="$JAVA_OPTS $CALCULATED_MEMORY"')
end

Expand Down
4 changes: 2 additions & 2 deletions spec/java_buildpack/jre/open_jdk_like_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
java_home.version = version_7
expect(component.command).to eq('CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_like/bin/' \
'java-buildpack-memory-calculator-0.0.0 -totMemory=$MEMORY_LIMIT' \
' -stackThreads=200 -loadedClasses=0 -poolType=permgen -vmOptions="$JAVA_OPTS")' \
' -loadedClasses=0 -poolType=permgen -stackThreads=200 -vmOptions="$JAVA_OPTS")' \
' && echo JVM Memory Configuration: $CALCULATED_MEMORY && ' \
'JAVA_OPTS="$JAVA_OPTS $CALCULATED_MEMORY"')

Expand All @@ -80,7 +80,7 @@
java_home.version = version_8
expect(component.command).to eq('CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_like/bin/' \
'java-buildpack-memory-calculator-0.0.0 -totMemory=$MEMORY_LIMIT' \
' -stackThreads=200 -loadedClasses=0 -poolType=metaspace -vmOptions="$JAVA_OPTS")' \
' -loadedClasses=0 -poolType=metaspace -stackThreads=200 -vmOptions="$JAVA_OPTS")' \
' && echo JVM Memory Configuration: $CALCULATED_MEMORY && ' \
'JAVA_OPTS="$JAVA_OPTS $CALCULATED_MEMORY"')

Expand Down

0 comments on commit 1977b77

Please sign in to comment.