Skip to content

Instantly share code, notes, and snippets.

@redjade
Last active May 30, 2018 07:32
Show Gist options
  • Save redjade/23034f913000954a21e9473ff8172233 to your computer and use it in GitHub Desktop.
Save redjade/23034f913000954a21e9473ff8172233 to your computer and use it in GitHub Desktop.
GOMAXPROCS
package main
import (
"fmt"
"log"
"net/http"
"time"
"runtime"
)
func main() {
/*
* print default GOMAXPROCS. See below.
* - https://golang.org/pkg/runtime/#GOMAXPROCS
* - https://docs.google.com/document/d/1At2Ls5_fhJQ59kDK2DFVhFu3g5mATSXqqV5QrxinasI/edit
* - https://dave.cheney.net/tag/gomaxprocs
* - https://morsmachine.dk/go-scheduler
*/
fmt.Printf("current GOMAXPROCS is %d\n", runtime.GOMAXPROCS(0))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if len(r.FormValue("case-two")) > 0 {
// when using http://localhost:8000/?case-two=true
fmt.Println("case two")
} else {
// when using http://localhost:8000/
fmt.Println("case one start")
time.Sleep(time.Second * 5)
fmt.Println("case one end")
}
})
if err := http.ListenAndServe(":8000", nil); err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment