Exemplo n.º 1
0
  public QueueBuilder getRequestQueueBuilder() {

    if (requestQueueBuilder == null) {
      requestQueueBuilder = QueueBuilder.queueBuilder();
    }

    return requestQueueBuilder;
  }
Exemplo n.º 2
0
  public QueueBuilder getResponseQueueBuilder() {

    if (responseQueueBuilder == null) {

      if (responseQueue == null) {
        responseQueueBuilder = QueueBuilder.queueBuilder();
      } else {

        responseQueueBuilder =
            new QueueBuilder() {

              @Override
              public <T> Queue<T> build() {
                //noinspection unchecked
                return (Queue<T>) responseQueue;
              }
            };
      }
    }

    return responseQueueBuilder;
  }
Exemplo n.º 3
0
  private static void run(
      int runs,
      int tradeCount,
      final int batchSize,
      int checkEvery,
      int numThreads,
      boolean forceLinkTransferQueue,
      int subscriberCount)
      throws InterruptedException {

    final QueueBuilder queueBuilder =
        QueueBuilder.queueBuilder().setName("trades").setBatchSize(batchSize).setSize(1_000_000);

    if (checkEvery > 0 || forceLinkTransferQueue) {
      queueBuilder.setLinkTransferQueue();
      queueBuilder.setCheckEvery(checkEvery);
    }

    final Queue<Trade> queue = queueBuilder.build();

    final AtomicLong tradeCounterReceived = new AtomicLong();

    final AtomicLong tradeCounterSent = new AtomicLong();

    final int totalTradeCount = tradeCount * numThreads;
    final QueueToStreamRoundRobin<Trade> stream = new QueueToStreamRoundRobin<>(queue);

    for (int s = 0; s < subscriberCount; s++) {
      stream.subscribe(
          new Subscriber<Trade>() {

            int count = batchSize / subscriberCount;
            Subscription subscription;

            @Override
            public void onSubscribe(Subscription s) {
              subscription = s;
              s.request(count);
            }

            @Override
            public void onNext(Trade trade) {
              tradeCounterReceived.incrementAndGet();
              trade.getName();
              trade.getAmount();

              count--;
              if (count == 0) {
                count = batchSize / subscriberCount;
                subscription.request(count);
              }
            }

            @Override
            public void onError(Throwable t) {}

            @Override
            public void onComplete() {}
          });
    }

    final long startRun = System.currentTimeMillis();

    for (int r = 0; r < runs; r++) {

      List<Thread> threads = new ArrayList<>(numThreads);

      tradeCounterReceived.set(0L);
      tradeCounterSent.set(0L);

      for (int t = 0; t < numThreads; t++) {

        Thread thread =
            new Thread(
                () -> {
                  sendMessages(tradeCount, queue);
                });

        thread.start();
        threads.add(thread);
      }

      for (int index = 0; index < 100000; index++) {
        Sys.sleep(10);
        if (tradeCounterReceived.get() >= totalTradeCount) {
          break;
        }
      }
    }

    System.out.printf(
        "DONE PUB traded %,d in %d batchSize = %,d, checkEvery = %,d, threads=%d\n",
        tradeCount * runs * numThreads,
        System.currentTimeMillis() - startRun,
        batchSize,
        checkEvery,
        numThreads);
    queue.stop();
  }
Exemplo n.º 4
0
 public QueueBuilder getWebResponseQueueBuilder() {
   if (webResponseQueueBuilder == null) {
     webResponseQueueBuilder = QueueBuilder.queueBuilder();
   }
   return webResponseQueueBuilder;
 }
Exemplo n.º 5
0
 public QueueBuilder getResponseQueueBuilder() {
   if (responseQueueBuilder == null) {
     this.responseQueueBuilder = QueueBuilder.queueBuilder();
   }
   return responseQueueBuilder;
 }