cloudwego / hertz

Go HTTP framework with high-performance and strong-extensibility for building micro-services.
https://www.cloudwego.io
Apache License 2.0
5.36k stars 529 forks source link

Netpoll prints connection error when wrk stress test ends #23

Closed hiqsociety closed 2 years ago

hiqsociety commented 2 years ago

possible to show us how to test with wrk or apache bench? coz cant test against fasthttp etc. got this as response

2022/05/31 14:13:56 readv(fd=59) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=58) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=57) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=56) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=55) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=54) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=53) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=51) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=49) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=48) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=47) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=46) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=45) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=44) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=43) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=41) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=40) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=39) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=38) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=36) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=34) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=33) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=32) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=31) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=30) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=29) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=28) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=27) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=26) failed: connection reset by peer
2022/05/31 14:13:56 readv(fd=25) failed: connection reset by peer

ab -n 100 -c 100 http://127.0.0.1:8888/ This is ApacheBench, Version 2.3 <$Revision: 1843412 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)...apr_pollset_poll: The timeout specified has expired (70007)

welkeyever commented 2 years ago

To figure out what happen you may try to fire a single http request and check out the logs from both sides(client&server). Sorry for the tentative suggestion, maybe paste your server demo will help us reproduce the problem.

hiqsociety commented 2 years ago

try with wrk -t 1 -d 10 -c 100 http://127.0.0.1:8888/ error as mentioned

using golang 1.18.1 compiled with go build -ldflags "-w -s" main.go

 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package main

import (
        "context"
        "fmt"

        "github.com/cloudwego/hertz/pkg/app"
        "github.com/cloudwego/hertz/pkg/app/server"
        "github.com/cloudwego/hertz/pkg/common/utils"
        "github.com/cloudwego/hertz/pkg/protocol/consts"
)

type Test struct {
        A string
        B string
}

func main() {
        h := server.Default()
        h.GET("/", func(c context.Context, ctx *app.RequestContext) {
                fmt.Fprintf(ctx, "Hello, World!\n")
                //ctx.Redirect(consts.StatusMovedPermanently, []byte("http://www.google.com/"))
        })
        //h.StaticFS("/", &app.FS{Root: "./", GenerateIndexPages: true})

        h.GET("/ping", func(c context.Context, ctx *app.RequestContext) {
                ctx.JSON(consts.StatusOK, utils.H{"ping": "pong"})
        })

        h.GET("/json", func(c context.Context, ctx *app.RequestContext) {
                ctx.JSON(consts.StatusOK, &Test{
                        A: "aaa",
                        B: "bbb",
                })
        })

        h.GET("/redirect", func(c context.Context, ctx *app.RequestContext) {
                ctx.Redirect(consts.StatusMovedPermanently, []byte("http://www.google.com/"))
        })

        v1 := h.Group("/v1")
        {
                v1.GET("/hello/:name", func(c context.Context, ctx *app.RequestContext) {
                        fmt.Fprintf(ctx, "Hi %s, this is the response from Hertz.\n", ctx.Param("name"))
                })
        }

        h.Spin()
}
welkeyever commented 2 years ago

Got it! Thanks for your report. We will check on this.

welkeyever commented 2 years ago

I will remove the bug label here, coz the root cause behind this error is that wrk close connection rudely by just reset the connection. More info you could find here: https://github.com/wg/wrk/issues/360.

At this moment netpoll (the default network impl under hertz) will print this connection reset error directly. We will take a deep look at it and discuss a final solution for this kind of situation. For now you can just ignore the error here.

Thanks again for the report!

welkeyever commented 2 years ago

cc @Hchenn @joway

hiqsociety commented 2 years ago

it's not professional to say to ignore this. apache bench and wrk cannot show any results. in any case, this http stress testing doesnt work. any work arounds to stress test hertz now? doesnt make sense at all as i have tested so many that works.

welkeyever commented 2 years ago

Sorry, I forgot about the ab.

The reason that ab -n 100 -c 100 http://127.0.0.1:8888/ didn't return is that hertz does not close the connection after processing a non-keepalived request. I'll fix it, and for now you may add the -k flag to work around with it.

If it's still not working, pls let me know.

Duslia commented 2 years ago

Now you can use ab to benchmark Hertz with short connection.