forked from redis/go-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move benchmark to relevant package. Added bench task
- Loading branch information
1 parent
3f9a836
commit 900913d
Showing
4 changed files
with
89 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package pool_test | ||
|
||
import ( | ||
"errors" | ||
"net" | ||
"testing" | ||
"time" | ||
|
||
"gopkg.in/redis.v3/internal/pool" | ||
) | ||
|
||
func benchmarkPoolGetPut(b *testing.B, poolSize int) { | ||
dial := func() (net.Conn, error) { | ||
return &net.TCPConn{}, nil | ||
} | ||
pool := pool.NewConnPool(dial, poolSize, time.Second, 0) | ||
pool.DialLimiter = nil | ||
|
||
b.ResetTimer() | ||
|
||
b.RunParallel(func(pb *testing.PB) { | ||
for pb.Next() { | ||
conn, _, err := pool.Get() | ||
if err != nil { | ||
b.Fatalf("no error expected on pool.Get but received: %s", err.Error()) | ||
} | ||
if err = pool.Put(conn); err != nil { | ||
b.Fatalf("no error expected on pool.Put but received: %s", err.Error()) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
func BenchmarkPoolGetPut10Conns(b *testing.B) { | ||
benchmarkPoolGetPut(b, 10) | ||
} | ||
|
||
func BenchmarkPoolGetPut100Conns(b *testing.B) { | ||
benchmarkPoolGetPut(b, 100) | ||
} | ||
|
||
func BenchmarkPoolGetPut1000Conns(b *testing.B) { | ||
benchmarkPoolGetPut(b, 1000) | ||
} | ||
|
||
func benchmarkPoolGetReplace(b *testing.B, poolSize int) { | ||
dial := func() (net.Conn, error) { | ||
return &net.TCPConn{}, nil | ||
} | ||
pool := pool.NewConnPool(dial, poolSize, time.Second, 0) | ||
pool.DialLimiter = nil | ||
|
||
removeReason := errors.New("benchmark") | ||
|
||
b.ResetTimer() | ||
|
||
b.RunParallel(func(pb *testing.PB) { | ||
for pb.Next() { | ||
conn, _, err := pool.Get() | ||
if err != nil { | ||
b.Fatalf("no error expected on pool.Get but received: %s", err.Error()) | ||
} | ||
if err = pool.Replace(conn, removeReason); err != nil { | ||
b.Fatalf("no error expected on pool.Remove but received: %s", err.Error()) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
func BenchmarkPoolGetReplace10Conns(b *testing.B) { | ||
benchmarkPoolGetReplace(b, 10) | ||
} | ||
|
||
func BenchmarkPoolGetReplace100Conns(b *testing.B) { | ||
benchmarkPoolGetReplace(b, 100) | ||
} | ||
|
||
func BenchmarkPoolGetReplace1000Conns(b *testing.B) { | ||
benchmarkPoolGetReplace(b, 1000) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters