linux - The number of connections is only 2 when the redis connection pool is applied under 10,000 concurrency?
仅有的幸福
仅有的幸福 2017-05-16 13:18:32
0
1
1008

As shown in the picture, I used golang's redigo library to write a redis connection pool, and used ab test to simulate 10,000 concurrent read operations. However, no matter how redis refreshes the info, the number of connections is always 2, and at most it only displays 4. However, there are more than 60 connections using write operations. At the same time, netstat-ano shows that there are indeed a large number of TCP connections in the TIME_WAIT state occurring on the remote 127.0.0.1:6379. What is the reason for this? (The maximum number of connections in the redis configuration is 10000)

(Please ignore the netstat window on the right. It was just that I didn’t take the screenshot properly. In fact, I found and filtered it myself and there were indeed a large number of TCP connections in the TIME_WAIT state occurring on the remote 127.0.0.1:6379)

PS: Another question is why the maximum -c parameter of the ab test program can only be 10,000. I entered 100,000 to directly display the help document. . .

仅有的幸福
仅有的幸福

reply all(1)
phpcn_u1582

Think the connection pool is not occupied?

Write like this

package main

import "github.com/garyburd/redigo/redis"
import (
    "flag"
    "fmt"
    "time"
)

func newPool(addr string) *redis.Pool {
    return &redis.Pool{
        MaxIdle:     30,
        IdleTimeout: 240 * time.Second,
        Dial:        func() (redis.Conn, error) { return redis.Dial("tcp", addr) },
    }
}

var (
    pool        *redis.Pool
    redisServer = flag.String("redisServer", ":6379", "")
)

func main() {
    flag.Parse()
    pool = newPool(*redisServer)
    fmt.Println(pool)
    conn := pool.Get()
    conn2 := pool.Get()
    conn3 := pool.Get()
    conn4 := pool.Get()
    conn.Do("get", "a")
    conn2.Do("get", "a")
    conn3.Do("get", "a")
    conn4.Do("get", "a")
    //这里使劲加connX,就能看到效果了
    //defer conn.Close()
    //defer conn2.Close()
    //defer conn3.Close()
    //defer conn4.Close()

    time.Sleep(100 * time.Second)
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template