use Math.sqrt(memory) to get container occupied memory according to system memory size,
instead of setting fixed size, more reasonable. In addition, '-Xms' not support floating
number, so use to_i.
Signed-off-by: Liu Yinsi <liuyinsi(a)163.com>
---
container/defconfig.rb | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/container/defconfig.rb b/container/defconfig.rb
index 05c56db..dd52fe3 100755
--- a/container/defconfig.rb
+++ b/container/defconfig.rb
@@ -35,3 +35,11 @@ def docker_rm(container)
system "docker stop #{container} && docker rm -f #{container}"
end
+
+def get_available_memory
+ memory = File.readlines('/proc/meminfo')[0].chomp.split[1].to_f / 1048576
+
+ # set container available memory size, minimum size is 1024m, maximum size is 30720m,
+ # take the middle value according to the system memory size.
+ [1024, 30720, Math.sqrt(memory) * 1024].sort[1].to_i
+end
--
2.23.0