Skip to content

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

Description

@gugu

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()
        }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions