[
https://issues.apache.org/jira/browse/BEAM-4726?focusedWorklogId=170757&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-170757
]
ASF GitHub Bot logged work on BEAM-4726:
----------------------------------------
Author: ASF GitHub Bot
Created on: 29/Nov/18 18:33
Start Date: 29/Nov/18 18:33
Worklog Time Spent: 10m
Work Description: aaltay closed pull request #7159: [BEAM-4726] Add heap
profiling hook
URL: https://github.com/apache/beam/pull/7159
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/sdks/go/pkg/beam/x/hooks/perf/perf.go
b/sdks/go/pkg/beam/x/hooks/perf/perf.go
index 6890ec022b23..d982b605f7dc 100644
--- a/sdks/go/pkg/beam/x/hooks/perf/perf.go
+++ b/sdks/go/pkg/beam/x/hooks/perf/perf.go
@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-// Package perf is to add performance measuring hooks to a runner, such as
cpu, or trace profiles.
+// Package perf is to add performance measuring hooks to a runner, such as
cpu, heap, or trace profiles.
package perf
import (
@@ -101,6 +101,36 @@ func init() {
}
}
hooks.RegisterHook("trace", hf)
+
+ hf = func(opts []string) hooks.Hook {
+ enabledHeapCaptureHooks = opts
+ enabled := len(enabledHeapCaptureHooks) > 0
+ var heapProfBuf bytes.Buffer
+ return hooks.Hook{
+ Req: func(ctx context.Context, req
*fnpb.InstructionRequest) (context.Context, error) {
+ if !enabled || req.GetProcessBundle() == nil {
+ return ctx, nil
+ }
+ heapProfBuf.Reset()
+ return ctx, nil
+ },
+ Resp: func(ctx context.Context, req
*fnpb.InstructionRequest, _ *fnpb.InstructionResponse) error {
+ if !enabled || req.GetProcessBundle() == nil {
+ return nil
+ }
+ pprof.WriteHeapProfile(&heapProfBuf)
+ for _, h := range enabledHeapCaptureHooks {
+ name, opts := hooks.Decode(h)
+ if err :=
heapCaptureHookRegistry[name](opts)(ctx, fmt.Sprintf("heap%s",
req.InstructionId), &heapProfBuf); err != nil {
+ return err
+ }
+ }
+ heapProfBuf.Reset()
+ return nil
+ },
+ }
+ }
+ hooks.RegisterHook("heap", hf)
}
// RegisterProfCaptureHook registers a CaptureHookFactory for the
@@ -168,3 +198,39 @@ func EnableTraceCaptureHook(name string, opts ...string) {
enabledTraceCaptureHooks = append(enabledTraceCaptureHooks, enc)
hooks.EnableHook("trace", enabledTraceCaptureHooks...)
}
+
+var heapCaptureHookRegistry = make(map[string]CaptureHookFactory)
+var enabledHeapCaptureHooks []string
+
+// RegisterHeapCaptureHook registers a CaptureHookFactory for the
+// supplied identifier. It panics if the same identifier is
+// registered twice.
+func RegisterHeapCaptureHook(name string, c CaptureHookFactory) {
+ if _, exists := heapCaptureHookRegistry[name]; exists {
+ panic(fmt.Sprintf("RegisterHeapCaptureHook: %s registered
twice", name))
+ }
+ heapCaptureHookRegistry[name] = c
+}
+
+// EnableHeapCaptureHook actives a registered heap profile capture hook for a
given pipeline.
+func EnableHeapCaptureHook(name string, opts ...string) {
+ _, exists := heapCaptureHookRegistry[name]
+ if !exists {
+ panic(fmt.Sprintf("EnableHeapCaptureHook: %s not registered",
name))
+ }
+
+ enc := hooks.Encode(name, opts)
+
+ for i, h := range enabledHeapCaptureHooks {
+ n, _ := hooks.Decode(h)
+ if h == n {
+ // Rewrite the registration with the current arguments
+ enabledHeapCaptureHooks[i] = enc
+ hooks.EnableHook("heap", enabledHeapCaptureHooks...)
+ return
+ }
+ }
+
+ enabledHeapCaptureHooks = append(enabledHeapCaptureHooks, enc)
+ hooks.EnableHook("heap", enabledHeapCaptureHooks...)
+}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 170757)
Time Spent: 7h 50m (was: 7h 40m)
> Reduce ParDo per element Invoke overhead
> ----------------------------------------
>
> Key: BEAM-4726
> URL: https://issues.apache.org/jira/browse/BEAM-4726
> Project: Beam
> Issue Type: Sub-task
> Components: sdk-go
> Reporter: Robert Burke
> Assignee: Robert Burke
> Priority: Major
> Time Spent: 7h 50m
> Remaining Estimate: 0h
>
> Each call to invoke allocates a new args []interface{}, but the common case
> is to run the same ProcessElement function over and again. It should be
> possible to have a container struct to retain the args slice, and avoid
> recomputing the indices for where to assign parameters before calling the
> ProcessElementFn.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)