Skip to content

Commit

Permalink
Merge pull request #1101 from cloudfoundry/more-gc
Browse files Browse the repository at this point in the history
Increase acceptance test memory usage threshold to 87 MB
  • Loading branch information
KevinJCross authored Nov 30, 2022
2 parents dbffea2 + 7324f52 commit 2a76184
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/acceptance/app/dynamic_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var _ = Describe("AutoScaler dynamic policy", func() {
Fail("There is not enough app memory in the app to run this test.\n - app resident size %d\n - app memory limit: %d\n - heap to use: %d", AppResidentSize, cfg.NodeMemoryLimit, int(heapToUse))
}

policy = GenerateDynamicScaleOutAndInPolicy(1, 2, "memoryused", 80, 80)
policy = GenerateDynamicScaleOutAndInPolicy(1, 2, "memoryused", 87, 87)
initialInstanceCount = 1
})

Expand Down
24 changes: 23 additions & 1 deletion src/acceptance/assets/app/nodeApp/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ let mfPassword = ''
const serviceName = process.env.SERVICE_NAME
let cpuWorkers = []
let memWorker = null
let timer = null

function gc () {
try {
if (global.gc) {
global.gc()
} else {
console.log('There is no gc exposed to the worker thread.')
}
} catch (e) {
console.log("Tried to garbage collect Failed please start with the option '--expose-gc'")
}
}

function getCredentials () {
// NOTE: the way we check for credentials existence might be further improved.
Expand Down Expand Up @@ -218,15 +231,20 @@ app.get('/memory/:megabytes/:minute', async function (req, res) {
}
megabytes = Math.max(1, megabytes)
memWorker.postMessage({ action: 'chew', totalMemoryUsage: megabytes, source: '/memory/:megabytes/:minute' })
setTimeout(async () => stopMemWorker('timer'), minute * 60 * 1000)
timer = setTimeout(async () => stopMemWorker('timer'), minute * 60 * 1000)
res.status(200).json({ result: 'success', msg: `using worker to allocate ${megabytes}MB of heap for ${minute} minutes` })
})

function stopMemWorker (src) {
if (timer) {
clearTimeout(timer)
timer = null
}
if (memWorker) {
memWorker.postMessage({ action: 'stop', source: src })
}
memWorker = null
gc()
}

function stopCpuWorkers (src) {
Expand Down Expand Up @@ -274,3 +292,7 @@ app.get('/cpu/close', async function (req, res) {
stopCpuWorkers()
res.status(200).json({ status: 'close cpu test' })
})

gc()


3 changes: 2 additions & 1 deletion src/acceptance/assets/app/nodeApp/mem_load.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ parentPort.on("message",(payload, node) => {
if (payload.action && payload.action === "chew") {
memoryHeld = chewMemory(payload.totalMemoryUsage)
} else {
memoryHeld = new List()
memoryHeld = null
gc()
console.log(`Mem: got a ${payload.action} freeing memory`)
process.exit()
gc()
}
})

Expand Down

0 comments on commit 2a76184

Please sign in to comment.