From 8592324a2fe722c6b748aad0e8b43795fa42b6a8 Mon Sep 17 00:00:00 2001 From: siddontang Date: Thu, 12 Jun 2014 14:10:29 +0800 Subject: [PATCH 1/3] optimize access log --- server/accesslog.go | 18 ++++-------------- server/client.go | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/server/accesslog.go b/server/accesslog.go index 58b34b7..9e517a8 100644 --- a/server/accesslog.go +++ b/server/accesslog.go @@ -1,9 +1,7 @@ package server import ( - "fmt" "github.com/siddontang/go-log/log" - "strings" ) const ( @@ -31,21 +29,13 @@ func (l *accessLog) Close() { l.l.Close() } -func (l *accessLog) Log(remoteAddr string, usedTime int64, cmd string, args [][]byte, err error) { - argsFormat := make([]string, len(args)) - argsI := make([]interface{}, len(args)) - for i := range args { - argsFormat[i] = " %.24q" - argsI[i] = args[i] - } +func (l *accessLog) Log(remoteAddr string, usedTime int64, request []byte, err error) { - argsStr := fmt.Sprintf(strings.Join(argsFormat, ""), argsI...) - - format := `%s [%s%s] %d [%s]` + format := `%s %q %d [%s]` if err == nil { - l.l.Info(format, remoteAddr, cmd, argsStr, usedTime, "OK") + l.l.Info(format, remoteAddr, request, usedTime, "OK") } else { - l.l.Info(format, remoteAddr, cmd, argsStr, usedTime, err.Error()) + l.l.Info(format, remoteAddr, request, usedTime, err.Error()) } } diff --git a/server/client.go b/server/client.go index ca3d72d..3f5c43c 100644 --- a/server/client.go +++ b/server/client.go @@ -32,6 +32,8 @@ type client struct { reqC chan error syncBuf bytes.Buffer + + logBuf bytes.Buffer } func newClient(c net.Conn, app *App) { @@ -158,7 +160,22 @@ func (c *client) handleRequest(req [][]byte) { duration := time.Since(start) if c.app.access != nil { - c.app.access.Log(c.c.RemoteAddr().String(), duration.Nanoseconds()/1000000, c.cmd, c.args, err) + c.logBuf.Reset() + for i, r := range req { + left := 256 - c.logBuf.Len() + if left <= 0 { + break + } else if len(r) <= left { + c.logBuf.Write(r) + if i != len(req)-1 { + c.logBuf.WriteByte(' ') + } + } else { + c.logBuf.Write(r[0:left]) + } + } + + c.app.access.Log(c.c.RemoteAddr().String(), duration.Nanoseconds()/1000000, c.logBuf.Bytes(), err) } if err != nil { From a7f91cfdc9c8b86de1ef37c5a2186461cf85ec7c Mon Sep 17 00:00:00 2001 From: siddontang Date: Thu, 12 Jun 2014 15:56:04 +0800 Subject: [PATCH 2/3] update read me --- README.md | 30 ++++++++++++++++++++++++++++-- README_CN.md | 29 +++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5f47c44..c6ee704 100644 --- a/README.md +++ b/README.md @@ -33,14 +33,40 @@ Ledisdb is a high performance nosql like redis based on leveldb written by go. I ./ledis-server -config=/etc/ledis.json + //another shell + redis-cli -p 6380 + + redis 127.0.0.1:6380> set a 1 + OK + redis 127.0.0.1:6380> get a + "1" + +## Lib + + import "github.com/siddontang/ledisdb/ledis" + l, _ := ledis.OpenWithConfig(cfg) + db, _ := l.Select(0) + + db.Set(key, value) + + db.Get(key) + + +## Replication + +set slaveof in config or dynamiclly + + redis-cli -p 6381 + + redis 127.0.0.1:6381> slaveof 127.0.0.1:6380 + OK + ## Benchmark See benchmark.md for more. ## Todo -+ Expire + TTL -+ Replication + Admin ## Feedback diff --git a/README_CN.md b/README_CN.md index a017dd1..b61de43 100644 --- a/README_CN.md +++ b/README_CN.md @@ -40,14 +40,39 @@ ledisdb是一个用go实现的类似redis的高性能nosql数据库,底层基 ./ledis-server -config=/etc/ledis.json + //another shell + redis-cli -p 6380 + + redis 127.0.0.1:6380> set a 1 + OK + redis 127.0.0.1:6380> get a + "1" + +## 嵌入库 + + import "github.com/siddontang/ledisdb/ledis" + l, _ := ledis.OpenWithConfig(cfg) + db, _ := l.Select(0) + + db.Set(key, value) + + db.Get(key) + ## Benchmark 可以通过查看benchmark.md获取最新的性能测试结果 +## Replication + +通过配置或者运行时输入slaveof开启slave的replication功能 + + redis-cli -p 6381 + + redis 127.0.0.1:6381> slaveof 127.0.0.1:6380 + OK + ## Todo -+ Expire + TTL -+ Replication + Admin ## 联系我 From b4d5c609c876e1d4eda7cb8f764f95c1bd96c9c5 Mon Sep 17 00:00:00 2001 From: siddontang Date: Thu, 12 Jun 2014 15:58:50 +0800 Subject: [PATCH 3/3] update read me --- README.md | 4 ++++ README_CN.md | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c6ee704..300049c 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,10 @@ See benchmark.md for more. + Admin +## Thanks + +Gamil: cenqichao@gmail.com + ## Feedback Gmail: siddontang@gmail.com \ No newline at end of file diff --git a/README_CN.md b/README_CN.md index b61de43..6404574 100644 --- a/README_CN.md +++ b/README_CN.md @@ -70,11 +70,15 @@ ledisdb是一个用go实现的类似redis的高性能nosql数据库,底层基 redis 127.0.0.1:6381> slaveof 127.0.0.1:6380 OK - + ## Todo + Admin +## 感谢 + +Gamil: cenqichao@gmail.com + ## 联系我 Gmail: siddontang@gmail.com \ No newline at end of file