0

Here is my code

func BenchmarkParallelGetSet(b *B) {
    parallel := runtime.GOMAXPROCS(0) * 8

    b.Run("redigo", func(b *B) {
        do(b, func() {
            conn := red.Get()
            //defer conn.Close()
            v, err := conn.Do("SET", "foo", "bar")
            if err != nil {
                fmt.Println(err)
                return
            }
            fmt.Println(v)
            v, err = redis.String(conn.Do("GET", "foo"))
            if err != nil {
                fmt.Println(err)
                return
            }
            fmt.Println(v)
        })
    })
}


func newPool(MaxIdle int) *redis.Pool {
    return &redis.Pool{
        MaxIdle:     MaxIdle,
        IdleTimeout: 240 * time.Second,
        Dial: func() (redis.Conn, error) {
            c, err := redis.Dial("tcp", "127.0.0.1:6379")
            if err != nil {
                return nil, err
            }
            return c, err;
        },
        TestOnBorrow: func(c redis.Conn, t time.Time) error {
            if time.Since(t) < time.Minute {
                return nil
            }
            _, err := c.Do("PING")
            return err
        },
    }
}

Error is

--- FAIL: BenchmarkParallelGetSet/redigo-8
    bench_test.go:192: read tcp 127.0.0.1:51701->127.0.0.1:6379: read: connection reset by peer

What's wrong with this? Any help is needed, thanks.

Ullaakut
  • 3,554
  • 2
  • 19
  • 34
user3051532
  • 9
  • 1
  • 2
  • 2
    Hi, welcome to Stackoverflow. Two comments. First, "connection reset by peer" means that the connection was closed by the Redis server end. You should check any logging or metrics there first. Secondly, although you've given some source code (good) you haven't said which line "bench_test:192" is or how long it takes to do this. Hope this helps, please update your question if you need more pointers from SO – Vorsprung Jan 31 '19 at 12:01
  • In majority of the cases it's because your redis server got restarted (post a crash perhaps), in which case it drops any active sockets/connections. – darkdefender27 Nov 19 '19 at 06:10
  • The program leaks connections because the call to `conn.Close()` is commented out. – Charlie Tumahai Jun 26 '21 at 17:09

0 Answers0