From 3c38beb62dccffaff1ddd16281b5694f1c91143f Mon Sep 17 00:00:00 2001 From: siddontang Date: Fri, 24 Oct 2014 23:20:42 +0800 Subject: [PATCH 1/5] update benchmark --- cmd/ledis-storebench/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/ledis-storebench/main.go b/cmd/ledis-storebench/main.go index 5493ee0..6d91a89 100644 --- a/cmd/ledis-storebench/main.go +++ b/cmd/ledis-storebench/main.go @@ -46,8 +46,8 @@ func bench(cmd string, f func()) { t2 := time.Now() d := t2.Sub(t1) - fmt.Printf("%s: %0.3f micros/op, %0.2fmb/s\n", cmd, float64(d.Nanoseconds()/1e3)/float64(*number), - float64((*valueSize+16)*(*number))/(1024.0*1024.0*(d.Seconds()))) + fmt.Printf("%s: %0.3f micros/op, %0.2fmb/s %0.2fop/s\n", cmd, float64(d.Nanoseconds()/1e3)/float64(*number), + float64((*valueSize+16)*(*number))/(1024.0*1024.0*(d.Seconds())), float64(*number)/d.Seconds()) } var kvSetBase int64 = 0 From 57d60b0ce019e060fd993e8ad994e7ff7c30de77 Mon Sep 17 00:00:00 2001 From: siddontang Date: Fri, 24 Oct 2014 23:30:27 +0800 Subject: [PATCH 2/5] add disable wal config for rocksdb --- config/config.go | 2 ++ config/config.toml | 5 ++++- etc/ledis.conf | 5 ++++- store/rocksdb/db.go | 2 ++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index 72c3105..551a798 100644 --- a/config/config.go +++ b/config/config.go @@ -59,6 +59,7 @@ type RocksDBConfig struct { StatsDumpPeriodSec int `toml:"stats_dump_period_sec"` BackgroundThreads int `toml:"background_theads"` HighPriorityBackgroundThreads int `toml:"high_priority_background_threads"` + DisableWAL bool `toml:"disable_wal"` } type LMDBConfig struct { @@ -169,6 +170,7 @@ func NewConfigDefault() *Config { cfg.RocksDB.UseFsync = false cfg.RocksDB.DisableAutoCompactions = false cfg.RocksDB.AllowOsBuffer = true + cfg.RocksDB.DisableWAL = false cfg.adjust() diff --git a/config/config.toml b/config/config.toml index 88f566b..a3b0833 100644 --- a/config/config.toml +++ b/config/config.toml @@ -82,7 +82,10 @@ max_background_flushes = 1 allow_os_buffer = true enable_statistics = false stats_dump_period_sec = 3600 - +# dangerous to set true, write may got lost after a crash +# you can set true if replication opened, we may recover from replication log, +# but it is still not a easy work. +disable_wal = false [lmdb] map_size = 524288000 diff --git a/etc/ledis.conf b/etc/ledis.conf index 88f566b..a3b0833 100644 --- a/etc/ledis.conf +++ b/etc/ledis.conf @@ -82,7 +82,10 @@ max_background_flushes = 1 allow_os_buffer = true enable_statistics = false stats_dump_period_sec = 3600 - +# dangerous to set true, write may got lost after a crash +# you can set true if replication opened, we may recover from replication log, +# but it is still not a easy work. +disable_wal = false [lmdb] map_size = 524288000 diff --git a/store/rocksdb/db.go b/store/rocksdb/db.go index 9bc7898..e1f10a4 100644 --- a/store/rocksdb/db.go +++ b/store/rocksdb/db.go @@ -150,9 +150,11 @@ func (db *DB) initOptions(cfg *config.RocksDBConfig) { db.readOpts = NewReadOptions() db.writeOpts = NewWriteOptions() + db.writeOpts.DisableWAL(cfg.DisableWAL) db.syncOpts = NewWriteOptions() db.syncOpts.SetSync(true) + db.syncOpts.DisableWAL(cfg.DisableWAL) db.iteratorOpts = NewReadOptions() db.iteratorOpts.SetFillCache(false) From 53072735f6513ae74c7fa8bc79bb9466edfdacd3 Mon Sep 17 00:00:00 2001 From: siddontang Date: Sat, 25 Oct 2014 14:48:52 +0800 Subject: [PATCH 3/5] add conn buffer config --- config/config.go | 5 +++++ config/config.toml | 4 ++++ server/client_resp.go | 12 ++++++++---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/config/config.go b/config/config.go index 551a798..5353ffc 100644 --- a/config/config.go +++ b/config/config.go @@ -110,6 +110,9 @@ type Config struct { Replication ReplicationConfig `toml:"replication"` Snapshot SnapshotConfig `toml:"snapshot"` + + ConnReadBufferSize int `toml:"conn_read_buffer_size"` + ConnWriteBufferSize int `toml:"conn_write_buffer_size"` } func NewConfigWithFile(fileName string) (*Config, error) { @@ -191,6 +194,8 @@ func (cfg *Config) adjust() { cfg.RocksDB.adjust() cfg.Replication.ExpiredLogDays = getDefault(7, cfg.Replication.ExpiredLogDays) + cfg.ConnReadBufferSize = getDefault(4*KB, cfg.ConnReadBufferSize) + cfg.ConnWriteBufferSize = getDefault(4*KB, cfg.ConnWriteBufferSize) } func (cfg *LevelDBConfig) adjust() { diff --git a/config/config.toml b/config/config.toml index a3b0833..aef46d6 100644 --- a/config/config.toml +++ b/config/config.toml @@ -43,6 +43,10 @@ db_sync_commit = 0 # enable replication or not use_replication = true +# set connection buffer, you can increase them appropriately +conn_read_buffer_size = 10240 +conn_write_buffer_size = 10240 + [leveldb] # for leveldb and goleveldb compression = false diff --git a/server/client_resp.go b/server/client_resp.go index cd5bee3..8d8378f 100644 --- a/server/client_resp.go +++ b/server/client_resp.go @@ -33,9 +33,13 @@ func newClientRESP(conn net.Conn, app *App) { c.client = newClient(app) c.conn = conn - c.rb = bufio.NewReaderSize(conn, 4096) + if tcpConn, ok := conn.(*net.TCPConn); ok { + tcpConn.SetReadBuffer(app.cfg.ConnReadBufferSize) + tcpConn.SetWriteBuffer(app.cfg.ConnWriteBufferSize) + } + c.rb = bufio.NewReaderSize(conn, app.cfg.ConnReadBufferSize) - c.resp = newWriterRESP(conn) + c.resp = newWriterRESP(conn, app.cfg.ConnWriteBufferSize) c.remoteAddr = conn.RemoteAddr().String() go c.run() @@ -158,9 +162,9 @@ func (c *respClient) handleRequest(reqData [][]byte) { // response writer -func newWriterRESP(conn net.Conn) *respWriter { +func newWriterRESP(conn net.Conn, size int) *respWriter { w := new(respWriter) - w.buff = bufio.NewWriterSize(conn, 256) + w.buff = bufio.NewWriterSize(conn, size) return w } From 37453395b2265b8119ad54451b3667899217ccfa Mon Sep 17 00:00:00 2001 From: siddontang Date: Sat, 25 Oct 2014 14:51:55 +0800 Subject: [PATCH 4/5] add my Skype id --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 72c8673..5a8436b 100644 --- a/README.md +++ b/README.md @@ -183,3 +183,4 @@ Gmail: wyk4true@gmail.com ## Feedback Gmail: siddontang@gmail.com +Skype: live:siddontang_1 From 8889197a395e92502bc86b3e4d1f70cf9c14840a Mon Sep 17 00:00:00 2001 From: siddontang Date: Sat, 25 Oct 2014 15:27:05 +0800 Subject: [PATCH 5/5] go client add conn buffer size config --- client/go/ledis/client.go | 12 ++++++++++-- client/go/ledis/conn.go | 2 +- cmd/ledis-benchmark/main.go | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/client/go/ledis/client.go b/client/go/ledis/client.go index ee1aca2..f6b0fc4 100644 --- a/client/go/ledis/client.go +++ b/client/go/ledis/client.go @@ -12,8 +12,10 @@ const ( ) type Config struct { - Addr string - MaxIdleConns int + Addr string + MaxIdleConns int + ReadBufferSize int + WriteBufferSize int } type Client struct { @@ -36,6 +38,12 @@ func NewClient(cfg *Config) *Client { c := new(Client) c.cfg = cfg + if c.cfg.ReadBufferSize == 0 { + c.cfg.ReadBufferSize = 4096 + } + if c.cfg.WriteBufferSize == 0 { + c.cfg.WriteBufferSize = 4096 + } c.conns = list.New() diff --git a/client/go/ledis/conn.go b/client/go/ledis/conn.go index 3d91925..7568772 100644 --- a/client/go/ledis/conn.go +++ b/client/go/ledis/conn.go @@ -384,7 +384,7 @@ func (c *Conn) readReply() (interface{}, error) { } func (c *Client) newConn(addr string) *Conn { - co := NewConn(addr) + co := NewConnSize(addr, c.cfg.ReadBufferSize, c.cfg.WriteBufferSize) co.client = c return co diff --git a/cmd/ledis-benchmark/main.go b/cmd/ledis-benchmark/main.go index 8f7d65d..510d436 100644 --- a/cmd/ledis-benchmark/main.go +++ b/cmd/ledis-benchmark/main.go @@ -268,6 +268,8 @@ func main() { cfg := new(ledis.Config) cfg.Addr = addr cfg.MaxIdleConns = *clients + cfg.ReadBufferSize = 10240 + cfg.WriteBufferSize = 10240 client = ledis.NewClient(cfg) if *round <= 0 {