squeaky-pl / japronto

Screaming-fast Python 3.5+ HTTP toolkit integrated with pipelining HTTP server based on uvloop and picohttpparser.
MIT License
8.61k stars 581 forks source link

Fix Golang code for Benchmark #83

Closed rebootcode closed 7 years ago

rebootcode commented 7 years ago

Please fix the golang code for benchmark purpose -

package main
import (
    "net/http"
)

func main() {
    http.HandleFunc("/", func hello(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("Hello world!"))
        })
    http.ListenAndServe("0.0.0.0:8080", nil)
}

Use Above code and please test the bechmark of golang with japronto. Same goes with fasthttp

squeaky-pl commented 7 years ago

This was discussed many times. The benchmark purpose is comparing single-core performance. Anyway if you are looking for multi core numbers these were done: https://github.com/squeaky-pl/japronto/pull/14

rebootcode commented 7 years ago

@squeaky-pl - Are you serious ? Above code is single-core performance. But using unwated if code unwanted variable creation.

package main
import "net/http"

/*
** Below Code is not required .
var (
    helloResp    = []byte("Hello world!")
    notFoundResp = []byte("Not Found")
)
*/
func hello(w http.ResponseWriter, r *http.Request) {

/*
* ===   Seriously ???  Why did you forget more of "if" with    if r.URL.Path != "404"
* === , "500", "401" and all other variant too  ====   This is un wanted call below.

    if r.URL.Path != "/" {
        w.WriteHeader(http.StatusNotFound)
        w.Write(notFoundResp)
        return
    }

*/

// You can simply call []byte("Hello World") here without any variable creation. 

//  w.Write(helloResp)

w.Write([]byte("Hello World"))
}

func main() {
        // You can call `func` right here inside `HandleFunc` but many people prefer to use same way. 
       // So, i will leave that as it is.
    http.HandleFunc("/", hello)
    http.ListenAndServe("0.0.0.0:8080", nil)
}

Above is your code . Can you see difference ?? Doing same work running on "single-core performance" but code and performance will vary a lot.

Especially when getting nodejs result as closer to golang itself looks funny.

squeaky-pl commented 7 years ago

Please compare this with other benchmarks, they all have the same logic for 404. Go won't do this by default so it needs to be added. Otherwise it is unfair. Also reading a global variable will be faster because it reduces pressure on Go garbage collector.

squeaky-pl commented 7 years ago

The particular global variable change was done here: https://github.com/squeaky-pl/japronto/pull/12/files and measured 18% speed up for Go.