use Math.sqrt(memory) to set 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@163.com --- container/defconfig.rb | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/container/defconfig.rb b/container/defconfig.rb index 05c56db..026a183 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 set_available_memory + memory = `awk '($1 == "MemTotal:"){print $2/1048576}' /proc/meminfo`.to_f + + # set container available memory size, minimum size is 1g, maximum size is 30g, + # take the middle value according to the system memory size. + [1, 30, Math.sqrt(memory)].sort[1].to_i +end
On Tue, Dec 01, 2020 at 11:36:25AM +0800, Liu Yinsi wrote:
use Math.sqrt(memory) to set 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@163.com
container/defconfig.rb | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/container/defconfig.rb b/container/defconfig.rb index 05c56db..026a183 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 set_available_memory
- memory = `awk '($1 == "MemTotal:"){print $2/1048576}' /proc/meminfo`.to_f
We can first create a more generic function by returning a hash.
[7] pry(main)> File.readlines('/proc/meminfo').map {|s| k,v,kb = s.split; {k.chomp(':') => v} } => [{"MemTotal"=>"1003932288"}, {"MemFree"=>"88093888"}, {"MemAvailable"=>"443704320"}, {"Buffers"=>"33081280"}, {"Cached"=>"393810496"}, {"SwapCached"=>"0"}, ...
- # set container available memory size, minimum size is 1g, maximum size is 30g,
- # take the middle value according to the system memory size.
- [1, 30, Math.sqrt(memory)].sort[1].to_i
That should go to a dedicated function for use by ES container.
+end
2.23.0
system "docker stop #{container} && docker rm -f #{container}" end
+def set_available_memory
- memory = `awk '($1 == "MemTotal:"){print $2/1048576}' /proc/meminfo`.to_f
We can first create a more generic function by returning a hash.
[7] pry(main)> File.readlines('/proc/meminfo').map {|s| k,v,kb = s.split; {k.chomp(':') => v} } => [{"MemTotal"=>"1003932288"}, {"MemFree"=>"88093888"}, {"MemAvailable"=>"443704320"}, {"Buffers"=>"33081280"}, {"Cached"=>"393810496"}, {"SwapCached"=>"0"}, ...
ok.
- # set container available memory size, minimum size is 1g, maximum size is 30g,
- # take the middle value according to the system memory size.
- [1, 30, Math.sqrt(memory)].sort[1].to_i
That should go to a dedicated function for use by ES container.
ok, i will define 2 function, 1 generic 1 dedicated.
Thanks, Yinsi
+end
2.23.0