返回 CodeWhale
index.mjs
1 export const inject = ['tools']
2 export function apply(ctx) {
3 ctx.tools.register({ name: 'memory_hog', description: 'Allocate and touch memory, 64 MiB at a time.',
4 parameters: { type: 'object', properties: { mib: { type: 'number' } } },
5 async execute(args) {
6 // Buffers live outside the JS heap, so Node's --max-old-space-size does
7 // not bound them: only the OS-level cap does.
8 const chunks = []
9 while (chunks.length * 64 < args.mib) {
10 chunks.push(Buffer.alloc(64 * 1024 * 1024, 1))
11 await new Promise((resolve) => setTimeout(resolve, 5))
12 }
13 return { allocated_mib: chunks.length * 64 }
14 },
15 })
16 }
17
17 lines Plain Text