[
https://issues.apache.org/jira/browse/BEAM-11097?focusedWorklogId=677647&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-677647
]
ASF GitHub Bot logged work on BEAM-11097:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 05/Nov/21 20:20
Start Date: 05/Nov/21 20:20
Worklog Time Spent: 10m
Work Description: lostluck commented on a change in pull request #15896:
URL: https://github.com/apache/beam/pull/15896#discussion_r743075662
##########
File path: sdks/go/pkg/beam/core/runtime/harness/cache_hooks.go
##########
@@ -0,0 +1,53 @@
+// 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 harness
+
+import (
+ "context"
+ "fmt"
+
+ "github.com/apache/beam/sdks/v2/go/pkg/beam/core/util/hooks"
+)
+
+type cacheHookKey string
+
+const (
+ cacheSizeKey cacheHookKey = "sideCacheSize"
+)
+
+func init() {
+ hf := func(opts []string) hooks.Hook {
+ return hooks.Hook{
+ Init: func(ctx context.Context) (context.Context,
error) {
+ if len(opts) == 0 {
+ return context.WithValue(ctx,
cacheSizeKey, 0), nil
+ }
+ if len(opts) > 1 {
+ return ctx, fmt.Errorf("expected 1
option, got %v: %v", len(opts), opts)
+ }
+
+ var count int
+ _, err := fmt.Sscan(opts[0], &count)
+ if err != nil {
+ return nil, err
+ }
+
+ return context.WithValue(ctx, cacheSizeKey,
count), nil
Review comment:
Per https://pkg.go.dev/context
> Use context Values only for request-scoped data that transits processes
and APIs, not for passing optional parameters to functions.
In this case, it's much more preferable to have an unexported Package level
variable that this hook sets, and it used, rather than propagating via context.
It would be much simpler to follow: we're always using the package level
field. The default value is quite evident.
The remote logging hook needed to cheat using a context value because of the
dependency reversal. (the remote logging hook is in the harness/init package
which calls into harness.Main(), and there's no good other good way to
propagate the parameters sensibly...). For a one off, it's fine, but we
probably should consider re-factoring how the remote logging is handled, to be
closer to what's happening with the state cache.
In this case, everything is in the harness package, so we can avoid adding
values to live in the context forever.
##########
File path: sdks/go/pkg/beam/core/runtime/harness/statecache/statecache.go
##########
@@ -86,6 +92,9 @@ func (c *SideInputCache) Init(cap int) error {
func (c *SideInputCache) SetValidTokens(cacheTokens
...*fnpb.ProcessBundleRequest_CacheToken) {
c.mu.Lock()
defer c.mu.Unlock()
+ if !c.enabled {
+ return
+ }
Review comment:
Since `enabled` should only be written in `Init()`, and `Init()` is only
written to once, I'd be OK with putting these checks before the locks.
--
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: 677647)
Time Spent: 14h (was: 13h 50m)
> [Go SDK] Windowed Side Input Caching (Cross Bundle)
> ---------------------------------------------------
>
> Key: BEAM-11097
> URL: https://issues.apache.org/jira/browse/BEAM-11097
> Project: Beam
> Issue Type: Improvement
> Components: sdk-go
> Reporter: Robert Burke
> Assignee: Jack McCluskey
> Priority: P3
> Labels: starter
> Time Spent: 14h
> Remaining Estimate: 0h
>
> This is implementing https://issues.apache.org/jira/browse/BEAM-5428 for the
> Go SDK.
> Side inputs are valid for given window. That means they can be and correctly
> cached and re-used in multiple bundles if the data has already been loaded
> into a given worker.
> Side input data for a given bundle is specified and keyed by the window and a
> a side input request token. The Go SDK presently doesn't use this information
> for a SDK side worker cache of data.
> Care needs to be taken to allow the data to be garbage collected if it hasn't
> been used in the last minute or so. In practice, Global Window side inputs
> will not be evicted while still in use, but infrequently accessed data will
> possibly be evicted more regularly. A limit should be set to avoid running
> out of memory.
> As presently implemented, each ProcessElement call (or StartBundle or
> FinishBundle) will only query for side input data on user request. However,
> results of user requests are not cached between elements or bundles, which
> means there's additional lookup and serialization time from the runner side.
> It may be possible to re-use allocated side input elements, but even a
> solution that re-decodes data on every call would be an improvement if the
> data isn't re-streamed from the runner.
> If https://issues.apache.org/jira/browse/BEAM-3293 has been implemented, then
> per-key+window caching should additionally be considered for more granular
> caching of data.
> This optimization has an outsized impact on streaming performance as side
> input data can change per bundle, and streaming bundles are typically small,
> and quickly processed.
> This work would be implemented in the exec package:
>
> [https://github.com/apache/beam/blob/master/sdks/go/pkg/beam/core/runtime/exec/sideinput.go]
>
> and probably the harness package
>
> [https://github.com/apache/beam/blob/c185adb7652034b5d044aae65a1a972d9ceb4377/sdks/go/pkg/beam/core/runtime/harness/statemgr.go#L50]
--
This message was sent by Atlassian Jira
(v8.3.4#803005)