Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replication metrics #3361

Merged
merged 3 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions service/history/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ func New(dc *dynamicconfig.Collection, numberOfShards int, storeType string, isA
ReplicationTaskFetcherAggregationInterval: dc.GetDurationProperty(dynamicconfig.ReplicationTaskFetcherAggregationInterval, 2*time.Second),
ReplicationTaskFetcherTimerJitterCoefficient: dc.GetFloat64Property(dynamicconfig.ReplicationTaskFetcherTimerJitterCoefficient, 0.15),
ReplicationTaskFetcherErrorRetryWait: dc.GetDurationProperty(dynamicconfig.ReplicationTaskFetcherErrorRetryWait, time.Second),
ReplicationTaskProcessorErrorRetryWait: dc.GetDurationPropertyFilteredByShardID(dynamicconfig.ReplicationTaskProcessorErrorRetryWait, time.Second),
ReplicationTaskProcessorErrorRetryMaxAttempts: dc.GetIntPropertyFilteredByShardID(dynamicconfig.ReplicationTaskProcessorErrorRetryMaxAttempts, 20),
ReplicationTaskProcessorErrorRetryWait: dc.GetDurationPropertyFilteredByShardID(dynamicconfig.ReplicationTaskProcessorErrorRetryWait, 50 * time.Millisecond),
ReplicationTaskProcessorErrorRetryMaxAttempts: dc.GetIntPropertyFilteredByShardID(dynamicconfig.ReplicationTaskProcessorErrorRetryMaxAttempts, 5),
ReplicationTaskProcessorNoTaskRetryWait: dc.GetDurationPropertyFilteredByShardID(dynamicconfig.ReplicationTaskProcessorNoTaskInitialWait, 2*time.Second),
ReplicationTaskProcessorCleanupInterval: dc.GetDurationPropertyFilteredByShardID(dynamicconfig.ReplicationTaskProcessorCleanupInterval, 1*time.Minute),
ReplicationTaskProcessorCleanupJitterCoefficient: dc.GetFloat64PropertyFilteredByShardID(dynamicconfig.ReplicationTaskProcessorCleanupJitterCoefficient, 0.15),
Expand Down
35 changes: 21 additions & 14 deletions service/history/replication/task_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ func (p *taskProcessorImpl) Stop() {
}

func (p *taskProcessorImpl) processorLoop() {
p.lastProcessedMessageID = p.shard.GetClusterReplicationLevel(p.sourceCluster)

defer func() {
p.logger.Info("Closing replication task processor.", tag.ReadLevel(p.lastRetrievedMessageID))
}()
Expand Down Expand Up @@ -246,7 +244,6 @@ func (p *taskProcessorImpl) cleanupAckedReplicationTasks() error {
}
}
}

p.logger.Debug("Cleaning up replication task queue.", tag.ReadLevel(minAckLevel))
p.metricsClient.Scope(metrics.ReplicationTaskCleanupScope).IncCounter(metrics.ReplicationTaskCleanupCount)
p.metricsClient.Scope(metrics.ReplicationTaskFetcherScope,
Expand All @@ -255,6 +252,11 @@ func (p *taskProcessorImpl) cleanupAckedReplicationTasks() error {
metrics.ReplicationTasksLag,
time.Duration(p.shard.GetTransferMaxReadLevel()-minAckLevel),
)
// update replication queue ack level.
// this ack level currently use by Kafka replication
if err := p.shard.UpdateReplicatorAckLevel(minAckLevel); err != nil {
return err
}
return p.shard.GetExecutionManager().RangeCompleteReplicationTask(
&persistence.RangeCompleteReplicationTaskRequest{
InclusiveEndTaskID: minAckLevel,
Expand All @@ -278,17 +280,9 @@ func (p *taskProcessorImpl) sendFetchMessageRequest() <-chan *r.ReplicationMessa

func (p *taskProcessorImpl) processResponse(response *r.ReplicationMessages) {

p.lastProcessedMessageID = response.GetLastRetrievedMessageId()
p.lastRetrievedMessageID = response.GetLastRetrievedMessageId()

p.syncShardChan <- response.GetSyncShardStatus()
// Note here we check replication tasks instead of hasMore. The expectation is that in a steady state
// we will receive replication tasks but hasMore is false (meaning that we are always catching up).
// So hasMore might not be a good indicator for additional wait.
if len(response.ReplicationTasks) == 0 {
backoffDuration := p.noTaskRetrier.NextBackOff()
time.Sleep(backoffDuration)
return
select {
case p.syncShardChan <- response.GetSyncShardStatus():
default:
}

for _, replicationTask := range response.ReplicationTasks {
Expand All @@ -298,6 +292,17 @@ func (p *taskProcessorImpl) processResponse(response *r.ReplicationMessages) {
return
}
}

// Note here we check replication tasks instead of hasMore. The expectation is that in a steady state
// we will receive replication tasks but hasMore is false (meaning that we are always catching up).
// So hasMore might not be a good indicator for additional wait.
if len(response.ReplicationTasks) == 0 {
backoffDuration := p.noTaskRetrier.NextBackOff()
time.Sleep(backoffDuration)
}

p.lastProcessedMessageID = response.GetLastRetrievedMessageId()
p.lastRetrievedMessageID = response.GetLastRetrievedMessageId()
scope := p.metricsClient.Scope(metrics.ReplicationTaskFetcherScope, metrics.TargetClusterTag(p.sourceCluster))
scope.UpdateGauge(metrics.LastRetrievedMessageID, float64(p.lastRetrievedMessageID))
p.noTaskRetrier.Reset()
Expand Down Expand Up @@ -370,6 +375,7 @@ func (p *taskProcessorImpl) processSingleTask(replicationTask *r.ReplicationTask
}

func (p *taskProcessorImpl) processTaskOnce(replicationTask *r.ReplicationTask) error {
startTime := time.Now()
scope, err := p.taskExecutor.execute(
p.sourceCluster,
replicationTask,
Expand All @@ -383,6 +389,7 @@ func (p *taskProcessorImpl) processTaskOnce(replicationTask *r.ReplicationTask)
metrics.ReplicationTaskFetcherScope,
metrics.TargetClusterTag(p.sourceCluster),
).IncCounter(metrics.ReplicationTasksApplied)
p.metricsClient.Scope(scope).RecordTimer(metrics.TaskProcessingLatency, time.Now().Sub(startTime))
}

return err
Expand Down
10 changes: 6 additions & 4 deletions service/history/replicatorQueueProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,11 @@ func (p *replicatorQueueProcessorImpl) getTasks(
lastReadTaskID = p.shard.GetClusterReplicationLevel(pollingCluster)
}

replicationScope := p.metricsClient.Scope(
metrics.ReplicatorQueueProcessorScope,
metrics.InstanceTag(strconv.Itoa(p.shard.GetShardID())),
)
taskGeneratedTimer := replicationScope.StartTimer(metrics.ReplicatorLatency)
taskInfoList, hasMore, err := p.readTasksWithBatchSize(lastReadTaskID, p.fetchTasksBatchSize)
if err != nil {
return nil, err
Expand Down Expand Up @@ -463,10 +468,7 @@ func (p *replicatorQueueProcessorImpl) getTasks(
}
}

replicationScope := p.metricsClient.Scope(
metrics.ReplicatorQueueProcessorScope,
metrics.InstanceTag(strconv.Itoa(p.shard.GetShardID())),
)
taskGeneratedTimer.Stop()

replicationScope.RecordTimer(
metrics.ReplicationTasksLag,
Expand Down