private static <T> T serializeAndDeserialize(TypeToken<T> typeToken, T testData1) {
   SerializerScanner registry = SerializerScanner.defaultScanner();
   SerializerGen serializerGen = registry.serializer(typeToken);
   BufferSerializer<T> serializer = bufferSerializerFactory.createBufferSerializer(serializerGen);
   return serializeAndDeserialize(testData1, serializer, serializer);
 }
Пример #2
0
  public static void main(String[] args) {
    StreamConsumers.ToList<TestAdvResult> consumerToList;
    int iterations = 30;
    root.setLevel(Level.ERROR);
    DefiningClassLoader classLoader = new DefiningClassLoader();
    ExecutorService executor = Executors.newCachedThreadPool();
    Path aggregationsDir = Paths.get("test/aggregations/");
    NioEventloop eventloop = new NioEventloop();

    for (int i = 0; i < iterations + 1; ++i) {
      if (i == iterations - 1) {
        Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
        root.setLevel(Level.INFO);
      }
      if (i == iterations) {
        classLoader = new DefiningClassLoader();
      }
      logger.info("Benchmark started.");

      logger.info("Initialization started.");
      deleteRecursivelyQuietly(aggregationsDir);
      CubeStructure structure = getStructure(classLoader);
      AggregationStorage aggregationStorage =
          new LocalFsAggregationStorage(eventloop, executor, structure, aggregationsDir);
      Cube cube =
          newCube(
              eventloop,
              classLoader,
              new LogToCubeMetadataStorageStub(),
              aggregationStorage,
              structure);
      cube.addAggregation(new Aggregation("pub", asList("pub"), asList("pubRequests")));
      cube.addAggregation(new Aggregation("adv", asList("adv"), asList("advRequests")));

      Path dir = Paths.get("test/logs/");
      deleteRecursivelyQuietly(dir);
      LogFileSystemImpl fileSystem = new LogFileSystemImpl(eventloop, executor, dir);
      SerializerFactory bufferSerializerFactory =
          SerializerFactory.createBufferSerializerFactory(classLoader, true, true);
      SerializerScanner registry = SerializerScanner.defaultScanner();
      SerializerGen serializerGen = registry.serializer(TypeToken.of(TestPubRequest.class));
      BufferSerializer<TestPubRequest> bufferSerializer =
          bufferSerializerFactory.createBufferSerializer(serializerGen);

      LogManager<TestPubRequest> logManager =
          new LogManagerImpl<>(eventloop, fileSystem, bufferSerializer);

      LogToCubeRunner<TestPubRequest> logToCubeRunner =
          new LogToCubeRunner<>(
              eventloop,
              cube,
              logManager,
              TestAggregatorSplitter.factory(),
              "testlog",
              asList("partitionA"),
              new LogToCubeMetadataStorageStub());
      logger.info("Initialization finished.");

      int numberOfTestRequests = 100_000;
      logger.info("Started generating {} random requests.", numberOfTestRequests);
      List<TestPubRequest> pubRequests = generatePubRequests(numberOfTestRequests);
      long advRequests = countAdvRequests(pubRequests);
      logger.info("Finished generating random requests. Adv requests generated: {}", advRequests);

      logger.info("Started streaming to LogManager.");
      new StreamProducers.OfIterator<>(eventloop, pubRequests.iterator())
          .streamTo(logManager.consumer("partitionA"));

      eventloop.run();
      logger.info("Finished streaming to LogManager.");

      CompletionCallbackObserver cb = new CompletionCallbackObserver();
      logger.info("Started processing log.");
      logToCubeRunner.processLog(cb);

      eventloop.run();
      logger.info("Finished processing log.");
      cb.check();

      consumerToList = StreamConsumers.toList(eventloop);
      cube.query(
              0,
              TestAdvResult.class,
              new CubeQuery()
                  .dimension("adv")
                  .measure("advRequests")
                  .between("adv", 2500, 7500)
                  .orderDesc("advRequests"))
          .streamTo(consumerToList);
      logger.info("Started executing query.");
      eventloop.run();
      logger.info("Finished executing query.");

      logger.info("Benchmark finished.");
    }

    executor.shutdownNow();
  }