-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: options for shrink cooldown on worker starter (#101)
* feat: options for shrink cooldown on worker starter
- Loading branch information
Showing
5 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/control_plane/__test__/e2e/ema_startup_shrink_cooldown.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import * as common from '#self/test/common'; | ||
import { baselineDir } from '#self/test/common'; | ||
import assert from 'assert'; | ||
import { bufferFromStream, sleep } from '#self/lib/util'; | ||
import { DefaultEnvironment } from '#self/test/env/environment'; | ||
|
||
describe(common.testName(__filename), function () { | ||
// Debug version of Node.js may take longer time to bootstrap. | ||
this.timeout(30_000); | ||
|
||
const env = new DefaultEnvironment({ | ||
createTestClock: true, | ||
config: common.extendDefaultConfig({ | ||
virtualMemoryPoolSize: '4gb', | ||
controlPlane: { | ||
useEmaScaling: true, | ||
workerTrafficStatsPullingMs: 1000, | ||
}, | ||
}), | ||
}); | ||
|
||
it('first shrink should work on request finish', async () => { | ||
await env.agent.setFunctionProfile([ | ||
{ | ||
name: 'aworker_echo_ema', | ||
runtime: 'aworker', | ||
url: `file://${baselineDir}/aworker_echo`, | ||
sourceFile: 'index.js', | ||
signature: 'md5:234234', | ||
worker: { | ||
maxActivateRequests: 1, | ||
shrinkCooldownOnStartup: false, | ||
}, | ||
resourceLimit: { | ||
memory: 200 * 1024 * 1024, | ||
}, | ||
}, | ||
]); | ||
|
||
const statManager = env.control._ctx.getInstance('stateManager'); | ||
|
||
await request('aworker_echo_ema', env); | ||
|
||
const brokerBefore = statManager.getBroker('aworker_echo_ema', false); | ||
|
||
assert(brokerBefore?.workerCount === 1); | ||
|
||
await sleep(10000); | ||
|
||
const brokerAfter = statManager.getBroker('aworker_echo_ema', false); | ||
assert(brokerAfter == null); | ||
}); | ||
|
||
it('first shrink should cooldown on request finish when shrinkCooldownOnStartup=true', async () => { | ||
await env.agent.setFunctionProfile([ | ||
{ | ||
name: 'aworker_echo_ema', | ||
runtime: 'aworker', | ||
url: `file://${baselineDir}/aworker_echo`, | ||
sourceFile: 'index.js', | ||
signature: 'md5:234234', | ||
worker: { | ||
maxActivateRequests: 1, | ||
shrinkCooldownOnStartup: true, | ||
}, | ||
resourceLimit: { | ||
memory: 200 * 1024 * 1024, | ||
}, | ||
}, | ||
]); | ||
|
||
const statManager = env.control._ctx.getInstance('stateManager'); | ||
|
||
await request('aworker_echo_ema', env); | ||
|
||
const brokerBefore = statManager.getBroker('aworker_echo_ema', false); | ||
|
||
assert(brokerBefore?.workerCount === 1); | ||
|
||
await sleep(10000); | ||
|
||
const brokerAfter = statManager.getBroker('aworker_echo_ema', false); | ||
assert(brokerAfter?.workerCount === 1); | ||
}); | ||
}); | ||
|
||
async function request(functionName: string, env: DefaultEnvironment) { | ||
const data = Buffer.from('200'); | ||
|
||
const response = await env.agent.invoke(functionName, data, { | ||
method: 'POST', | ||
}); | ||
|
||
assert.strictEqual(response.status, 200); | ||
|
||
return await bufferFromStream(response); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters