Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

set MALLOC_ARENA_MAX to a lower dynamic value to prevent OOM #143

Merged
merged 2 commits into from
Feb 22, 2018
Merged
Changes from 1 commit
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
Next Next commit
set MALLOC_ARENA_MAX to a lower dynamic value to prevent OOM
The default behavior is 8x the number of detected CPUs . As Cloud
Foundry typically uses large host machines with smaller containers,
and the Java process is unaware of the difference in allocated CPUs,
the numbers are way off. This often leads to high native memory usage,
followed by a cgroup OOM killer event.

We go with Heroku's recommendation of lowering to a
setting of 2 for small instances. We also grown the setting linearly
with memory to be more in line with the default setting in Mendix
Cloud v3.

References:
- cloudfoundry/java-buildpack#163
- https://devcenter.heroku.com/articles/testing-cedar-14-memory-use
- cloudfoundry/java-buildpack#320
  • Loading branch information
Jouke Waleson committed Feb 21, 2018
commit 5cfad0115b13d74b10dc357d21df6bff25ec08b4
12 changes: 10 additions & 2 deletions start.py
Original file line number Diff line number Diff line change
@@ -241,7 +241,7 @@ def get_constants(metadata):
return constants


def set_jvm_memory(javaopts, vcap, java_version):
def set_jvm_memory(m2ee_section, vcap, java_version):
max_memory = os.environ.get('MEMORY_LIMIT')

if max_memory:
@@ -273,6 +273,7 @@ def set_jvm_memory(javaopts, vcap, java_version):
heap_size,
)
)
javaopts = m2ee_section['javaopts']

javaopts.append('-Xmx%s' % heap_size)
javaopts.append('-Xms%s' % heap_size)
@@ -284,6 +285,13 @@ def set_jvm_memory(javaopts, vcap, java_version):

logger.debug('Java heap size set to %s' % heap_size)

if os.getenv('MALLOC_ARENA_MAX'):
logger.info('Using provided environment setting for MALLOC_ARENA_MAX')
else:
m2ee_section['custom_environment']['MALLOC_ARENA_MAX'] = str(
max(1, limit / 1024) * 2
)


def _get_s3_specific_config(vcap_services, m2ee):
access_key = secret = bucket = encryption_keys = key_suffix = None
@@ -671,7 +679,7 @@ def set_up_m2ee_client(vcap_data):
m2ee.config.get_runtime_version()
)
set_jvm_memory(
m2ee.config._conf['m2ee']['javaopts'],
m2ee.config._conf['m2ee'],
vcap_data,
java_version,
)