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

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

                Author: ASF GitHub Bot
            Created on: 17/May/19 14:27
            Start Date: 17/May/19 14:27
    Worklog Time Spent: 10m 
      Work Description: mxm commented on pull request #8599: [BEAM-7348] 
Support environment expiration
URL: https://github.com/apache/beam/pull/8599#discussion_r285143401
 
 

 ##########
 File path: 
runners/java-fn-execution/src/main/java/org/apache/beam/runners/fnexecution/control/DefaultJobBundleFactory.java
 ##########
 @@ -141,47 +150,54 @@ public static DefaultJobBundleFactory create(
             .setDataServer(dataServer)
             .setStateServer(stateServer)
             .build();
+    this.environmentExpirationMillis = 0;
     this.environmentCache = createEnvironmentCache(serverFactory -> 
serverInfo);
   }
 
   private LoadingCache<Environment, WrappedSdkHarnessClient> 
createEnvironmentCache(
       ThrowingFunction<ServerFactory, ServerInfo> serverInfoCreator) {
-    return CacheBuilder.newBuilder()
-        .removalListener(
-            (RemovalNotification<Environment, WrappedSdkHarnessClient> 
notification) -> {
-              LOG.debug("Cleaning up for environment {}", 
notification.getKey().getUrn());
-              try {
-                notification.getValue().close();
-              } catch (Exception e) {
-                LOG.warn(
-                    String.format("Error cleaning up environment %s", 
notification.getKey()), e);
-              }
-            })
-        .build(
-            new CacheLoader<Environment, WrappedSdkHarnessClient>() {
-              @Override
-              public WrappedSdkHarnessClient load(Environment environment) 
throws Exception {
-                EnvironmentFactory.Provider environmentFactoryProvider =
-                    environmentFactoryProviderMap.get(environment.getUrn());
-                ServerFactory serverFactory = 
environmentFactoryProvider.getServerFactory();
-                ServerInfo serverInfo = serverInfoCreator.apply(serverFactory);
-
-                EnvironmentFactory environmentFactory =
-                    environmentFactoryProvider.createEnvironmentFactory(
-                        serverInfo.getControlServer(),
-                        serverInfo.getLoggingServer(),
-                        serverInfo.getRetrievalServer(),
-                        serverInfo.getProvisioningServer(),
-                        clientPool,
-                        stageIdGenerator);
-                return WrappedSdkHarnessClient.wrapping(
-                    environmentFactory.createEnvironment(environment), 
serverInfo);
-              }
-            });
+    CacheBuilder builder =
+        CacheBuilder.newBuilder()
+            .removalListener(
+                (RemovalNotification<Environment, WrappedSdkHarnessClient> 
notification) -> {
+                  int refCount = notification.getValue().unref();
+                  LOG.debug(
+                      "Removed environment {} with {} remaining bundle 
references.",
+                      notification.getKey(),
+                      refCount);
+                });
+
+    if (environmentExpirationMillis > 0) {
+      builder = builder.expireAfterWrite(environmentExpirationMillis, 
TimeUnit.MILLISECONDS);
+    }
+    return builder.build(
+        new CacheLoader<Environment, WrappedSdkHarnessClient>() {
+          @Override
+          public WrappedSdkHarnessClient load(Environment environment) throws 
Exception {
+            EnvironmentFactory.Provider environmentFactoryProvider =
+                environmentFactoryProviderMap.get(environment.getUrn());
+            ServerFactory serverFactory = 
environmentFactoryProvider.getServerFactory();
+            ServerInfo serverInfo = serverInfoCreator.apply(serverFactory);
+
+            EnvironmentFactory environmentFactory =
+                environmentFactoryProvider.createEnvironmentFactory(
+                    serverInfo.getControlServer(),
+                    serverInfo.getLoggingServer(),
+                    serverInfo.getRetrievalServer(),
+                    serverInfo.getProvisioningServer(),
+                    clientPool,
+                    stageIdGenerator);
+            return WrappedSdkHarnessClient.wrapping(
+                environmentFactory.createEnvironment(environment), serverInfo);
+          }
+        });
   }
 
   @Override
   public StageBundleFactory forStage(ExecutableStage executableStage) {
+    if (true) {
+      return new SmarterStageBundleFactory(executableStage);
+    }
 
 Review comment:
   Is this a TODO?
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 244043)
    Time Spent: 20m  (was: 10m)

> Option to expire SDK worker environments
> ----------------------------------------
>
>                 Key: BEAM-7348
>                 URL: https://issues.apache.org/jira/browse/BEAM-7348
>             Project: Beam
>          Issue Type: Improvement
>          Components: runner-core
>    Affects Versions: 2.12.0
>            Reporter: Thomas Weise
>            Assignee: Thomas Weise
>            Priority: Major
>              Labels: portability, portability-flink
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> We discovered that Python SDK workers are susceptible to memory leaks that 
> are quite hard to identify and/or fix. This becomes an issue in streaming 
> pipelines, where the workers run "forever". It would be good if the user has 
> an option to recycle the workers when there is no other practical way to 
> address (slow) resource leaks.



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

Reply via email to