From b9eef8caa4b5f81b9512763a7bb797c630c8918e Mon Sep 17 00:00:00 2001 From: Liu-HongYe Date: Sun, 23 Dec 2018 15:42:49 +0800 Subject: [PATCH 1/3] Dynamically setting the JVM memory limit by reading the Cgroup configuration during container startup. --- core/java8/Dockerfile | 3 ++- core/java8/init.sh | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 core/java8/init.sh diff --git a/core/java8/Dockerfile b/core/java8/Dockerfile index 71ece46b..54afb37f 100644 --- a/core/java8/Dockerfile +++ b/core/java8/Dockerfile @@ -37,4 +37,5 @@ RUN cd /javaAction \ && rm -rf /javaAction/src \ && ./compileClassCache.sh -CMD ["java", "-Dfile.encoding=UTF-8", "-Xshareclasses:cacheDir=/javaSharedCache,readonly", "-Xquickstart", "-jar", "/javaAction/build/libs/javaAction-all.jar"] +ADD init.sh ./ +CMD ["./init.sh"] \ No newline at end of file diff --git a/core/java8/init.sh b/core/java8/init.sh new file mode 100644 index 00000000..07c19345 --- /dev/null +++ b/core/java8/init.sh @@ -0,0 +1,17 @@ +#!/bin/bash +limit_in_bytes=$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes) +heap_size=64 +export JAVA_OPTS="-Dfile.encoding=UTF-8 -Xshareclasses:cacheDir=/javaSharedCache,readonly -Xquickstart" +export RESERVED_MEGABYTES=64 + +# If not default limit_in_bytes in cgroup +if [ "$limit_in_bytes" -ne "9223372036854771712" ] +then + limit_in_megabytes=$(expr $limit_in_bytes \/ 1048576) + heap_size=$(expr $limit_in_megabytes - $RESERVED_MEGABYTES) + export JAVA_OPTS="-Xmx${heap_size}m $JAVA_OPTS" +fi + +echo JAVA_OPTS= $JAVA_OPTS + +java $JAVA_OPTS -jar /javaAction/build/libs/javaAction-all.jar From e5c4f95f68b1de6930427713b9bb5834ce9eda13 Mon Sep 17 00:00:00 2001 From: Liu-HongYe Date: Sun, 23 Dec 2018 15:58:26 +0800 Subject: [PATCH 2/3] # add license head --- core/java8/init.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/core/java8/init.sh b/core/java8/init.sh index 07c19345..28a2a8c3 100644 --- a/core/java8/init.sh +++ b/core/java8/init.sh @@ -1,4 +1,21 @@ -#!/bin/bash +#!/usr/bin/env bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + limit_in_bytes=$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes) heap_size=64 export JAVA_OPTS="-Dfile.encoding=UTF-8 -Xshareclasses:cacheDir=/javaSharedCache,readonly -Xquickstart" From 9da41928e17c593bf54ee412ea5670e2409f556b Mon Sep 17 00:00:00 2001 From: Liu-HongYe Date: Sun, 23 Dec 2018 16:19:21 +0800 Subject: [PATCH 3/3] # permission denied --- core/java8/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/core/java8/Dockerfile b/core/java8/Dockerfile index 54afb37f..d3ea6a31 100644 --- a/core/java8/Dockerfile +++ b/core/java8/Dockerfile @@ -38,4 +38,5 @@ RUN cd /javaAction \ && ./compileClassCache.sh ADD init.sh ./ +RUN chmod 777 ./init.sh CMD ["./init.sh"] \ No newline at end of file