This repository was archived by the owner on Jun 18, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathloop.js
More file actions
54 lines (48 loc) · 1.5 KB
/
loop.js
File metadata and controls
54 lines (48 loc) · 1.5 KB
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
// Example - geneation of Nodereport via signal for a looping application
require('nodereport').setEvents('signal');
var http = require('http');
var count = 0;
function my_listener(request, response) {
switch(count++) {
case 0:
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write('\nRunning NodeReport looping application demo. Node process ID = ' + process.pid);
response.write('\n\nRefresh page to enter loop, then use \'kill -USR2 ' + process.pid + '\' to trigger NodeReport');
response.end();
break;
case 1:
console.log('loop.js: going to loop now, use \'kill -USR2 ' + process.pid + '\' to trigger NodeReport');
var list = [];
var j='';
for (var i=0; i<10000000000; i++) {
for (j=0; i<1000; i++) {
list.push(new MyRecord());
}
for (j=0; i<1000; i++) {
list[j].id += 1;
list[j].account += 2;
}
for (j=0; i<1000; i++) {
list.pop();
}
}
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write('\nNodeReport demo.... finished looping');
response.end();
break;
default:
}
}
function MyRecord() {
this.name = 'foo';
this.id = 128;
this.account = 98454324;
}
var http_server = http.createServer(my_listener);
http_server.listen(8080);
console.log('loop.js: Node running');
console.log('loop.js: Go to http://<machine>:8080/ or http://localhost:8080/');
setTimeout(function() {
console.log('loop.js: timeout expired, exiting.');
process.exit(0);
}, 60000);