use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ThreadFactoryBuilder in project beam by apache.
the class EmbeddedSdkHarness method before.
@Override
protected void before() throws Exception {
InProcessServerFactory serverFactory = InProcessServerFactory.create();
executor = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).build());
ControlClientPool clientPool = MapControlClientPool.create();
FnApiControlClientPoolService clientPoolService = FnApiControlClientPoolService.offeringClientsToPool(clientPool.getSink(), GrpcContextHeaderAccessorProvider.getHeaderAccessor());
loggingServer = GrpcFnServer.allocatePortAndCreateFor(GrpcLoggingService.forWriter(Slf4jLogWriter.getDefault()), serverFactory);
dataServer = GrpcFnServer.allocatePortAndCreateFor(GrpcDataService.create(PipelineOptionsFactory.create(), executor, OutboundObserverFactory.serverDirect()), serverFactory);
controlServer = GrpcFnServer.allocatePortAndCreateFor(clientPoolService, serverFactory);
InstructionRequestHandler requestHandler = EmbeddedEnvironmentFactory.create(PipelineOptionsFactory.create(), loggingServer, controlServer, clientPool.getSource()).createEnvironment(Environment.getDefaultInstance(), "embedded_worker").getInstructionRequestHandler();
client = SdkHarnessClient.usingFnApiClient(requestHandler, dataServer.getService());
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ThreadFactoryBuilder in project beam by apache.
the class MetricsPusher method start.
public void start() {
if (!(metricsSink instanceof NoOpMetricsSink)) {
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("MetricsPusher-thread").build());
scheduledFuture = scheduler.scheduleAtFixedRate(this::run, 0, period, TimeUnit.SECONDS);
}
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ThreadFactoryBuilder in project beam by apache.
the class ExecutorServiceParallelExecutorTest method ensureMetricsThreadDoesntLeak.
@Test
@Ignore("https://issues.apache.org/jira/browse/BEAM-4088 Test reliably fails.")
public void ensureMetricsThreadDoesntLeak() throws ExecutionException, InterruptedException {
final DirectGraph graph = DirectGraph.create(emptyMap(), emptyMap(), LinkedListMultimap.create(), emptySet(), emptyMap());
final ExecutorService metricsExecutorService = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setDaemon(false).setNameFormat("dontleak_" + getClass().getName() + "#" + testName.getMethodName()).build());
// fake a metrics usage
metricsExecutorService.submit(() -> {
}).get();
final EvaluationContext context = EvaluationContext.create(MockClock.fromInstant(Instant.now()), CloningBundleFactory.create(), graph, emptySet(), metricsExecutorService);
ExecutorServiceParallelExecutor.create(2, TransformEvaluatorRegistry.javaSdkNativeRegistry(context, PipelineOptionsFactory.create().as(DirectOptions.class)), emptyMap(), context, metricsExecutorService).stop();
try {
metricsExecutorService.awaitTermination(10L, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ThreadFactoryBuilder in project beam by apache.
the class DirectRunner method run.
@Override
public DirectPipelineResult run(Pipeline pipeline) {
try {
options = MAPPER.readValue(MAPPER.writeValueAsBytes(options), PipelineOptions.class).as(DirectOptions.class);
} catch (IOException e) {
throw new IllegalArgumentException("PipelineOptions specified failed to serialize to JSON.", e);
}
performRewrites(pipeline);
MetricsEnvironment.setMetricsSupported(true);
try {
DirectGraphVisitor graphVisitor = new DirectGraphVisitor();
pipeline.traverseTopologically(graphVisitor);
@SuppressWarnings("rawtypes") KeyedPValueTrackingVisitor keyedPValueVisitor = KeyedPValueTrackingVisitor.create();
pipeline.traverseTopologically(keyedPValueVisitor);
DisplayDataValidator.validatePipeline(pipeline);
DisplayDataValidator.validateOptions(options);
ExecutorService metricsPool = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setThreadFactory(MoreExecutors.platformThreadFactory()).setDaemon(// otherwise you say you want to leak, please don't!
false).setNameFormat("direct-metrics-counter-committer").build());
DirectGraph graph = graphVisitor.getGraph();
EvaluationContext context = EvaluationContext.create(clockSupplier.get(), Enforcement.bundleFactoryFor(enabledEnforcements, graph), graph, keyedPValueVisitor.getKeyedPValues(), metricsPool);
TransformEvaluatorRegistry registry = TransformEvaluatorRegistry.javaSdkNativeRegistry(context, options);
PipelineExecutor executor = ExecutorServiceParallelExecutor.create(options.getTargetParallelism(), registry, Enforcement.defaultModelEnforcements(enabledEnforcements), context, metricsPool);
executor.start(graph, RootProviderRegistry.javaNativeRegistry(context, options));
DirectPipelineResult result = new DirectPipelineResult(executor, context);
if (options.isBlockOnRun()) {
try {
result.waitUntilFinish();
} catch (UserCodeException userException) {
throw new PipelineExecutionException(userException.getCause());
} catch (Throwable t) {
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
throw new RuntimeException(t);
}
}
return result;
} finally {
MetricsEnvironment.setMetricsSupported(false);
}
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ThreadFactoryBuilder in project beam by apache.
the class RemoteExecutionTest method launchSdkHarness.
public void launchSdkHarness(PipelineOptions options) throws Exception {
// Setup execution-time servers
ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true).build();
serverExecutor = Executors.newCachedThreadPool(threadFactory);
InProcessServerFactory serverFactory = InProcessServerFactory.create();
dataServer = GrpcFnServer.allocatePortAndCreateFor(GrpcDataService.create(PipelineOptionsFactory.create(), serverExecutor, OutboundObserverFactory.serverDirect()), serverFactory);
loggingServer = GrpcFnServer.allocatePortAndCreateFor(GrpcLoggingService.forWriter(Slf4jLogWriter.getDefault()), serverFactory);
stateDelegator = GrpcStateService.create();
stateServer = GrpcFnServer.allocatePortAndCreateFor(stateDelegator, serverFactory);
ControlClientPool clientPool = MapControlClientPool.create();
controlServer = GrpcFnServer.allocatePortAndCreateFor(FnApiControlClientPoolService.offeringClientsToPool(clientPool.getSink(), GrpcContextHeaderAccessorProvider.getHeaderAccessor()), serverFactory);
// Create the SDK harness, and wait until it connects
sdkHarnessExecutor = Executors.newSingleThreadExecutor(threadFactory);
sdkHarnessExecutorFuture = sdkHarnessExecutor.submit(() -> {
try {
FnHarness.main(WORKER_ID, options, // Runner capabilities.
Collections.emptySet(), loggingServer.getApiServiceDescriptor(), controlServer.getApiServiceDescriptor(), null, ManagedChannelFactory.createInProcess(), OutboundObserverFactory.clientDirect(), Caches.eternal());
} catch (Exception e) {
throw new RuntimeException(e);
}
});
InstructionRequestHandler controlClient = clientPool.getSource().take(WORKER_ID, java.time.Duration.ofSeconds(2));
this.controlClient = SdkHarnessClient.usingFnApiClient(controlClient, dataServer.getService());
}
Aggregations