diff --git a/server/info.go b/server/info.go index d899d4f..1b7d27d 100644 --- a/server/info.go +++ b/server/info.go @@ -173,15 +173,31 @@ func (i *info) dumpStore(buf *bytes.Buffer) { s := i.app.ldb.StoreStat() + getNum := s.GetNum.Get() + getTotalTime := s.GetTotalTime.Get() + + gt := int64(0) + if getNum > 0 { + gt = getTotalTime.Nanoseconds() / (getNum * 1e3) + } + + commitNum := s.BatchCommitNum.Get() + commitTotalTime := s.BatchCommitTotalTime.Get() + + ct := int64(0) + if commitNum > 0 { + ct = commitTotalTime.Nanoseconds() / (commitNum * 1e3) + } + i.dumpPairs(buf, infoPair{"name", i.app.cfg.DBName}, infoPair{"get", s.GetNum}, infoPair{"get_missing", s.GetMissingNum}, - infoPair{"put", s.PutNum}, - infoPair{"delete", s.DeleteNum}, + infoPair{"get_per_time", fmt.Sprintf("%0.002fms", float64(gt)/1000.0)}, infoPair{"iter", s.IterNum}, infoPair{"iter_seek", s.IterSeekNum}, infoPair{"iter_close", s.IterCloseNum}, infoPair{"batch_commit", s.BatchCommitNum}, + infoPair{"batch_commit_per_time", fmt.Sprintf("%0.002fms", float64(ct)/1000.0)}, ) } diff --git a/store/db.go b/store/db.go index 7e88342..9964c5e 100644 --- a/store/db.go +++ b/store/db.go @@ -39,8 +39,10 @@ func (db *DB) NewIterator() *Iterator { } func (db *DB) Get(key []byte) ([]byte, error) { + t := time.Now() v, err := db.db.Get(key) db.st.statGet(v, err) + db.st.GetTotalTime.Add(time.Now().Sub(t)) return v, err } @@ -159,8 +161,10 @@ func (db *DB) needSyncCommit() bool { func (db *DB) GetSlice(key []byte) (Slice, error) { if d, ok := db.db.(driver.ISliceGeter); ok { + t := time.Now() v, err := d.GetSlice(key) db.st.statGet(v, err) + db.st.GetTotalTime.Add(time.Now().Sub(t)) return v, err } else { v, err := db.Get(key) diff --git a/store/stat.go b/store/stat.go index a14a135..e0a035a 100644 --- a/store/stat.go +++ b/store/stat.go @@ -5,22 +5,24 @@ import ( ) type Stat struct { - GetNum sync2.AtomicInt64 - GetMissingNum sync2.AtomicInt64 - PutNum sync2.AtomicInt64 - DeleteNum sync2.AtomicInt64 - IterNum sync2.AtomicInt64 - IterSeekNum sync2.AtomicInt64 - IterCloseNum sync2.AtomicInt64 - SnapshotNum sync2.AtomicInt64 - SnapshotCloseNum sync2.AtomicInt64 - BatchNum sync2.AtomicInt64 - BatchCommitNum sync2.AtomicInt64 - TxNum sync2.AtomicInt64 - TxCommitNum sync2.AtomicInt64 - TxCloseNum sync2.AtomicInt64 - CompactNum sync2.AtomicInt64 - CompactTotalTime sync2.AtomicDuration + GetNum sync2.AtomicInt64 + GetMissingNum sync2.AtomicInt64 + GetTotalTime sync2.AtomicDuration + PutNum sync2.AtomicInt64 + DeleteNum sync2.AtomicInt64 + IterNum sync2.AtomicInt64 + IterSeekNum sync2.AtomicInt64 + IterCloseNum sync2.AtomicInt64 + SnapshotNum sync2.AtomicInt64 + SnapshotCloseNum sync2.AtomicInt64 + BatchNum sync2.AtomicInt64 + BatchCommitNum sync2.AtomicInt64 + BatchCommitTotalTime sync2.AtomicDuration + TxNum sync2.AtomicInt64 + TxCommitNum sync2.AtomicInt64 + TxCloseNum sync2.AtomicInt64 + CompactNum sync2.AtomicInt64 + CompactTotalTime sync2.AtomicDuration } func (st *Stat) statGet(v interface{}, err error) { diff --git a/store/writebatch.go b/store/writebatch.go index bf4658c..773eeaf 100644 --- a/store/writebatch.go +++ b/store/writebatch.go @@ -2,38 +2,37 @@ package store import ( "github.com/siddontang/ledisdb/store/driver" + "time" ) type WriteBatch struct { - wb driver.IWriteBatch - st *Stat - putNum int64 - deleteNum int64 + wb driver.IWriteBatch + st *Stat db *DB } func (wb *WriteBatch) Put(key []byte, value []byte) { - wb.putNum++ wb.wb.Put(key, value) } func (wb *WriteBatch) Delete(key []byte) { - wb.deleteNum++ wb.wb.Delete(key) } func (wb *WriteBatch) Commit() error { wb.st.BatchCommitNum.Add(1) - wb.st.PutNum.Add(wb.putNum) - wb.st.DeleteNum.Add(wb.deleteNum) - wb.putNum = 0 - wb.deleteNum = 0 + var err error + t := time.Now() if wb.db == nil || !wb.db.needSyncCommit() { - return wb.wb.Commit() + err = wb.wb.Commit() } else { - return wb.wb.SyncCommit() + err = wb.wb.SyncCommit() } + + wb.st.BatchCommitTotalTime.Add(time.Now().Sub(t)) + + return err } func (wb *WriteBatch) Rollback() error {