[
https://issues.apache.org/jira/browse/BEAM-13001?focusedWorklogId=672054&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-672054
]
ASF GitHub Bot logged work on BEAM-13001:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 29/Oct/21 16:45
Start Date: 29/Oct/21 16:45
Worklog Time Spent: 10m
Work Description: lostluck commented on a change in pull request #15657:
URL: https://github.com/apache/beam/pull/15657#discussion_r739391168
##########
File path: sdks/go/pkg/beam/core/metrics/sampler.go
##########
@@ -0,0 +1,98 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package metrics
+
+import (
+ "context"
+ "sync/atomic"
+ "time"
+ "unsafe"
+
+ "github.com/apache/beam/sdks/v2/go/pkg/beam/log"
+)
+
+// StateSampler tracks the state of a bundle.
+type StateSampler struct {
+ store *Store // used to store states into state
registry
+ millisSinceLastTransition time.Duration
+ transitionsAtLastSample int64
+ nextLogTime time.Duration
+ logInterval time.Duration
+}
+
+// NewSampler creates a new state sampler.
+func NewSampler(store *Store) StateSampler {
+ return StateSampler{store: store, nextLogTime: 5 * time.Minute,
logInterval: 5 * time.Minute}
+}
+
+// Sample checks for state transition in processing a DoFn
+func (s *StateSampler) Sample(ctx context.Context, t time.Duration) {
+ ps := loadCurrentState(s)
+ if ps.pid == "" {
+ return
+ }
+ s.store.mu.Lock()
+ defer s.store.mu.Unlock()
+
+ if v, ok := s.store.stateRegistry[ps.pid]; ok {
+ v[ps.state].TotalTime += t
+ v[TotalBundle].TotalTime += t
+
+ if s.transitionsAtLastSample != ps.transitions {
+ // state change detected
+ s.millisSinceLastTransition = 0
+ s.transitionsAtLastSample = ps.transitions
+ } else {
+ s.millisSinceLastTransition += t
+ }
+
+ if s.millisSinceLastTransition > s.nextLogTime {
+ log.Info(ctx, "...standard long running operation log
...", ps.pid, ps.state, s.millisSinceLastTransition)
Review comment:
No worries. It's easy to get caught up in apparent urgency.
There's a saying, Slow is Fast. Going fast often leads to technical debt and
mistakes that will slow things down later, when compared to taking a bit more
time initially, to get it right. Usually discussed in context of larger product
roadmaps and team scale development (eg
https://www.infoq.com/articles/slow-down-go-faster/). It does apply on an
individual level too though.
In this instance, a trick is to review your own code, and try to catch
issues yourself before sending them out. Yes, you won't always catch your own
mistakes (being blind to mistakes in code you just wrote is common), but over
time you will get better at it. The way I've approached this in the past has
been to make the changes, go work on something else for a bit (go workout, eat,
another change etc.) then take a look at the new changes, and see if there's
anything else to polish up. Then again at the whole current PR. Make those
fixes and then take another look, and then send it out for review by someone
else.
It's important to not get too caught up in increasing the scope when doing
this (eg. Oh I can just do this part now...), but that's another issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 672054)
Time Spent: 8h (was: 7h 50m)
> DoFn Execution time metrics (msecs) for Go SDK
> ----------------------------------------------
>
> Key: BEAM-13001
> URL: https://issues.apache.org/jira/browse/BEAM-13001
> Project: Beam
> Issue Type: Improvement
> Components: sdk-go
> Reporter: Ritesh Ghorse
> Assignee: Ritesh Ghorse
> Priority: P2
> Time Spent: 8h
> Remaining Estimate: 0h
>
> Implement DoFn execution time metrics for Go SDK.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)