Restrict mongodb memory usage
authorPradeep Kilambi <pkilambi@redhat.com>
Wed, 11 Jan 2017 18:56:57 +0000 (13:56 -0500)
committerPradeep Kilambi <pkilambi@redhat.com>
Mon, 17 Apr 2017 12:46:05 +0000 (12:46 +0000)
Currently, mongodb has no limits on how much memory
it can consume. This enforces restriction so mongodb
service limits through systemd.

The puppet-systemd module has support for limits. The
MemoryLimit support is added in the follwoing pull
request https://github.com/camptocamp/puppet-systemd/pull/23

Closes-bug: #1656558

Change-Id: Ie9391aa39532507c5de8dd668a70d5b66e17c891
(cherry picked from commit 3aa86a4ea3c2406f79d6283cbb158f67136b5e9a)

manifests/profile/base/database/mongodb.pp
releasenotes/notes/restrict-mongodb-memory-c19d69638b63feb4.yaml [new file with mode: 0644]

index 8967f5b..4740d67 100644 (file)
 #   for more details.
 #   Defaults to hiera('step')
 #
+# [*memory_limit*]
+#   (Optional) Limit amount of memory mongodb can use
+#   Defaults to 20G
+#
 class tripleo::profile::base::database::mongodb (
   $mongodb_replset,
   $bootstrap_node = downcase(hiera('bootstrap_nodeid')),
   $step           = hiera('step'),
+  $memory_limit   = '20G',
 ) {
   if $step >= 2 {
 
@@ -56,5 +61,11 @@ class tripleo::profile::base::database::mongodb (
       }
     }
 
+    # Limit memory utilization
+    ::systemd::service_limits { 'mongod.service':
+      limits => {
+        'MemoryLimit' => $memory_limit
+      }
+    }
   }
 }
diff --git a/releasenotes/notes/restrict-mongodb-memory-c19d69638b63feb4.yaml b/releasenotes/notes/restrict-mongodb-memory-c19d69638b63feb4.yaml
new file mode 100644 (file)
index 0000000..1186bb9
--- /dev/null
@@ -0,0 +1,6 @@
+---
+fixes:
+  - Add a way for mongodb to limit amount of memory it comsumes
+    with systemd. A new param memory_limit has been added to
+    tripleo::profile::base::database::mongodb class with
+    default limit of 20G.