forked from mirror/ledisdb
update store statistic
This commit is contained in:
parent
bd9e546da4
commit
4668350862
|
@ -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)},
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
type Stat struct {
|
||||
GetNum sync2.AtomicInt64
|
||||
GetMissingNum sync2.AtomicInt64
|
||||
GetTotalTime sync2.AtomicDuration
|
||||
PutNum sync2.AtomicInt64
|
||||
DeleteNum sync2.AtomicInt64
|
||||
IterNum sync2.AtomicInt64
|
||||
|
@ -16,6 +17,7 @@ type Stat struct {
|
|||
SnapshotCloseNum sync2.AtomicInt64
|
||||
BatchNum sync2.AtomicInt64
|
||||
BatchCommitNum sync2.AtomicInt64
|
||||
BatchCommitTotalTime sync2.AtomicDuration
|
||||
TxNum sync2.AtomicInt64
|
||||
TxCommitNum sync2.AtomicInt64
|
||||
TxCloseNum sync2.AtomicInt64
|
||||
|
|
|
@ -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
|
||||
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue