From d0127d51bdb9a6b51fec5d91f2dbd72177e4c4ca Mon Sep 17 00:00:00 2001 From: Steve Lewis Date: Mon, 22 Jun 2015 17:49:51 -0700 Subject: [PATCH] Configurable memcached connections limit & threads Increasing memcached_connections may require ulimit to be raised so that will be done if necessary. Increasing memcached_threads is not strongly recommended but is available if needed. Change-Id: I4b58d59f647e6f843fc33561dea75be67c0f78c4 Closes-Bug: #1438498 --- .../roles/memcached_server/defaults/main.yml | 2 ++ .../memcached_server/tasks/memcached_config.yml | 15 ++++++++++++++- .../memcached_server/templates/memcached.conf | 2 ++ .../roles/memcached_server/templates/memcached.j2 | 6 ++++++ 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 playbooks/roles/memcached_server/templates/memcached.j2 diff --git a/playbooks/roles/memcached_server/defaults/main.yml b/playbooks/roles/memcached_server/defaults/main.yml index d36220c929..4220a1c1be 100644 --- a/playbooks/roles/memcached_server/defaults/main.yml +++ b/playbooks/roles/memcached_server/defaults/main.yml @@ -26,6 +26,8 @@ memcached_port: 11211 memcached_user: memcache memcached_listen: "127.0.0.1" memcached_log: /var/log/memcached.log +memcached_connections: 1024 +memcached_threads: 4 memcached_apt_packages: - memcached diff --git a/playbooks/roles/memcached_server/tasks/memcached_config.yml b/playbooks/roles/memcached_server/tasks/memcached_config.yml index edb9460768..52aa7a8452 100644 --- a/playbooks/roles/memcached_server/tasks/memcached_config.yml +++ b/playbooks/roles/memcached_server/tasks/memcached_config.yml @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Drop memcached config +- name: Apply memcached config template: src: "memcached.conf" dest: "/etc/memcached.conf" @@ -23,3 +23,16 @@ notify: Restart memcached tags: - memcached-config + +- name: Apply resource limits + template: + src: "memcached.j2" + dest: "/etc/default/memcached" + owner: "root" + group: "root" + mode: "0644" + when: > + memcached_connections > 1024 + notify: Restart memcached + tags: + - memcached-config diff --git a/playbooks/roles/memcached_server/templates/memcached.conf b/playbooks/roles/memcached_server/templates/memcached.conf index 7a77444932..efd0cf5121 100644 --- a/playbooks/roles/memcached_server/templates/memcached.conf +++ b/playbooks/roles/memcached_server/templates/memcached.conf @@ -6,3 +6,5 @@ logfile {{ memcached_log }} -p {{ memcached_port }} -u {{ memcached_user }} -l {{ memcached_listen }} +-c {{ memcached_connections }} +-t {{ memcached_threads }} diff --git a/playbooks/roles/memcached_server/templates/memcached.j2 b/playbooks/roles/memcached_server/templates/memcached.j2 new file mode 100644 index 0000000000..a6223d295f --- /dev/null +++ b/playbooks/roles/memcached_server/templates/memcached.j2 @@ -0,0 +1,6 @@ +# {{ ansible_managed }} +# Any other value will disable memcached. +ENABLE_MEMCACHED=yes + +ulimit -Hn {{ memcached_connections }} +ulimit -n {{ memcached_connections }}