From 9c5def7f1f5424131b769a2a418f380f8b617b9d Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Fri, 27 Jul 2012 14:43:30 +0300 Subject: [PATCH] Fix imports. --- redis.go | 6 ++--- redis_test.go | 72 ++++++++++++++++++++++++++++++++++++++++++++++--- request.go | 2 +- request_test.go | 51 +++++++++++++++++++++++++++++++++++ 4 files changed, 123 insertions(+), 8 deletions(-) create mode 100644 request_test.go diff --git a/redis.go b/redis.go index 79a7b1cd..58d775e3 100644 --- a/redis.go +++ b/redis.go @@ -5,7 +5,7 @@ import ( "io" "sync" - "github.com/togoio/redisgoproxy/bufreader" + "github.com/vmihailenco/bufreader" ) type connectFunc func() (io.ReadWriter, error) @@ -27,7 +27,7 @@ type Client struct { func NewClient(connect connectFunc, disconnect disconnectFunc) *Client { return &Client{ - readerPool: bufreader.NewReaderPool(10, createReader), + readerPool: bufreader.NewReaderPool(100, createReader), connect: connect, disconnect: disconnect, } @@ -35,7 +35,7 @@ func NewClient(connect connectFunc, disconnect disconnectFunc) *Client { func NewMultiClient(connect connectFunc, disconnect disconnectFunc) *Client { return &Client{ - readerPool: bufreader.NewReaderPool(10, createReader), + readerPool: bufreader.NewReaderPool(100, createReader), connect: connect, disconnect: disconnect, diff --git a/redis_test.go b/redis_test.go index 95b448b0..1ed4af4f 100644 --- a/redis_test.go +++ b/redis_test.go @@ -3,12 +3,14 @@ package redis_test import ( "io" "net" + "strconv" "testing" "time" . "launchpad.net/gocheck" - "github.com/togoio/redisgoproxy/redis" + "github.com/vmihailenco/bufreader" + "github.com/vmihailenco/redis" ) //------------------------------------------------------------------------------ @@ -1166,20 +1168,82 @@ func (t *RedisTest) TestMultiExec(c *C) { //------------------------------------------------------------------------------ -func (t *RedisTest) BenchmarkPing(c *C) { +func (t *RedisTest) TestConcAccess(c *C) { + for i := int64(0); i < 99; i++ { + go func() { + msg := "echo" + strconv.FormatInt(i, 10) + echo, err := t.redisC.Echo(msg).Reply() + c.Check(err, IsNil) + c.Check(echo, Equals, msg) + }() + } +} + +//------------------------------------------------------------------------------ + +func (t *RedisTest) BenchmarkRedisPing(c *C) { + c.StopTimer() + + for i := 0; i < 10; i++ { + pong, err := t.redisC.Ping().Reply() + c.Check(err, IsNil) + c.Check(pong, Equals, "PONG") + } + + c.StartTimer() + for i := 0; i < c.N; i++ { t.redisC.Ping().Reply() } } -func (t *RedisTest) BenchmarkSet(c *C) { +func (t *RedisTest) BenchmarkRedisSet(c *C) { + c.StopTimer() + + for i := 0; i < 10; i++ { + ok, err := t.redisC.Set("foo", "bar").Reply() + c.Check(err, IsNil) + c.Check(ok, Equals, "OK") + } + + c.StartTimer() + for i := 0; i < c.N; i++ { t.redisC.Set("foo", "bar").Reply() } } -func (t *RedisTest) BenchmarkGet(c *C) { +func (t *RedisTest) BenchmarkRedisGet(c *C) { + c.StopTimer() + + for i := 0; i < 10; i++ { + v, err := t.redisC.Get("foo").Reply() + c.Check(err, Equals, redis.Nil) + c.Check(v, Equals, "") + } + + c.StartTimer() + for i := 0; i < c.N; i++ { t.redisC.Get("foo").Reply() } } + +func (t *RedisTest) BenchmarkRedisWriteRead(c *C) { + c.StopTimer() + + req := []byte("PING\r\n") + rd := bufreader.NewSizedReader(1024) + + for i := 0; i < 10; i++ { + err := t.redisC.WriteRead(req, rd) + c.Check(err, IsNil) + c.Check(rd.Bytes(), DeepEquals, []byte("+PONG\r\n")) + } + + c.StartTimer() + + for i := 0; i < c.N; i++ { + t.redisC.WriteRead(req, rd) + } +} diff --git a/request.go b/request.go index 72150091..c9af41ea 100644 --- a/request.go +++ b/request.go @@ -6,7 +6,7 @@ import ( "io" "strconv" - "github.com/togoio/redisgoproxy/bufreader" + "github.com/vmihailenco/bufreader" ) var Nil = errors.New("(nil)") diff --git a/request_test.go b/request_test.go new file mode 100644 index 00000000..23a3fac4 --- /dev/null +++ b/request_test.go @@ -0,0 +1,51 @@ +package redis_test + +import ( + "github.com/vmihailenco/bufreader" + . "launchpad.net/gocheck" + + "github.com/vmihailenco/redis" +) + +//------------------------------------------------------------------------------ + +type RequestTest struct{} + +var _ = Suite(&RequestTest{}) + +//------------------------------------------------------------------------------ + +func (t *RequestTest) SetUpTest(c *C) {} + +func (t *RequestTest) TearDownTest(c *C) {} + +//------------------------------------------------------------------------------ + +func (t *RequestTest) BenchmarkStatusReq(c *C) { + c.StopTimer() + + rd := bufreader.NewSizedReader(1024) + rd.Set([]byte("+OK\r\n")) + req := redis.NewStatusReq() + + for i := 0; i < 10; i++ { + rd.ResetPos() + vI, err := req.ParseReply(rd) + c.Check(err, IsNil) + c.Check(vI, Equals, "OK") + + req.SetVal(vI) + v, err := req.Reply() + c.Check(err, IsNil) + c.Check(v, Equals, "OK") + } + + c.StartTimer() + + for i := 0; i < c.N; i++ { + rd.ResetPos() + v, _ := req.ParseReply(rd) + req.SetVal(v) + req.Reply() + } +}