Skip to content

Instantly share code, notes, and snippets.

@dchapkine
Last active August 1, 2016 06:00
Show Gist options
  • Save dchapkine/015cf0967a68964cf27c7d94ca66eb13 to your computer and use it in GitHub Desktop.
Save dchapkine/015cf0967a68964cf27c7d94ca66eb13 to your computer and use it in GitHub Desktop.
Tests (ignore it)
var http = require('http');
var os = require("os");
var hostname = os.hostname();
var pid = process.pid;
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Node example works [V2] @"+hostname+"/"+pid+" \n");
});
server.listen(8080, "0.0.0.0");
console.log("Server running ...");
var http = require('http');
var os = require("os");
var hostname = os.hostname();
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Node example works @"+hostname+" \n");
});
server.listen(8080, "0.0.0.0");
console.log("Server running ...");
var http = require('http');
var os = require("os");
var hostname = os.hostname();
var pid = process.pid;
var hits = 0;
var server = http.createServer(function (request, response) {
hits++;
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Node example works [V2] @"+hostname+"/"+pid+" #"+hits+" \n");
console.log("#"+hits);
});
server.listen(8080, "0.0.0.0");
console.log("Server running ...");
var http = require('http');
var os = require("os");
var hostname = os.hostname();
var pid = process.pid;
var hits = 0;
var hitsPerInterval = 0;
setInterval(function(){
hitsPerInterval = 0;
}, 1000);
var server = http.createServer(function (request, response) {
hits++;
// let's say our load balancer we are not happy to get 50 req per node per second
if (hitsPerInterval > 50)
{
response.writeHead(429, {"Content-Type": "text/plain"});
response.end("\n");
}
else
{
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Node example works [V2] @"+hostname+"/"+pid+" #"+hits+" \n");
console.log("#"+hits);
}
});
server.listen(8080, "0.0.0.0");
console.log("Server running ...");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment