Exemple #1
0
  @Subscribe
  public void buildStarting(BuildStartingEvent event) {
    Preconditions.checkNotNull(workers);

    this.buildRequest = event.getRequest();

    WorkerOptions options = buildRequest.getOptions(WorkerOptions.class);
    workers.setMaxTotalPerKey(options.workerMaxInstances);
    workers.setMaxIdlePerKey(options.workerMaxInstances);
    workers.setMinIdlePerKey(options.workerMaxInstances);
    workers.setVerbose(options.workerVerbose);
    this.verbose = options.workerVerbose;
  }
 public void shutdown() {
   workerPool.shutdown();
   bossPool.shutdown();
   if (releasePool) {
     releasePool();
   }
 }
  public void engage() {
    // starts WorkerPool workers in separate thread(s)
    RingBuffer<DemoEvent> ringBuf = workerPool.start(execService);

    // publish lots of events
    for (int i = 0; i < 5 * NUM_WORKERS; i++) {
      long seq = ringBuf.next();
      ringBuf.get(seq).setProcessId(i);
      ringBuf.publish(seq);
      // try it with and without the sleep
      // try { Thread.sleep(33); } catch (Exception e) { }
    }

    // wait until all published events are processed, then stop the workers
    workerPool.drainAndHalt();
  }
Exemple #4
0
 // Kill workers on Ctrl-C to quickly end the interrupted build.
 // TODO(philwo) - make sure that this actually *kills* the workers and not just politely waits
 // for them to finish.
 @Subscribe
 public void buildInterrupted(BuildInterruptedEvent event) {
   if (workers != null) {
     if (verbose) {
       env.getReporter().handle(Event.info("Build interrupted, shutting down worker pool..."));
     }
     workers.close();
     workers = null;
   }
 }
Exemple #5
0
 @Subscribe
 public void buildComplete(BuildCompleteEvent event) {
   if (workers != null && buildRequest.getOptions(WorkerOptions.class).workerQuitAfterBuild) {
     if (verbose) {
       env.getReporter().handle(Event.info("Build completed, shutting down worker pool..."));
     }
     workers.close();
     workers = null;
   }
 }
  @Override
  protected long runDisruptorPass() throws InterruptedException {

    resetCounters();
    RingBuffer<ValueEvent> ringBuffer = workerPool.start(EXECUTOR);
    long start = System.currentTimeMillis();

    for (long i = 0; i < ITERATIONS; i++) {
      long sequence = ringBuffer.next();
      ringBuffer.getPreallocated(sequence).setValue(i);
      ringBuffer.publish(sequence);
    }

    workerPool.drainAndHalt();
    long opsPerSecond = (ITERATIONS * 1000L) / (System.currentTimeMillis() - start);

    assertEquals(ITERATIONS, sumCounters());

    return opsPerSecond;
  }
Exemple #7
0
  @Override
  public void beforeCommand(Command command, CommandEnvironment env) {
    this.env = env;
    env.getEventBus().register(this);

    if (workers == null) {
      Path logDir = env.getRuntime().getOutputBase().getRelative("worker-logs");
      try {
        logDir.createDirectory();
      } catch (IOException e) {
        env.getReporter()
            .handle(Event.error("Could not create directory for worker logs: " + logDir));
      }

      GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig();

      // It's better to re-use a worker as often as possible and keep it hot, in order to profit
      // from JIT optimizations as much as possible.
      config.setLifo(true);

      // Check for & deal with idle workers every 5 seconds.
      config.setTimeBetweenEvictionRunsMillis(5 * 1000);

      // Always test the liveliness of worker processes.
      config.setTestOnBorrow(true);
      config.setTestOnCreate(true);
      config.setTestOnReturn(true);
      config.setTestWhileIdle(true);

      // Don't limit the total number of worker processes, as otherwise the pool might be full of
      // e.g. Java workers and could never accommodate another request for a different kind of
      // worker.
      config.setMaxTotal(-1);

      workers = new WorkerPool(new WorkerFactory(), config);
      workers.setReporter(env.getReporter());
      workers.setLogDirectory(logDir);
    }
  }
 // mina.netty change -  adding this to create child datagram channels
 public NioChildDatagramChannel newChildChannel(Channel parent, final ChannelPipeline pipeline) {
   return new NioChildDatagramChannel(
       parent, this, pipeline, childSink, workerPool.nextWorker(), family);
 }
 public void releaseExternalResources() {
   workerPool.shutdown();
   bossPool.shutdown();
   releasePool();
 }
 @Override
 public void halt() {
   workerPool.halt();
 }
 @Override
 public void start(final Executor executor) {
   workerPool.start(executor);
 }
 @Override
 public Sequence[] getSequences() {
   return workerPool.getWorkerSequences();
 }