Skip to content

Commit

Permalink
Reserved memory for captain and nginx as we don't every want them OOM
Browse files Browse the repository at this point in the history
  • Loading branch information
dummy-head committed Nov 30, 2017
1 parent 8171ae3 commit b785ad9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
14 changes: 12 additions & 2 deletions app-backend/src/docker/DockerApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,15 @@ class DockerApi {
* value: 'some value'
* }
* ]
* @param resourcesObject:
* [
* {
* Limits: { NanoCPUs , MemoryBytes}
* Reservation: { NanoCPUs , MemoryBytes}
*
* ]
*/
createServiceOnNodeId(imageName, serviceName, portsToMap, nodeId, volumeToMount, arrayOfEnvKeyAndValue) {
createServiceOnNodeId(imageName, serviceName, portsToMap, nodeId, volumeToMount, arrayOfEnvKeyAndValue, resourcesObject) {

const self = this;

Expand All @@ -437,6 +444,7 @@ class DockerApi {
ContainerSpec: {
Image: imageName
},
Resources: resourcesObject,
Placement: {
Constraints: nodeId ? ['node.id == ' + nodeId] : []
}
Expand Down Expand Up @@ -875,6 +883,8 @@ class DockerApi {
* }
* ]
* @param instanceCount: String '12' or null
* @param nodeId: nodeId of the node this service will be locked to or null
* @param namespace: String 'captain' or null
* @returns {Promise.<>}
*/
updateService(serviceName, imageName, volumes, networks, arrayOfEnvKeyAndValue, secrets, authObject, instanceCount, nodeId, namespace) {
Expand Down Expand Up @@ -942,7 +952,7 @@ class DockerApi {
// named volumes are created here:
// /var/lib/docker/volumes/YOUR_VOLUME_NAME/_data
mts.push({
Source: (namespace ? (namespace + '--' ) : '' ) + v.volumeName,
Source: (namespace ? (namespace + '--') : '') + v.volumeName,
Target: v.containerPath,
Type: TYPE_VOLUME,
ReadOnly: false
Expand Down
8 changes: 6 additions & 2 deletions app-backend/src/user/LoadBalancerManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class LoadBalancerManager {

}

ensureBaseNginxConf(){
ensureBaseNginxConf() {
return Promise.resolve()
.then(function () {

Expand Down Expand Up @@ -280,7 +280,11 @@ class LoadBalancerManager {
}, {
containerPort: 443,
hostPort: 443
}], nodeId)
}], nodeId, null, null, {
Reservation: {
MemoryBytes: 30 * 1024 * 1024
}
})
.then(function () {

let waitTimeInMillis = 5000;
Expand Down
6 changes: 5 additions & 1 deletion app-backend/src/utils/CaptainInstaller.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ module.exports.install = function () {
});

return DockerApi.get().createServiceOnNodeId(captainNameAndVersion,
CaptainConstants.captainServiceName, ports, nodeId, volumeToMount, env);
CaptainConstants.captainServiceName, ports, nodeId, volumeToMount, env, {
Reservation: {
MemoryBytes: 100 * 1024 * 1024
}
});

})
.catch(function (error) {
Expand Down

0 comments on commit b785ad9

Please sign in to comment.