-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
64 lines (51 loc) · 1.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var os = require('os');
var fs = require('fs');
// Cloud Foundry App Instande Index
var index = parseInt(process.env.INSTANCE_INDEX);
var mem = [];
var disk = 0;
log('APP INDEX: ' + index);
var freeMemory = Math.round(os.freemem() / 1024 / 1024);
log('Free Memory: ' + freeMemory + ' MB');
var maxBlocks = 100;
schedule();
function schedule() {
setTimeout(doTask, 5000);
}
function log(msg) {
console.log('[' + index + '] ' + msg)
}
function doTask() {
// Task depends on which index we are
switch(index) {
case 1:
allocateMemory();
break;
case 2:
allocateDisk();
break;
default:
log('Looping....')
break;
}
schedule();
}
function allocateMemory() {
var maxBlocks = freeMemory;
log('Max Blocks: ' + maxBlocks);
log("Allocating memory.....");
// 0.5MB
// Each element in the array is 8 bytes
var block = new Array(1.5 * 1024 * 1024);
mem.push(block);
log("Allocated " + (mem.length) + " MB");
if(mem.length >= maxBlocks) {
mem = [];
log('Freeing allocated memory');
}
}
function allocateDisk() {
log("Allocating disk.....");
fs.writeFile('file_' + disk, new Buffer(24*1024*1024));
disk++;
}