Can I configure Linux swap space on AWS Elastic Beanstalk?

假装没事ソ 提交于 2020-07-06 13:17:43

问题


Can I configure Linux swap space for an AWS Elastic Beanstalk environment?

I don't see an option for it in the console. From looking at /proc/meminfo on my running instances in my environment MemAvailable is looking quite low despite there being quite high Inactive values. I suspect there are a few dormant background processes that it would do no harm to page out, and would free up a non-trivial portion of the limited physical memory on the t2.nano I'm using.


回答1:


I figured out how to do this using the .ebextensions config folder in my Tomcat web app.

Add a file .ebextensions/swap.config:

container_commands:
  add-swap-space:
    command: "/bin/bash .ebextensions/scripts/add-swap-space.sh"
    ignoreErrors: true

Add a file .ebextensions/scripts/add-swap-space.sh:

#!/bin/bash

set -o xtrace
set -e

if grep -E 'SwapTotal:\s+0+\s+kB' /proc/meminfo; then
    echo "Positively identified no swap space, creating some."
    dd if=/dev/zero of=/var/swapfile bs=1M count=512
    /sbin/mkswap /var/swapfile
    chmod 000 /var/swapfile
    /sbin/swapon /var/swapfile
else
    echo "Did not confirm zero swap space, doing nothing."
fi

More docs: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html

After a while running this allowed 150MiB to be swapped out on my t2.nano instance which runs the Elastic Beanstalk Java Tomcat platform with default heap options. From what I can see there is no ongoing paging while the application runs. It looks like some dormant data has been pushed to swap and the page cache is significantly larger (up from 30MiB to 180MiB).



来源:https://stackoverflow.com/questions/36119306/can-i-configure-linux-swap-space-on-aws-elastic-beanstalk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!