globalsign / mgo

The MongoDB driver for Go
Other
1.97k stars 230 forks source link

Setting the maxPoolSize has no effect #336

Closed tokingHong closed 5 years ago

tokingHong commented 5 years ago

before test image image no connections

func TestUserRepository_GetUserList(t *testing.T) {
    session ,_ =  mgo.Dial("mongodb://10.124.203.14:27017/user?maxPoolSize=10")
    session.SetPoolLimit(10)
    for i:=0;i<300;i++ {
        //time.Sleep(time.Millisecond*2)
          go func() {
            var xx []interface{}
            copySession := session.Clone()
            copySession.DB("user").C("user").Find(nil).All(&xx)
            copySession.Close()
            utils.Debugf("xxx")
          }()
    }
    //time.Sleep(10*time.Second)
    select {

    }
}

image image

Why the maxPoolSize had no effect?

go version 1.10 mgo is latest

domodwyer commented 5 years ago

Hi @tokingHong

Cloning a session is documented to reuse the same socket:

Clone works just like Copy, but also reuses the same socket as the original session

I guess your connections are coming from somewhere else?

I'm going to close this, feel free to reply if you think it is definitely a mgo issue though! Dom

tokingHong commented 5 years ago

@domodwyer You can check my code and have a test :)