goplus / gop

The Go+ programming language is designed for engineering, STEM education, and data science. Our vision is to enable everyone to become a builder of the digital world.
https://goplus.org
Apache License 2.0
8.96k stars 547 forks source link

Q的http包进行压力测试的时候发现会崩溃 #127

Closed insionng closed 8 years ago

insionng commented 8 years ago

测试的Q代码:

package main

import (
    "fmt"

    "qlang.io/cl/qlang"
    _ "qlang.io/qlang/builtin"
    "qlang.io/qlang/net/http"
)

func main() {

    qlang.Import("http", http.Exports)
    q := qlang.New()

    err := q.SafeExec([]byte(`
mux = http.serveMux()
mux.handle("/404", http.notFoundHandler())
mux.handleFunc("/", fn(w, req) {
    fprintln(w, "host:", req.host, "path:", req.URL)
})

err = http.listenAndServe(":8000", mux)
if err != nil {
    fprintln(os.stderr, err)
}
`), "")
    if err != nil {
        fmt.Println(err)
        return
    }

}

结果:

wrk -c10 -d20s -t8 http://localhost:8000
Running 20s test @ http://localhost:8000
  8 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    41.87us  575.52us  45.73ms   99.90%
    Req/Sec     3.80k     4.83k   32.71k    82.74%
  595222 requests in 20.01s, 82.87MB read
  Socket errors: connect 0, read 4773, write 0, timeout 0
Requests/sec:  29740.43
Transfer/sec:      4.14MB

Go的实现的测试代码:

package main

import (
    "fmt"
    "net/http"
    "os"
)

func main() {
    mux := http.NewServeMux()
    mux.Handle("/404", http.NotFoundHandler())
    mux.HandleFunc("/", func(resw http.ResponseWriter, req *http.Request) {
        fmt.Fprintln(resw, "host:", req.Host, "path:", req.URL)
    })

    err := http.ListenAndServe(":8000", mux)
    if err != nil {
        fmt.Fprintln(os.Stderr, err)
    }

}
wrk -c10 -d20s -t8 http://localhost:8000
Running 20s test @ http://localhost:8000
  8 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    54.05us  138.85us   9.72ms   97.92%
    Req/Sec    22.79k     1.22k   25.79k    65.05%
  3646295 requests in 20.10s, 507.70MB read
Requests/sec: 181409.20
Transfer/sec:     25.26MB

不奢求Q的性能有多好,但求不要崩溃就行了...

insionng commented 8 years ago

错误太长了,超出了GITHUB的限制,就不发上来了~

xushiwei commented 8 years ago

这个属于并发bug,实际上由于 Go 代码的回调可能来自新的 goroutine 导致 处理中...