/** {@inheritDoc} */
  @Override
  protected GridConfiguration getConfiguration(String gridName) throws Exception {
    GridConfiguration c = super.getConfiguration(gridName);

    c.setLocalHost(HOST);

    assert c.getClientConnectionConfiguration() == null;

    GridClientConnectionConfiguration clientCfg = new GridClientConnectionConfiguration();

    clientCfg.setRestTcpPort(REST_TCP_PORT_BASE);

    GridSslContextFactory sslCtxFactory = sslContextFactory();

    if (sslCtxFactory != null) {
      clientCfg.setRestTcpSslEnabled(true);
      clientCfg.setRestTcpSslContextFactory(sslCtxFactory);
    }

    c.setClientConnectionConfiguration(clientCfg);

    GridTcpDiscoverySpi disco = new GridTcpDiscoverySpi();

    disco.setIpFinder(IP_FINDER);

    c.setDiscoverySpi(disco);

    TestCommunicationSpi spi = new TestCommunicationSpi();

    spi.setLocalPort(GridTestUtils.getNextCommPort(getClass()));

    c.setCommunicationSpi(spi);

    c.setCacheConfiguration(
        cacheConfiguration(null),
        cacheConfiguration(PARTITIONED_CACHE_NAME),
        cacheConfiguration(REPLICATED_CACHE_NAME),
        cacheConfiguration(REPLICATED_ASYNC_CACHE_NAME));

    ThreadPoolExecutor exec =
        new ThreadPoolExecutor(40, 40, 0, MILLISECONDS, new LinkedBlockingQueue<Runnable>());

    exec.prestartAllCoreThreads();

    c.setExecutorService(exec);

    c.setExecutorServiceShutdown(true);

    ThreadPoolExecutor sysExec =
        new ThreadPoolExecutor(40, 40, 0, MILLISECONDS, new LinkedBlockingQueue<Runnable>());

    sysExec.prestartAllCoreThreads();

    c.setSystemExecutorService(sysExec);

    c.setSystemExecutorServiceShutdown(true);

    return c;
  }
  static void oneRun(BlockingQueue<Runnable> q, int nThreads, int iters, boolean print)
      throws Exception {

    ThreadPoolExecutor pool =
        new ThreadPoolExecutor(nThreads + 1, Integer.MAX_VALUE, 1L, TimeUnit.SECONDS, q);

    CountDownLatch done = new CountDownLatch(iters);
    remaining.set(nThreads - 1);
    pool.prestartAllCoreThreads();
    Task t = new Task(pool, done);
    long start = System.nanoTime();
    pool.execute(t);
    done.await();
    long time = System.nanoTime() - start;
    if (print) System.out.println("\t: " + LoopHelpers.rightJustify(time / iters) + " ns per task");
    q.clear();
    Thread.sleep(100);
    pool.shutdown();
    Thread.sleep(100);
    pool.shutdownNow();
  }
Exemple #3
0
  public synchronized void start() {
    // register ESP/CEP engine
    cepProvider = CEPProvider.getCEPProvider();
    cepProvider.init(sleepListenerMillis);

    // register statements
    String suffix = Server.MODES.getProperty("_SUFFIX");
    if ("NOOP".equals(mode)) {;
    } else {
      String stmtString = Server.MODES.getProperty(mode) + " " + suffix;
      System.out.println("Using " + mode + " : " + stmtString);

      if (Server.MODES.getProperty(mode).indexOf('$') < 0) {
        cepProvider.registerStatement(stmtString, mode);
        System.out.println("\nStatements registered # 1 only");
      } else {
        // create a stmt for each symbol
        for (int i = 0; i < Symbols.SYMBOLS.length; i++) {
          if (i % 100 == 0) System.out.print(".");
          String ticker = Symbols.SYMBOLS[i];
          cepProvider.registerStatement(stmtString.replaceAll("\\$", ticker), mode + "-" + ticker);
        }
        System.out.println("\nStatements registered # " + Symbols.SYMBOLS.length);
      }
    }

    // start thread pool if any
    if (queueMax < 0) {
      executor = null;
      System.out.println("Using direct handoff, cpu#" + Runtime.getRuntime().availableProcessors());
    } else {
      // executor
      System.out.println(
          "Using ThreadPoolExecutor, cpu#"
              + Runtime.getRuntime().availableProcessors()
              + ", threadCore#"
              + threadCore
              + " queue#"
              + queueMax);
      BlockingQueue<Runnable> queue;
      if (queueMax == 0) {
        queue = new SynchronousQueue<Runnable>(true); // enforce fairness
      } else {
        queue = new LinkedBlockingQueue<Runnable>(queueMax);
      }

      executor =
          new ThreadPoolExecutor(
              threadCore,
              Runtime.getRuntime().availableProcessors() * threadCore,
              10,
              TimeUnit.SECONDS,
              queue,
              new ThreadFactory() {
                long count = 0;

                public Thread newThread(Runnable r) {
                  System.out.println("Create EsperServer thread " + (count + 1));
                  return new Thread(r, "EsperServer-" + count++);
                }
              },
              new ThreadPoolExecutor.CallerRunsPolicy() {
                public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
                  super.rejectedExecution(r, e);
                }
              });
      executor.prestartAllCoreThreads();
    }

    super.start();
  }