Skip to content

Commit

Permalink
fix busy ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesCheung96 committed Nov 2, 2023
1 parent 59601e8 commit 10fc210
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions cdc/sink/dmlsink/cloudstorage/dml_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"bytes"
"context"
"path"
"strconv"
"sync/atomic"
"time"

Expand Down Expand Up @@ -127,7 +128,7 @@ func newDMLWorker(
metricFlushDuration: mcloudstorage.CloudStorageFlushDurationHistogram.
WithLabelValues(changefeedID.Namespace, changefeedID.ID),
metricsWorkerBusyRatio: mcloudstorage.CloudStorageWorkerBusyRatioCounter.
WithLabelValues(changefeedID.Namespace, changefeedID.ID),
WithLabelValues(changefeedID.Namespace, changefeedID.ID, strconv.Itoa(id)),
}

return d
Expand Down Expand Up @@ -155,7 +156,7 @@ func (d *dmlWorker) run(ctx context.Context) error {
// active means that a table has events since last flushing.
func (d *dmlWorker) flushMessages(ctx context.Context) error {
var flushTimeSlice, totalTimeSlice time.Duration
overseerTicker := time.NewTicker(time.Second)
overseerTicker := time.NewTicker(d.config.FlushInterval * 2)
defer overseerTicker.Stop()
startToWork := time.Now()
for {
Expand All @@ -164,8 +165,8 @@ func (d *dmlWorker) flushMessages(ctx context.Context) error {
return errors.Trace(ctx.Err())
case now := <-overseerTicker.C:
totalTimeSlice = now.Sub(startToWork)
busyRatio := int(flushTimeSlice.Seconds() / totalTimeSlice.Seconds() * 1000)
d.metricsWorkerBusyRatio.Add(float64(busyRatio) / float64(d.config.WorkerCount))
busyRatio := float64(flushTimeSlice.Seconds() / totalTimeSlice.Seconds() * 1000)
d.metricsWorkerBusyRatio.Add(busyRatio)
startToWork = now
flushTimeSlice = 0
case task := <-d.flushNotifyCh:
Expand Down
2 changes: 1 addition & 1 deletion cdc/sink/metrics/cloudstorage/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var (
Subsystem: subsystem,
Name: "cloud_storage_worker_busy_ratio",
Help: "Busy ratio (X ms in 1s) for cloud storage sink dml worker.",
}, []string{"namespace", "changefeed"})
}, []string{"namespace", "changefeed", "id"})
)

// InitMetrics registers all metrics in this file.
Expand Down

0 comments on commit 10fc210

Please sign in to comment.