[ 
https://issues.apache.org/jira/browse/BEAM-5987?focusedWorklogId=186126&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-186126
 ]

ASF GitHub Bot logged work on BEAM-5987:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 17/Jan/19 02:34
            Start Date: 17/Jan/19 02:34
    Worklog Time Spent: 10m 
      Work Description: kennknowles commented on pull request #7091: 
[BEAM-5987] Spark: Share cached side inputs between tasks.
URL: https://github.com/apache/beam/pull/7091#discussion_r248521765
 
 

 ##########
 File path: 
runners/spark/src/main/java/org/apache/beam/runners/spark/util/CachedSideInputReader.java
 ##########
 @@ -86,9 +55,27 @@ private CachedSideInputReader(SideInputReader delegate) {
   @Override
   public <T> T get(PCollectionView<T> view, BoundedWindow window) {
     @SuppressWarnings("unchecked")
-    final Map<Key<T>, T> materializedCasted = (Map) materialized;
-    return materializedCasted.computeIfAbsent(
-        new Key<>(view, window), key -> delegate.get(view, window));
+    final Cache<Key<T>, Optional<T>> materializedCasted =
+        (Cache) SideInputStorage.getMaterializedSideInputs();
+
+    Key<T> sideInputKey = new Key<>(view, window);
+
+    try {
+      Optional<T> optionalResult =
+          materializedCasted.get(
+              sideInputKey,
+              () -> {
+                final T result = delegate.get(view, window);
+                LOG.info(
+                    "Caching de-serialized side input for {} of size [{}B] in 
memory.",
+                    sideInputKey,
+                    SizeEstimator.estimate(result));
+                return Optional.ofNullable(result);
+              });
+      return optionalResult.orElse(null);
 
 Review comment:
   Ah, thank you for clarifying. That is a good attempt. The problem is that 
these will incorrectly be turned into the same thing:
   
   `Optional.ofNullable(null).orElse(null) == null`
   
   `Optional.ofNullable(Optional.absent()).orElse(null) == null`
   
   The fact that `Optional.of(null)` throws NPE is a mistake in the design 
(both Java and Guava). Maybe the point of the design is to convince people to 
not use `null`, which [is a billion dollar good 
idea](https://en.wikipedia.org/wiki/Null_pointer#History). But it makes 
`Optional<T>` not correctly parametric in `T`.
   
   I think that if you actually convert `null` into 
`Optional.of(Optional.absent())` and other values `v` into 
`Optional.of(Optional.of(v))` you can simulate the behavior it should have had 
in the first place. Or you could make your own little replacement of `Optional`.
 
----------------------------------------------------------------
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: 186126)
    Time Spent: 7h  (was: 6h 50m)

> Spark SideInputReader performance
> ---------------------------------
>
>                 Key: BEAM-5987
>                 URL: https://issues.apache.org/jira/browse/BEAM-5987
>             Project: Beam
>          Issue Type: Bug
>          Components: runner-spark
>    Affects Versions: 2.8.0
>            Reporter: David Moravek
>            Assignee: David Moravek
>            Priority: Major
>             Fix For: 2.9.0
>
>         Attachments: Screen Shot 2018-11-06 at 13.05.36.png
>
>          Time Spent: 7h
>  Remaining Estimate: 0h
>
> We did some profiling of a spark job and 90% of the application time was 
> spent on side input deserialization.
> For spark, an easy fix is to cache materialized side inputs per bundle. This 
> improved running time of the profiled job from 3 hours to 30 minutes.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to