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

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

                Author: ASF GitHub Bot
            Created on: 18/Jan/22 23:12
            Start Date: 18/Jan/22 23:12
    Worklog Time Spent: 10m 
      Work Description: lukecwik commented on a change in pull request #16495:
URL: https://github.com/apache/beam/pull/16495#discussion_r787224006



##########
File path: 
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/Caches.java
##########
@@ -165,10 +141,57 @@ public int weigh(Object key, Object value) {
   }
 
   @VisibleForTesting
-  static Cache<Object, Object> forCache(
-      
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.cache.Cache<CompositeKey,
 Object>
-          cache) {
-    return new SubCache<>(cache, CompositeKeyPrefix.ROOT);
+  static <K, V> Cache<K, V> forMaximumBytes(long maximumBytes) {
+    // We specifically use Guava cache since it allows for recursive 
computeIfAbsent calls
+    // preventing deadlock from occurring when a loading function mutates the 
underlying cache
+    LongAdder weightInBytes = new LongAdder();
+    return new SubCache<>(
+        new ShrinkOnEviction(
+                CacheBuilder.newBuilder()
+                    .maximumWeight(maximumBytes >> WEIGHT_RATIO)
+                    .weigher(
+                        new Weigher<Object, WeightedValue<Object>>() {
+
+                          @Override
+                          public int weigh(Object key, WeightedValue<Object> 
value) {
+                            // Round up to the next closest multiple of 
WEIGHT_RATIO
+                            long size = ((value.getWeight() - 1) >> 
WEIGHT_RATIO) + 1;

Review comment:
       Originally I was having trouble getting a good way of not paying the 
cost of weighing the key over and over but I solved that and added it back.




-- 
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: 710965)
    Time Spent: 51h 20m  (was: 51h 10m)

> Optimize Java SDK harness
> -------------------------
>
>                 Key: BEAM-13015
>                 URL: https://issues.apache.org/jira/browse/BEAM-13015
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-java-harness
>            Reporter: Luke Cwik
>            Assignee: Luke Cwik
>            Priority: P2
>          Time Spent: 51h 20m
>  Remaining Estimate: 0h
>
> Use profiling tools to remove bundle processing overhead in the SDK harness.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to