Beispiel #1
0
  /**
   * Tests the performance of an event listener on the map for Insert events of 2 MB strings. Expect
   * it to handle at least 50 2 MB updates per second.
   */
  @Test
  public void testSubscriptionMapEventListenerInsertPerformance() {
    _testMap.clear();

    YamlLogging.setAll(true);
    // Create subscriber and register
    TestChronicleMapEventListener mapEventListener =
        new TestChronicleMapEventListener(_mapName, _twoMbTestStringLength);

    Subscriber<MapEvent> mapEventSubscriber = e -> e.apply(mapEventListener);
    clientAssetTree.registerSubscriber(_mapName, MapEvent.class, mapEventSubscriber);

    Jvm.pause(100);
    KVSSubscription subscription =
        (KVSSubscription) serverAssetTree.getAsset(_mapName).subscription(false);
    Assert.assertEquals(1, subscription.entrySubscriberCount());

    // Perform test a number of times to allow the JVM to warm up, but verify runtime against
    // average
    TestUtils.runMultipleTimesAndVerifyAvgRuntime(
        i -> {
          if (i > 0) {
            waitFor(() -> mapEventListener.getNoOfInsertEvents().get() >= _noOfPuts);
            Assert.assertEquals(_noOfPuts, mapEventListener.getNoOfInsertEvents().get());
          }
          // Test that the correct number of events were triggered on event listener
          Assert.assertEquals(0, mapEventListener.getNoOfRemoveEvents().get());
          Assert.assertEquals(0, mapEventListener.getNoOfUpdateEvents().get());

          _testMap.clear();

          mapEventListener.resetCounters();
        },
        () -> {
          IntStream.range(0, _noOfPuts)
              .forEach(
                  i -> {
                    _testMap.put(TestUtils.getKey(_mapName, i), _twoMbTestString);
                  });
        },
        _noOfRunsToAverage,
        2 * _secondInNanos);

    clientAssetTree.unregisterSubscriber(_mapName, mapEventSubscriber);

    Jvm.pause(1000);
    Assert.assertEquals(0, subscription.entrySubscriberCount());
  }
Beispiel #2
0
  /**
   * Tests the performance of an event listener on the map for Update events of 2 MB strings. Expect
   * it to handle at least 50 2 MB updates per second.
   */
  @Test
  public void testSubscriptionMapEventListenerUpdatePerformance() {
    _testMap.clear();

    // Put values before testing as we want to ignore the insert events
    Function<Integer, Object> putFunction =
        a -> _testMap.put(TestUtils.getKey(_mapName, a), _twoMbTestString);

    IntStream.range(0, _noOfPuts)
        .forEach(
            i -> {
              putFunction.apply(i);
            });

    Jvm.pause(100);
    // Create subscriber and register
    TestChronicleMapEventListener mapEventListener =
        new TestChronicleMapEventListener(_mapName, _twoMbTestStringLength);

    Subscriber<MapEvent> mapEventSubscriber = e -> e.apply(mapEventListener);
    clientAssetTree.registerSubscriber(
        _mapName + "?bootstrap=false", MapEvent.class, mapEventSubscriber);

    KVSSubscription subscription =
        (KVSSubscription) serverAssetTree.getAsset(_mapName).subscription(false);

    waitFor(() -> subscription.entrySubscriberCount() == 1);
    Assert.assertEquals(1, subscription.entrySubscriberCount());

    // Perform test a number of times to allow the JVM to warm up, but verify runtime against
    // average
    TestUtils.runMultipleTimesAndVerifyAvgRuntime(
        i -> {
          if (i > 0) {
            waitFor(() -> mapEventListener.getNoOfUpdateEvents().get() >= _noOfPuts);

            // Test that the correct number of events were triggered on event listener
            Assert.assertEquals(_noOfPuts, mapEventListener.getNoOfUpdateEvents().get());
          }
          Assert.assertEquals(0, mapEventListener.getNoOfInsertEvents().get());
          Assert.assertEquals(0, mapEventListener.getNoOfRemoveEvents().get());

          mapEventListener.resetCounters();
        },
        () -> {
          IntStream.range(0, _noOfPuts)
              .forEach(
                  i -> {
                    putFunction.apply(i);
                  });
        },
        _noOfRunsToAverage,
        3 * _secondInNanos);
    clientAssetTree.unregisterSubscriber(_mapName, mapEventSubscriber);

    waitFor(() -> subscription.entrySubscriberCount() == 0);
    Assert.assertEquals(0, subscription.entrySubscriberCount());
  }
