Skip to content

Instantly share code, notes, and snippets.

@thekvs
Created June 26, 2018 17:00
Show Gist options
  • Save thekvs/7f65e2870c649d8ae0e0dcbeff629ef8 to your computer and use it in GitHub Desktop.
Save thekvs/7f65e2870c649d8ae0e0dcbeff629ef8 to your computer and use it in GitHub Desktop.
package main
import (
"net/http"
"runtime"
)
func cpuEater() {
var counter uint64
for {
counter += 1
if counter == 0xfffffffffffffffe {
counter = 0
}
runtime.Gosched()
}
}
func handler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello World!"))
}
func main() {
for i := 0; i < runtime.NumCPU(); i++ {
go cpuEater()
}
http.HandleFunc("/", handler)
if err := http.ListenAndServe(":8080", nil); err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment