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()
|
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},
|
i.dumpPairs(buf, infoPair{"name", i.app.cfg.DBName},
|
||||||
infoPair{"get", s.GetNum},
|
infoPair{"get", s.GetNum},
|
||||||
infoPair{"get_missing", s.GetMissingNum},
|
infoPair{"get_missing", s.GetMissingNum},
|
||||||
infoPair{"put", s.PutNum},
|
infoPair{"get_per_time", fmt.Sprintf("%0.002fms", float64(gt)/1000.0)},
|
||||||
infoPair{"delete", s.DeleteNum},
|
|
||||||
infoPair{"iter", s.IterNum},
|
infoPair{"iter", s.IterNum},
|
||||||
infoPair{"iter_seek", s.IterSeekNum},
|
infoPair{"iter_seek", s.IterSeekNum},
|
||||||
infoPair{"iter_close", s.IterCloseNum},
|
infoPair{"iter_close", s.IterCloseNum},
|
||||||
infoPair{"batch_commit", s.BatchCommitNum},
|
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) {
|
func (db *DB) Get(key []byte) ([]byte, error) {
|
||||||
|
t := time.Now()
|
||||||
v, err := db.db.Get(key)
|
v, err := db.db.Get(key)
|
||||||
db.st.statGet(v, err)
|
db.st.statGet(v, err)
|
||||||
|
db.st.GetTotalTime.Add(time.Now().Sub(t))
|
||||||
return v, err
|
return v, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,8 +161,10 @@ func (db *DB) needSyncCommit() bool {
|
||||||
|
|
||||||
func (db *DB) GetSlice(key []byte) (Slice, error) {
|
func (db *DB) GetSlice(key []byte) (Slice, error) {
|
||||||
if d, ok := db.db.(driver.ISliceGeter); ok {
|
if d, ok := db.db.(driver.ISliceGeter); ok {
|
||||||
|
t := time.Now()
|
||||||
v, err := d.GetSlice(key)
|
v, err := d.GetSlice(key)
|
||||||
db.st.statGet(v, err)
|
db.st.statGet(v, err)
|
||||||
|
db.st.GetTotalTime.Add(time.Now().Sub(t))
|
||||||
return v, err
|
return v, err
|
||||||
} else {
|
} else {
|
||||||
v, err := db.Get(key)
|
v, err := db.Get(key)
|
||||||
|
|
|
@ -5,22 +5,24 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Stat struct {
|
type Stat struct {
|
||||||
GetNum sync2.AtomicInt64
|
GetNum sync2.AtomicInt64
|
||||||
GetMissingNum sync2.AtomicInt64
|
GetMissingNum sync2.AtomicInt64
|
||||||
PutNum sync2.AtomicInt64
|
GetTotalTime sync2.AtomicDuration
|
||||||
DeleteNum sync2.AtomicInt64
|
PutNum sync2.AtomicInt64
|
||||||
IterNum sync2.AtomicInt64
|
DeleteNum sync2.AtomicInt64
|
||||||
IterSeekNum sync2.AtomicInt64
|
IterNum sync2.AtomicInt64
|
||||||
IterCloseNum sync2.AtomicInt64
|
IterSeekNum sync2.AtomicInt64
|
||||||
SnapshotNum sync2.AtomicInt64
|
IterCloseNum sync2.AtomicInt64
|
||||||
SnapshotCloseNum sync2.AtomicInt64
|
SnapshotNum sync2.AtomicInt64
|
||||||
BatchNum sync2.AtomicInt64
|
SnapshotCloseNum sync2.AtomicInt64
|
||||||
BatchCommitNum sync2.AtomicInt64
|
BatchNum sync2.AtomicInt64
|
||||||
TxNum sync2.AtomicInt64
|
BatchCommitNum sync2.AtomicInt64
|
||||||
TxCommitNum sync2.AtomicInt64
|
BatchCommitTotalTime sync2.AtomicDuration
|
||||||
TxCloseNum sync2.AtomicInt64
|
TxNum sync2.AtomicInt64
|
||||||
CompactNum sync2.AtomicInt64
|
TxCommitNum sync2.AtomicInt64
|
||||||
CompactTotalTime sync2.AtomicDuration
|
TxCloseNum sync2.AtomicInt64
|
||||||
|
CompactNum sync2.AtomicInt64
|
||||||
|
CompactTotalTime sync2.AtomicDuration
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *Stat) statGet(v interface{}, err error) {
|
func (st *Stat) statGet(v interface{}, err error) {
|
||||||
|
|
|
@ -2,38 +2,37 @@ package store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/siddontang/ledisdb/store/driver"
|
"github.com/siddontang/ledisdb/store/driver"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WriteBatch struct {
|
type WriteBatch struct {
|
||||||
wb driver.IWriteBatch
|
wb driver.IWriteBatch
|
||||||
st *Stat
|
st *Stat
|
||||||
putNum int64
|
|
||||||
deleteNum int64
|
|
||||||
|
|
||||||
db *DB
|
db *DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wb *WriteBatch) Put(key []byte, value []byte) {
|
func (wb *WriteBatch) Put(key []byte, value []byte) {
|
||||||
wb.putNum++
|
|
||||||
wb.wb.Put(key, value)
|
wb.wb.Put(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wb *WriteBatch) Delete(key []byte) {
|
func (wb *WriteBatch) Delete(key []byte) {
|
||||||
wb.deleteNum++
|
|
||||||
wb.wb.Delete(key)
|
wb.wb.Delete(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wb *WriteBatch) Commit() error {
|
func (wb *WriteBatch) Commit() error {
|
||||||
wb.st.BatchCommitNum.Add(1)
|
wb.st.BatchCommitNum.Add(1)
|
||||||
wb.st.PutNum.Add(wb.putNum)
|
var err error
|
||||||
wb.st.DeleteNum.Add(wb.deleteNum)
|
t := time.Now()
|
||||||
wb.putNum = 0
|
|
||||||
wb.deleteNum = 0
|
|
||||||
if wb.db == nil || !wb.db.needSyncCommit() {
|
if wb.db == nil || !wb.db.needSyncCommit() {
|
||||||
return wb.wb.Commit()
|
err = wb.wb.Commit()
|
||||||
} else {
|
} else {
|
||||||
return wb.wb.SyncCommit()
|
err = wb.wb.SyncCommit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wb.st.BatchCommitTotalTime.Add(time.Now().Sub(t))
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wb *WriteBatch) Rollback() error {
|
func (wb *WriteBatch) Rollback() error {
|
||||||
|
|
Loading…
Reference in New Issue