Skip to content

Commit

Permalink
expose and run GC for nodejs to avoid memory intensive actions to run…
Browse files Browse the repository at this point in the history
… in memory limit (#1826)

Expose garbage collection so that it is explicitly available for use in actions
  • Loading branch information
jeremiaswerner authored and Justin Berstler committed May 19, 2017
1 parent aee7958 commit 5a7467a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/nodejs6Action/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ xmlhttprequest@1.8.0 \
yauzl@2.7.0

# See app.js
CMD node app.js
CMD node --expose-gc app.js
13 changes: 13 additions & 0 deletions tests/dat/actions/memoryWithGC.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function eat(memoryMB) {
var bytes = 1*1024*1024*memoryMB;
var buffer = new Buffer.alloc(bytes, 'a');
buffer = null;
console.log('done.');
}

function main(msg) {
console.log('helloEatMemory', 'memory ' + msg.payload + 'MB');
global.gc();
eat(msg.payload);
return {msg: 'OK, buffer of size ' + msg.payload + ' MB has been filled.'};
}
20 changes: 20 additions & 0 deletions tests/src/test/scala/whisk/core/limits/ActionLimitsTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,24 @@ class ActionLimitsTests extends TestHelpers with WskTestHelpers {
}.length shouldBe 1
}
}

it should "be able to run memory intensive actions multiple times by running the GC in the action" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>
val name = "TestNodeJsMemoryActionAbleToRunOften"
assetHelper.withCleaner(wsk.action, name, confirmDelete = true) {
val allowedMemory = 512 megabytes
val actionName = TestUtils.getTestActionFilename("memoryWithGC.js")
(action, _) => action.create(name, Some(actionName), memory = Some(allowedMemory))
}

for( a <- 1 to 10){
val run = wsk.action.invoke(name, Map("payload" -> "128".toJson))
withActivation(wsk.activation, run) { response =>
response.response.status shouldBe "success"
response.response.result shouldBe Some(JsObject(
"msg" -> "OK, buffer of size 128 MB has been filled.".toJson))
}
}
}

}

0 comments on commit 5a7467a

Please sign in to comment.