Skip to content

Instantly share code, notes, and snippets.

@codeboost
Created May 17, 2012 23:01
Show Gist options
  • Save codeboost/2722169 to your computer and use it in GitHub Desktop.
Save codeboost/2722169 to your computer and use it in GitHub Desktop.
Source code for test scripts
package main
import (
"net/http"
"log"
"fmt"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
fmt.Fprintf(w, "Hello, World\r\n")
})
log.Printf("Server running at http://127.0.0.1:1337/")
http.ListenAndServe("0.0.0.0:1337", nil)
}
var cluster = require('cluster');
var http = require('http');
var numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < numCPUs / 2; i++) {
cluster.fork();
}
cluster.on('death', function(worker) {
console.log('worker ' + worker.pid + ' died');
});
} else {
// Worker processes have a http server.
http.Server(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end("hello world\n");
}).listen(1338, '0.0.0.0');
}
console.log('Server running at http://127.0.0.1:1338/');
@codeboost
Copy link
Author

@khigia
Copy link

khigia commented May 20, 2012

Not sure how relevant it is, but note that GOMAXPROCS variable used to default to 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment