Skip to content

Commit 485c455

Browse files
author
Christopher Frost
committed
Configure number of stack threads for memory
This commit adds the ability to configure the number of threads the memory calculator should use when calculating the stack to allocate per thread. The default behaviour of the Java Buildpack is unchanged. [#91088912]
1 parent 83b743a commit 485c455

6 files changed

Lines changed: 49 additions & 10 deletions

File tree

config/open_jdk_jre.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jre:
2222
memory_calculator:
2323
version: 2.+
2424
repository_root: ! '{default.repository.root}/memory-calculator/{platform}/{architecture}'
25+
stack_threads:
2526
memory_sizes:
2627
heap:
2728
metaspace: 64m..

config/oracle_jre.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jre:
2525
memory_calculator:
2626
version: 2.+
2727
repository_root: ! '{default.repository.root}/memory-calculator/{platform}/{architecture}'
28+
stack_threads:
2829
memory_sizes:
2930
heap:
3031
metaspace: 64m..

docs/jre-open_jdk_jre.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ The JRE can be configured by modifying the [`config/open_jdk_jre.yml`][] file in
3030
The JRE can also be configured by overlaying a set of resources on the default distribution. To do this, add files to the `resources/open_jdk_jre` directory in the buildpack fork. For example, to add the JCE Unlimited Strength `local_policy.jar` add your file to `resources/open_jdk_jre/lib/security/local_policy.jar`.
3131

3232
### Memory
33-
The total available memory is specified when an application is pushed as part of it's configuration. The Java buildpack uses this value to control the JRE's use of various regions of memory. The JRE memory settings can be influenced by configuring the `memory_sizes` and/or `memory_heuristics` mappings.
33+
The total available memory is specified when an application is pushed as part of it's configuration. The Java buildpack uses this value to control the JRE's use of various regions of memory. The JRE memory settings can be influenced by configuring the `memory_sizes`, `memory_heuristics`, `memory_initials` and/or `stack_threads` mappings.
3434

35-
Note: if the total available memory is scaled up or down, the Java buildpack will re-calculate the JRE memory settings the next time the appication is started.
35+
Note: if the total available memory is scaled up or down, the Java buildpack will re-calculate the JRE memory settings the next time the application is started.
3636

3737
#### Memory Sizes
3838
The following optional properties may be specified in the `memory_sizes` mapping.
@@ -83,6 +83,14 @@ If no initial value is specified for a memory type the JVM default will be used.
8383

8484
A value of 100% for each memory types is generally recommended for best performance. Smaller values will potentially preserve unused system memory for other tenants on the same host. Using the G1 garbage collector along with aggressive `MinHeapFreeRatio` and `MaxHeapFreeRatio` values the JVM will actually release unused heap back to the system up to the initial value.
8585

86+
#### Stack Threads
87+
88+
The amount of memory that should be allocated to the stack is given as an amount of memory per thread with the command line option `-Xss`. The default behaviour is to use an estimate of the number of threads based on the total memory for the application. If an explicit number of threads should be used for the calculation of stack memory then it should be specified like the following example:
89+
90+
```yaml
91+
stack_threads: 500
92+
```
93+
8694
#### Memory Calculation
8795
Memory calculation happens before every `start` of an application and is performed by an external program, the [Java Buildpack Memory Calculator]. There is no need to `restage` an application after scaling the memory as restarting will cause the memory settings to be recalculated.
8896

docs/jre-oracle_jre.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ The JRE can be configured by modifying the [`config/oracle_jre.yml`][] file in t
3939
The JRE can also be configured by overlaying a set of resources on the default distribution. To do this, add files to the `resources/oracle_jre` directory in the buildpack fork. For example, to add the JCE Unlimited Strength `local_policy.jar` add your file to `resources/oracle_jre/lib/security/local_policy.jar`.
4040

4141
### Memory
42-
The total available memory is specified when an application is pushed as part of it's configuration. The Java buildpack uses this value to control the JRE's use of various regions of memory. The JRE memory settings can be influenced by configuring the `memory_sizes` and/or `memory_heuristics` mappings.
42+
The total available memory is specified when an application is pushed as part of it's configuration. The Java buildpack uses this value to control the JRE's use of various regions of memory. The JRE memory settings can be influenced by configuring the `memory_sizes`, `memory_heuristics`, `memory_initials` and/or `stack_threads` mappings.
4343

44-
Note: if the total available memory is scaled up or down, the Java buildpack will re-calculate the JRE memory settings the next time the appication is started.
44+
Note: if the total available memory is scaled up or down, the Java buildpack will re-calculate the JRE memory settings the next time the application is started.
4545

4646
#### Memory Sizes
4747
The following optional properties may be specified in the `memory_sizes` mapping.
@@ -92,6 +92,14 @@ If no initial value is specified for a memory type the JVM default will be used.
9292

9393
A value of 100% for each memory types is generally recommended for best performance. Smaller values will potentially preserve unused system memory for other tenants on the same host. Using the G1 garbage collector along with aggressive `MinHeapFreeRatio` and `MaxHeapFreeRatio` values the JVM will actually release unused heap back to the system up to the initial value.
9494

95+
#### Stack Threads
96+
97+
The amount of memory that should be allocated to the stack is given as an amount of memory per thread with the command line option `-Xss`. The default behaviour is to use an estimate of the number of threads based on the total memory for the application. If an explicit number of threads should be used for the calculation of stack memory then it should be specified like the following example:
98+
99+
```yaml
100+
stack_threads: 500
101+
```
102+
95103
#### Memory Calculation
96104
Memory calculation happens before every `start` of an application and is performed by an external program, the [Java Buildpack Memory Calculator]. There is no need to `restage` an application after scaling the memory as restarting will cause the memory settings to be recalculated.
97105

lib/java_buildpack/jre/open_jdk_like_memory_calculator.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ def memory_calculator_tar
7575

7676
def memory_calculation_string(relative_path)
7777
"#{qualify_path memory_calculator, relative_path} -memorySizes=#{memory_sizes @configuration} " \
78-
"-memoryWeights=#{memory_weights @configuration} -memoryInitials=#{memory_initials @configuration} " \
79-
'-totMemory=$MEMORY_LIMIT'
78+
"-memoryWeights=#{memory_weights @configuration} -memoryInitials=#{memory_initials @configuration}" \
79+
"#{stack_threads @configuration} -totMemory=$MEMORY_LIMIT"
8080
end
8181

8282
def memory_sizes(configuration)
@@ -85,13 +85,13 @@ def memory_sizes(configuration)
8585
end
8686

8787
def memory_weights(configuration)
88-
memory_sizes = version_specific configuration['memory_heuristics']
89-
memory_sizes.map { |k, v| "#{k}:#{v}" }.join(',')
88+
memory_heuristics = version_specific configuration['memory_heuristics']
89+
memory_heuristics.map { |k, v| "#{k}:#{v}" }.join(',')
9090
end
9191

9292
def memory_initials(configuration)
93-
memory_sizes = version_specific configuration['memory_initials']
94-
memory_sizes.map { |k, v| "#{k}:#{v}" }.join(',')
93+
memory_initials = version_specific configuration['memory_initials']
94+
memory_initials.map { |k, v| "#{k}:#{v}" }.join(',')
9595
end
9696

9797
def unpack_calculator(file)
@@ -103,6 +103,10 @@ def unpack_compressed_calculator(file)
103103
FileUtils.mv(memory_calculator_tar, memory_calculator)
104104
end
105105

106+
def stack_threads(configuration)
107+
configuration['stack_threads'] ? " -stackThreads=#{configuration['stack_threads']}" : ''
108+
end
109+
106110
def version_specific(configuration)
107111
if @droplet.java_home.java_8_or_later?
108112
configuration.delete 'permgen'

spec/java_buildpack/jre/open_jdk_like_memory_calculator_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,21 @@
135135
expect(java_opts).to include('$CALCULATED_MEMORY')
136136
end
137137

138+
context do
139+
140+
let(:configuration) { super().merge 'stack_threads' => '200' }
141+
142+
it 'create memory calculation command with stack threads specified' do
143+
java_home.version = version_7
144+
command = component.memory_calculation_command
145+
146+
expect(command).to eq('CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_like_memory_calculator/bin/' \
147+
'java-buildpack-memory-calculator-0.0.0 -memorySizes=permgen:64m.. ' \
148+
'-memoryWeights=heap:75,permgen:10,stack:5,native:10 ' \
149+
'-memoryInitials=heap:100%,permgen:100% ' \
150+
'-stackThreads=200 -totMemory=$MEMORY_LIMIT)')
151+
end
152+
153+
end
154+
138155
end

0 commit comments

Comments
 (0)