Search in sources :

Example 1 with ThreadFactoryBuilder

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());
}
Also used : FnApiControlClientPoolService(org.apache.beam.runners.fnexecution.control.FnApiControlClientPoolService) InProcessServerFactory(org.apache.beam.sdk.fn.server.InProcessServerFactory) MapControlClientPool(org.apache.beam.runners.fnexecution.control.MapControlClientPool) ControlClientPool(org.apache.beam.runners.fnexecution.control.ControlClientPool) ThreadFactoryBuilder(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ThreadFactoryBuilder) InstructionRequestHandler(org.apache.beam.runners.fnexecution.control.InstructionRequestHandler)

Example 2 with ThreadFactoryBuilder

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);
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ThreadFactoryBuilder(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ThreadFactoryBuilder)

Example 3 with ThreadFactoryBuilder

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);
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ThreadFactoryBuilder) Ignore(org.junit.Ignore) Test(org.junit.Test) MetricsPusherTest(org.apache.beam.runners.core.metrics.MetricsPusherTest)

Example 4 with ThreadFactoryBuilder

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);
    }
}
Also used : IOException(java.io.IOException) DirectPipelineResult(org.apache.beam.runners.direct.DirectRunner.DirectPipelineResult) UserCodeException(org.apache.beam.sdk.util.UserCodeException) PipelineExecutionException(org.apache.beam.sdk.Pipeline.PipelineExecutionException) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ThreadFactoryBuilder) PTransformOverride(org.apache.beam.sdk.runners.PTransformOverride)

Example 5 with ThreadFactoryBuilder

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());
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) InProcessServerFactory(org.apache.beam.sdk.fn.server.InProcessServerFactory) ThreadFactoryBuilder(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ThreadFactoryBuilder) CoderException(org.apache.beam.sdk.coders.CoderException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ThreadFactoryBuilder (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ThreadFactoryBuilder)5 ExecutorService (java.util.concurrent.ExecutorService)2 InProcessServerFactory (org.apache.beam.sdk.fn.server.InProcessServerFactory)2 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 MetricsPusherTest (org.apache.beam.runners.core.metrics.MetricsPusherTest)1 DirectPipelineResult (org.apache.beam.runners.direct.DirectRunner.DirectPipelineResult)1 ControlClientPool (org.apache.beam.runners.fnexecution.control.ControlClientPool)1 FnApiControlClientPoolService (org.apache.beam.runners.fnexecution.control.FnApiControlClientPoolService)1 InstructionRequestHandler (org.apache.beam.runners.fnexecution.control.InstructionRequestHandler)1 MapControlClientPool (org.apache.beam.runners.fnexecution.control.MapControlClientPool)1 PipelineExecutionException (org.apache.beam.sdk.Pipeline.PipelineExecutionException)1 CoderException (org.apache.beam.sdk.coders.CoderException)1 PTransformOverride (org.apache.beam.sdk.runners.PTransformOverride)1 UserCodeException (org.apache.beam.sdk.util.UserCodeException)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1