Last active
August 1, 2016 06:00
-
-
Save dchapkine/015cf0967a68964cf27c7d94ca66eb13 to your computer and use it in GitHub Desktop.
Tests (ignore it)
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
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 ..."); |
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
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 ..."); |
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
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 ..."); |
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
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