Ejemplo n.º 1
0
  public static void main(String args[]) throws IOException {
    BasicConfigurator.configure();
    Map<String, String> config = parseArguments(args);
    BasicConfigurator.configure();
    if (config.get(LOG4J) != null) {
      PropertyConfigurator.configure(config.get("log4j"));
    } else {
      PropertyConfigurator.configure(
          System.getProperty("user.dir")
              + File.separator
              + "etc"
              + File.separator
              + Config.CONFIG_DEFAULT_MILE_LOG_PROPERTIES);
    }
    OptionParser parser = new OptionParser();
    parser.accepts(SELECT, "execute select operations").withOptionalArg().ofType(Integer.class);
    parser.accepts(INSERT, "execute insert operations").withOptionalArg().ofType(Integer.class);
    parser
        .accepts(THREADS, "max number concurrent worker threads  Default = 1")
        .withRequiredArg()
        .ofType(Integer.class);
    parser
        .accepts(ITERATIONS, "number of times to repeat the test  Default = 1")
        .withRequiredArg()
        .ofType(Integer.class);
    parser.accepts(VERIFY, "verify values read");
    parser
        .accepts(INTERVAL, "print requests on this interval  Default = 0")
        .withRequiredArg()
        .ofType(Integer.class);
    parser.accepts(LOG4J, "log4j into mod ").withRequiredArg().ofType(String.class);
    parser.accepts(TARGET_THROUGHPUT, "fix the throughput").withRequiredArg().ofType(Integer.class);
    parser.accepts(OPS_COUNT, "number of operations to do").withRequiredArg().ofType(Integer.class);
    parser.accepts(METRIC_TYPE, "type of metric [histogram | summary]").withRequiredArg();
    parser
        .accepts(CONFIG_FILE, "the config file path of the mile client")
        .withRequiredArg()
        .ofType(String.class);
    parser.accepts(INSERT_CMD, "the cmd of insert").withRequiredArg().ofType(String.class);
    parser.accepts(SELECT_CMD, "the cmd of select").withRequiredArg().ofType(String.class);
    parser
        .accepts(INSERT_PARAMS, "the params of insert preSql")
        .withRequiredArg()
        .ofType(String.class);
    parser
        .accepts(SELECT_PARAMS, "the params of select preSql")
        .withRequiredArg()
        .ofType(String.class);
    parser.accepts(RECORD_FILE, "the record file path").withOptionalArg().ofType(String.class);
    parser.accepts(CMD_PROVIDER, "command provider").withOptionalArg().ofType(String.class);
    parser
        .accepts(CTU_SIMILAR_THRESHOLD, "ctu minisearch similarity threshold")
        .withOptionalArg()
        .ofType(Float.class);
    parser
        .accepts(CTU_MINISEARCH_LIMIT, "ctu minisearch query limit")
        .withOptionalArg()
        .ofType(Integer.class);
    parser.accepts(
        CTU_MINISEARCH_CONTAIN_ORIGINAL,
        "ctu minisearch contain original text when parse the text");

    parser.accepts(HELP);

    OptionSet options = parser.parse(args);

    if (options.has(HELP)) {
      parser.printHelpOn(System.out);
      System.exit(0);
    }

    Props mainProps = new Props();

    if (!options.has(OPS_COUNT)) {
      printUsage(parser, "Missing " + OPS_COUNT);
    }
    mainProps.put(OPS_COUNT, (Integer) options.valueOf(OPS_COUNT));

    if (options.has(VERIFY)) {
      mainProps.put(VERIFY, "true");
    } else {
      mainProps.put(VERIFY, "false");
    }
    if (options.has(CTU_MINISEARCH_CONTAIN_ORIGINAL)) {
      mainProps.put(CTU_MINISEARCH_CONTAIN_ORIGINAL, "true");
    } else {
      mainProps.put(CTU_MINISEARCH_CONTAIN_ORIGINAL, "false");
    }

    if (!options.has(CONFIG_FILE)) {
      printUsage(parser, "Missing " + CONFIG_FILE);
      mainProps.put(
          CONFIG_FILE,
          System.getProperty("user.dir")
              + File.separator
              + "etc"
              + File.separator
              + "mileCliClent.properties.prod");
    } else {
      mainProps.put(CONFIG_FILE, (String) options.valueOf(CONFIG_FILE));
    }
    if (options.has(RECORD_FILE)) {
      mainProps.put(RECORD_FILE, (String) options.valueOf(RECORD_FILE));
    }
    if (options.has(CMD_PROVIDER)) {
      mainProps.put(CMD_PROVIDER, (String) options.valueOf(CMD_PROVIDER));
    }
    mainProps.put(INSERT, CmdUtils.valueOf(options, INSERT, 0));
    mainProps.put(SELECT, CmdUtils.valueOf(options, SELECT, 0));
    mainProps.put(INSERT_CMD, (String) options.valueOf(INSERT_CMD));
    mainProps.put(SELECT_CMD, (String) options.valueOf(SELECT_CMD));
    mainProps.put(INSERT_PARAMS, (String) options.valueOf(INSERT_PARAMS));
    mainProps.put(SELECT_PARAMS, (String) options.valueOf(SELECT_PARAMS));
    mainProps.put(ITERATIONS, CmdUtils.valueOf(options, ITERATIONS, 1));
    mainProps.put(THREADS, CmdUtils.valueOf(options, THREADS, MAX_WORKERS));
    mainProps.put(INTERVAL, CmdUtils.valueOf(options, INTERVAL, 0));
    mainProps.put(TARGET_THROUGHPUT, CmdUtils.valueOf(options, TARGET_THROUGHPUT, -1));
    mainProps.put(METRIC_TYPE, CmdUtils.valueOf(options, METRIC_TYPE, SUMMARY_METRIC_TYPE));
    mainProps.put(
        CTU_SIMILAR_THRESHOLD, CmdUtils.valueOf(options, CTU_SIMILAR_THRESHOLD, (float) 0.7));
    mainProps.put(CTU_MINISEARCH_LIMIT, CmdUtils.valueOf(options, CTU_MINISEARCH_LIMIT, 100));

    // Start the benchmark
    Benchmark benchmark = null;
    try {
      benchmark = new Benchmark();
      benchmark.initialize(mainProps);
      benchmark.warmUpAndRun();
      benchmark.close();
    } catch (Exception e) {
      LOGGER.error(e);
      parser.printHelpOn(System.err);
      System.exit(-1);
    }
    System.exit(-1);
  }