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

[#29180][prism] Return total element count to progress loop. Split less aggressively. #29968

Merged
merged 2 commits into from
Jan 12, 2024
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
2 changes: 1 addition & 1 deletion sdks/go/pkg/beam/runners/prism/internal/jobservices/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (j *Job) PipelineOptions() *structpb.Struct {
}

// ContributeTentativeMetrics returns the datachannel read index, and any unknown monitoring short ids.
func (j *Job) ContributeTentativeMetrics(payloads *fnpb.ProcessBundleProgressResponse) (int64, []string) {
func (j *Job) ContributeTentativeMetrics(payloads *fnpb.ProcessBundleProgressResponse) (map[string]int64, []string) {
return j.metrics.ContributeTentativeMetrics(payloads)
}

Expand Down
18 changes: 12 additions & 6 deletions sdks/go/pkg/beam/runners/prism/internal/jobservices/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ func (m *metricsStore) AddShortIDs(resp *fnpb.MonitoringInfosMetadataResponse) {
}
}

func (m *metricsStore) contributeMetrics(d durability, mdata map[string][]byte) (int64, []string) {
readIndex := int64(-1)
func (m *metricsStore) contributeMetrics(d durability, mdata map[string][]byte) (map[string]int64, []string) {
var index, totalCount int64
if m.accums[d] == nil {
m.accums[d] = map[metricKey]metricAccumulator{}
}
Expand Down Expand Up @@ -510,14 +510,20 @@ func (m *metricsStore) contributeMetrics(d durability, mdata map[string][]byte)
panic(fmt.Sprintf("error decoding metrics %v: %+v\n\t%+v", key.Urn(), key, a))
}
accums[key] = a
if key.Urn() == "beam:metric:data_channel:read_index:v1" {
readIndex = a.(*sumInt64).sum
switch u := key.Urn(); u {
case "beam:metric:data_channel:read_index:v1":
index = a.(*sumInt64).sum // There should only be one of these per progress response.
case "beam:metric:element_count:v1":
totalCount += a.(*sumInt64).sum
}
}
return readIndex, missingShortIDs
return map[string]int64{
"index": index,
"totalCount": totalCount,
}, missingShortIDs
}

func (m *metricsStore) ContributeTentativeMetrics(payloads *fnpb.ProcessBundleProgressResponse) (int64, []string) {
func (m *metricsStore) ContributeTentativeMetrics(payloads *fnpb.ProcessBundleProgressResponse) (map[string]int64, []string) {
m.mu.Lock()
defer m.mu.Unlock()
return m.contributeMetrics(tentative, payloads.GetMonitoringData())
Expand Down
15 changes: 10 additions & 5 deletions sdks/go/pkg/beam/runners/prism/internal/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ func (s *stage) Execute(ctx context.Context, j *jobservices.Job, wk *worker.W, c

// Progress + split loop.
previousIndex := int64(-2)
var splitsDone bool
previousTotalCount := int64(-2) // Total count of all pcollection elements.

unsplit := true
progTick := time.NewTicker(100 * time.Millisecond)
defer progTick.Stop()
var dataFinished, bundleFinished bool
Expand Down Expand Up @@ -166,8 +168,10 @@ progress:
j.AddMetricShortIDs(md)
}
slog.Debug("progress report", "bundle", rb, "index", index, "prevIndex", previousIndex)
// Progress for the bundle hasn't advanced. Try splitting.
if previousIndex == index && !splitsDone {

// Check if there has been any measurable progress by the input, or all output pcollections since last report.
slow := previousIndex == index["index"] && previousTotalCount == index["totalCount"]
if slow && unsplit {
slog.Debug("splitting report", "bundle", rb, "index", index)
sr, err := b.Split(ctx, wk, 0.5 /* fraction of remainder */, nil /* allowed splits */)
if err != nil {
Expand All @@ -176,7 +180,7 @@ progress:
}
if sr.GetChannelSplits() == nil {
slog.Debug("SDK returned no splits", "bundle", rb)
splitsDone = true
unsplit = false
continue progress
}
// TODO sort out rescheduling primary Roots on bundle failure.
Expand All @@ -201,7 +205,8 @@ progress:
em.ReturnResiduals(rb, int(fr), s.inputInfo, residualData)
}
} else {
previousIndex = index
previousIndex = index["index"]
previousTotalCount = index["totalCount"]
}
}
}
Expand Down