Beispiel #3
0
  /**
   * Test that listening to events for a given key can handle 50 updates per second of 2 MB string
   * values.
   */
  @Test
  public void testSubscriptionMapEventOnKeyPerformance() {
    _testMap.clear();

    String key = TestUtils.getKey(_mapName, 0);

    // Create subscriber and register
    // Add 4 for the number of puts that is added to the string
    TestChronicleKeyEventSubscriber keyEventSubscriber =
        new TestChronicleKeyEventSubscriber(_twoMbTestStringLength);

    clientAssetTree.registerSubscriber(
        _mapName + "/" + key + "?bootstrap=false", String.class, keyEventSubscriber);
    Jvm.pause(100);
    Asset child = serverAssetTree.getAsset(_mapName).getChild(key);
    Assert.assertNotNull(child);
    Subscription subscription = child.subscription(false);
    Assert.assertEquals(1, subscription.subscriberCount());

    long start = System.nanoTime();
    // Perform test a number of times to allow the JVM to warm up, but verify runtime against
    // average
    TestUtils.runMultipleTimesAndVerifyAvgRuntime(
        () -> {
          IntStream.range(0, _noOfPuts)
              .forEach(
                  i -> {
                    _testMap.put(key, _twoMbTestString);
                  });
        },
        _noOfRunsToAverage,
        3 * _secondInNanos);

    waitFor(() -> keyEventSubscriber.getNoOfEvents().get() >= _noOfPuts * _noOfRunsToAverage);
    long time = System.nanoTime() - start;
    System.out.printf("Took %.3f seconds to receive all events%n", time / 1e9);

    // Test that the correct number of events was triggered on event listener
    Assert.assertEquals(_noOfPuts * _noOfRunsToAverage, keyEventSubscriber.getNoOfEvents().get());

    clientAssetTree.unregisterSubscriber(_mapName + "/" + key, keyEventSubscriber);

    Jvm.pause(100);
    Assert.assertEquals(0, subscription.subscriberCount());
  }
Beispiel #4
0
  /**
   * Test that listening to events for a given map can handle 50 updates per second of 2 MB string
   * values and are triggering events which contain both the key and value (topic).
   */
  @Test
  public void testSubscriptionMapEventOnTopicPerformance() {
    _testMap.clear();

    String key = TestUtils.getKey(_mapName, 0);

    // Create subscriber and register
    TestChronicleTopicSubscriber topicSubscriber =
        new TestChronicleTopicSubscriber(key, _twoMbTestStringLength);

    clientAssetTree.registerTopicSubscriber(_mapName, String.class, String.class, topicSubscriber);

    Jvm.pause(100);
    KVSSubscription subscription =
        (KVSSubscription) serverAssetTree.getAsset(_mapName).subscription(false);
    Assert.assertEquals(1, subscription.topicSubscriberCount());

    // Perform test a number of times to allow the JVM to warm up, but verify runtime against
    // average
    TestUtils.runMultipleTimesAndVerifyAvgRuntime(
        i -> {
          System.out.println("test");
          int events = _noOfPuts * i;
          waitFor(() -> events == topicSubscriber.getNoOfEvents().get());
          Assert.assertEquals(events, topicSubscriber.getNoOfEvents().get());
        },
        () -> {
          IntStream.range(0, _noOfPuts)
              .forEach(
                  i -> {
                    _testMap.put(key, _twoMbTestString);
                  });
        },
        _noOfRunsToAverage,
        3 * _secondInNanos);

    // Test that the correct number of events was triggered on event listener
    int events = _noOfPuts * _noOfRunsToAverage;
    waitFor(() -> events == topicSubscriber.getNoOfEvents().get());
    Assert.assertEquals(events, topicSubscriber.getNoOfEvents().get());

    clientAssetTree.unregisterTopicSubscriber(_mapName, topicSubscriber);
    waitFor(() -> 0 == subscription.topicSubscriberCount());
    Assert.assertEquals(0, subscription.topicSubscriberCount());
  }
 @Override
 public void run() {
   while (running && !Thread.currentThread().isInterrupted()) {
     Jvm.pause(1);
     long delay = System.nanoTime() - sample;
     if (delay > 1000 * 1000) {
       System.out.println(
           "\n"
               + (System.currentTimeMillis() - START_TIME)
               + " : Delay of "
               + delay / 100000 / 10.0
               + " ms.");
       int count = 0;
       for (StackTraceElement ste : thread.getStackTrace()) {
         System.out.println("\tat " + ste);
         if (count++ > 6) break;
       }
     }
   }
 }
 public static void reset() {
   DESC_TO_SERVER_SOCKET_CHANNEL_MAP.values().forEach(Closeable::closeQuietly);
   HOSTNAME_PORT_ALIAS.clear();
   DESC_TO_SERVER_SOCKET_CHANNEL_MAP.clear();
   Jvm.pause(500);
 }
Beispiel #7
0
 private void waitFor(BooleanSupplier b) {
   for (int i = 1; i <= 40; i++) if (!b.getAsBoolean()) Jvm.pause(i * i);
 }