Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default value of MaxIdleConnections in net2.ConnectionPool is extremely slow #261

Open
gugu opened this issue Aug 16, 2023 · 0 comments
Open

Comments

@gugu
Copy link

gugu commented Aug 16, 2023

Benchmark results:

Fake dealer:
BenchmarkGetConnection-16           	 1492227	       803.2 ns/op
BenchmarkGetConnectionMaxIdle-16    	 1888982	       631.4 ns/op
Real dealer:
BenchmarkGetConnection-16           	    9052	    113356 ns/op
BenchmarkGetConnectionMaxIdle-16    	 1901071	       626.9 ns/op

Code example:

func BenchmarkGetConnection(b *testing.B) {
        // dialer := fakeDialer{}
        // mockClock := time2.MockClock{}

        options := ConnectionOptions{
                // MaxIdleConnections: 1,
                // Dial:               dialer.FakeDial,
                // NowFunc:            mockClock.Now,
        }

        pool := NewSimpleConnectionPool(options)
        pool.Register("tcp", "localhost:11211")
        b.ResetTimer();
        for i := 0; i < b.N; i++ {
                c, err := pool.Get("tcp", "localhost:6379")
                if err != nil {
                        b.Fatal(err)
                }
                c.ReleaseConnection()
        }
}

func BenchmarkGetConnectionMaxIdle(b *testing.B) {
        // dialer := fakeDialer{}
        // mockClock := time2.MockClock{}

        options := ConnectionOptions{
                MaxIdleConnections: 1,
                // Dial:               dialer.FakeDial,
                // NowFunc:            mockClock.Now,
        }

        pool := NewSimpleConnectionPool(options)
        pool.Register("tcp", "localhost:11211")
        b.ResetTimer();
        for i := 0; i < b.N; i++ {
                c, err := pool.Get("tcp", "localhost:6379")
                if err != nil {
                        b.Fatal(err)
                }
                c.ReleaseConnection()
        }
}
@gugu gugu changed the title 10x slowdown if memcached shard manager used Default value of MaxIdleConnections in net2.ConnectionPool slows down memcached client 10x times Aug 17, 2023
@gugu gugu changed the title Default value of MaxIdleConnections in net2.ConnectionPool slows down memcached client 10x times Default value of MaxIdleConnections in net2.ConnectionPool is extremely slow Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant