diff --git a/server/info.go b/server/info.go index 2babae8..2c729ed 100644 --- a/server/info.go +++ b/server/info.go @@ -28,6 +28,11 @@ type info struct { Persistence struct { DBName string } + + Replication struct { + PubLogNum int64 + PubLogTotalTime int64 //milliseconds + } } func newInfo(app *App) (i *info, err error) { @@ -156,6 +161,15 @@ func (i *info) dumpReplication(buf *bytes.Buffer) { slaves = append(slaves, s.remoteAddr) } + num := i.Replication.PubLogNum + p = append(p, infoPair{"pub_log_num", num}) + + if num != 0 { + p = append(p, infoPair{"pub_log_per_time", i.Replication.PubLogTotalTime / num}) + } else { + p = append(p, infoPair{"pub_log_per_time", 0}) + } + p = append(p, infoPair{"slaveof", i.app.cfg.SlaveOf}) if len(slaves) > 0 { diff --git a/server/replication.go b/server/replication.go index a21c46f..7b37de4 100644 --- a/server/replication.go +++ b/server/replication.go @@ -15,6 +15,7 @@ import ( "path" "strconv" "sync" + "sync/atomic" "time" ) @@ -336,6 +337,8 @@ func (app *App) publishNewLog(l *rpl.Log) { return } + startTime := time.Now() + ack := &syncAck{ logId, make(chan uint64, len(ss)), } @@ -369,4 +372,8 @@ func (app *App) publishNewLog(l *rpl.Log) { case <-time.After(time.Duration(app.cfg.Replication.WaitSyncTime) * time.Millisecond): log.Info("replication wait timeout") } + + stopTime := time.Now() + atomic.AddInt64(&app.info.Replication.PubLogNum, 1) + atomic.AddInt64(&app.info.Replication.PubLogTotalTime, stopTime.Sub(startTime).Nanoseconds()/1e6) }