/** * Initialize the workload. Called once, in the main client thread, before any operations are * started. * * @throws IOException * @throws ClassNotFoundException */ public void init(Props props) throws IOException { CmdProvider cmdProvider; int readPercent = props.getInt(Benchmark.SELECT, 0); int writePercent = props.getInt(Benchmark.INSERT, 0); double readProportion = (double) readPercent / (double) 100; double writeProportion = (double) writePercent / (double) 100; if (readProportion + writeProportion > 0) { double sum = readProportion + writeProportion; readProportion = readProportion / sum; writeProportion = writeProportion / sum; } if (readProportion > 0) { cmdProvider = new QueryProvider(props); operationChooser.addValue(readProportion, cmdProvider.getName()); operations.put(cmdProvider.getName(), cmdProvider); } if (writeProportion > 0) { cmdProvider = new InsertProvider(props); operationChooser.addValue(writeProportion, cmdProvider.getName()); operations.put(cmdProvider.getName(), cmdProvider); } if (props.containsKey(Benchmark.RECORD_FILE)) { String cmd = props.getString(Benchmark.CMD_PROVIDER, ""); if (StringUtils.startsWith(cmd, "ctu_minisearch")) { cmdProvider = new CtuMiniSearchProvider(props); } else { cmdProvider = new SqlFileProvider(props); } operationChooser.addValue(1.0, cmdProvider.getName()); operations.put(cmdProvider.getName(), cmdProvider); } }
public void initializeWorkload(Props workloadProps) throws MileException, IOException { if (!this.storeInitialized) { throw new MileException("Store not initialized correctly"); } // Calculate perThreadThroughputPerMs = default unlimited (-1) this.targetThroughput = workloadProps.getInt(TARGET_THROUGHPUT, -1); this.perThreadThroughputPerMs = -1; if (targetThroughput > 0) { double targetperthread = ((double) targetThroughput) / ((double) numThreads); this.perThreadThroughputPerMs = targetperthread / 1000.0; } // Compulsory parameters if (workloadProps.containsKey(OPS_COUNT)) { this.opsCount = workloadProps.getInt(OPS_COUNT); } else { throw new MileException("Missing compulsory parameters - " + OPS_COUNT); } // Initialize measurement Metrics.setProperties(workloadProps); Metrics.getInstance().reset(); // Initialize workload this.workLoad = new Workload(); this.workLoad.init(workloadProps); }
public void initializeStore(Props benchmarkProps) throws UnsupportedEncodingException { this.numThreads = benchmarkProps.getInt(THREADS, MAX_WORKERS); this.numIterations = benchmarkProps.getInt(ITERATIONS, 1); this.statusIntervalSec = benchmarkProps.getInt(INTERVAL, 0); this.verifyRead = benchmarkProps.getBoolean(VERIFY, false); /** 初始化mile client */ this.applicationClient = new ApplationClientImpl(); this.applicationClient.readProperties(benchmarkProps.getString(CONFIG_FILE)); this.applicationClient.setBossExecutorCount(16); this.applicationClient.setWorkerExecutorCount(16); this.applicationClient.init(); this.storeInitialized = true; }
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); }