use of com.orientechnologies.orient.stresstest.workload.OWorkload in project orientdb by orientechnologies.
the class OStressTesterCommandLineParser method getStressTester.
/**
* builds a StressTester object using the command line arguments
*
* @param args
*
* @return
*
* @throws Exception
*/
public static OStressTester getStressTester(String[] args) throws Exception {
final Map<String, String> options = checkOptions(readOptions(args));
final OStressTesterSettings settings = new OStressTesterSettings();
settings.dbName = TEMP_DATABASE_NAME + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
if (options.get(OPTION_DBNAME) != null)
settings.dbName = options.get(OPTION_DBNAME);
settings.mode = OStressTester.OMode.valueOf(options.get(OPTION_MODE).toUpperCase());
settings.rootPassword = options.get(OPTION_ROOT_PASSWORD);
settings.resultOutputFile = options.get(OPTION_OUTPUT_FILE);
settings.plocalPath = options.get(OPTION_PLOCAL_PATH);
settings.operationsPerTransaction = getNumber(options.get(OPTION_TRANSACTIONS), "transactions");
settings.delay = getNumber(options.get(OPTION_DELAY), "delay");
settings.concurrencyLevel = getNumber(options.get(OPTION_CONCURRENCY), "concurrency");
settings.remoteIp = options.get(OPTION_REMOTE_IP);
settings.haMetrics = options.get(OPTION_HA_METRICS) != null ? Boolean.parseBoolean(options.get(OPTION_HA_METRICS)) : false;
settings.workloadCfg = options.get(OPTION_WORKLOAD);
settings.keepDatabaseAfterTest = options.get(OPTION_KEEP_DATABASE_AFTER_TEST) != null ? Boolean.parseBoolean(options.get(OPTION_KEEP_DATABASE_AFTER_TEST)) : false;
settings.remotePort = 2424;
settings.checkDatabase = Boolean.parseBoolean(options.get(OPTION_CHECK_DATABASE));
if (options.get(OPTION_LOAD_BALANCING) != null)
settings.loadBalancing = OStorageRemote.CONNECTION_STRATEGY.valueOf(options.get(OPTION_LOAD_BALANCING).toUpperCase());
if (settings.plocalPath != null) {
if (settings.plocalPath.endsWith(File.separator)) {
settings.plocalPath = settings.plocalPath.substring(0, settings.plocalPath.length() - File.separator.length());
}
File plocalFile = new File(settings.plocalPath);
if (!plocalFile.exists()) {
throw new IllegalArgumentException(String.format(COMMAND_LINE_PARSER_NOT_EXISTING_PLOCAL_PATH, settings.plocalPath));
}
if (!plocalFile.canWrite()) {
throw new IllegalArgumentException(String.format(COMMAND_LINE_PARSER_NO_WRITE_PERMISSION_PLOCAL_PATH, settings.plocalPath));
}
if (!plocalFile.isDirectory()) {
throw new IllegalArgumentException(String.format(COMMAND_LINE_PARSER_PLOCAL_PATH_IS_NOT_DIRECTORY, settings.plocalPath));
}
}
if (settings.resultOutputFile != null) {
File outputFile = new File(settings.resultOutputFile);
if (outputFile.exists()) {
outputFile.delete();
}
File parentFile = outputFile.getParentFile();
// if the filename does not contain a path (both relative and absolute)
if (parentFile == null) {
parentFile = new File(".");
}
if (!parentFile.exists()) {
throw new IllegalArgumentException(String.format(COMMAND_LINE_PARSER_NOT_EXISTING_OUTPUT_DIRECTORY, parentFile.getAbsoluteFile()));
}
if (!parentFile.canWrite()) {
throw new IllegalArgumentException(String.format(COMMAND_LINE_PARSER_NO_WRITE_PERMISSION_OUTPUT_FILE, parentFile.getAbsoluteFile()));
}
}
if (options.get(OPTION_REMOTE_PORT) != null) {
settings.remotePort = getNumber(options.get(OPTION_REMOTE_PORT), "remotePort");
if (settings.remotePort > 65535) {
throw new IllegalArgumentException(String.format(COMMAND_LINE_PARSER_INVALID_REMOTE_PORT_NUMBER, settings.remotePort));
}
}
if (settings.mode == OStressTester.OMode.DISTRIBUTED) {
throw new IllegalArgumentException(String.format("OMode [%s] not yet supported.", settings.mode));
}
if (settings.mode == OStressTester.OMode.REMOTE && settings.remoteIp == null) {
throw new IllegalArgumentException(COMMAND_LINE_PARSER_MISSING_REMOTE_IP);
}
if (settings.rootPassword == null && settings.mode == OStressTester.OMode.REMOTE) {
Console console = System.console();
if (console != null) {
settings.rootPassword = String.valueOf(console.readPassword(String.format(CONSOLE_REMOTE_PASSWORD_PROMPT, settings.remoteIp, settings.remotePort)));
} else {
throw new Exception(ERROR_OPENING_CONSOLE);
}
}
final List<OWorkload> workloads = parseWorkloads(settings.workloadCfg);
final ODatabaseIdentifier databaseIdentifier = new ODatabaseIdentifier(settings);
return new OStressTester(workloads, databaseIdentifier, settings);
}
use of com.orientechnologies.orient.stresstest.workload.OWorkload in project orientdb by orientechnologies.
the class OStressTesterCommandLineParser method parseWorkloads.
private static List<OWorkload> parseWorkloads(final String workloadConfig) {
if (workloadConfig == null || workloadConfig.isEmpty())
throw new IllegalArgumentException("Workload parameter is mandatory. Syntax: <workload-name:workload-params>");
final List<OWorkload> result = new ArrayList<OWorkload>();
final String[] parts = workloadConfig.split(",");
for (String part : parts) {
String workloadName;
String workloadParams;
final int pos = part.indexOf(":");
if (pos > -1) {
workloadName = part.substring(0, pos);
workloadParams = part.substring(pos + 1);
} else {
workloadName = part;
workloadParams = null;
}
final OWorkload workload = OStressTester.getWorkloadFactory().get(workloadName);
if (workload == null)
throw new IllegalArgumentException("Workload '" + workloadName + "' is not configured. Use one of the following: " + OStressTester.getWorkloadFactory().getRegistered());
workload.parseParameters(workloadParams);
result.add(workload);
}
return result;
}
use of com.orientechnologies.orient.stresstest.workload.OWorkload in project orientdb by orientechnologies.
the class OStressTester method writeFile.
private void writeFile() {
try {
final StringBuilder output = new StringBuilder();
output.append("{\"result\":[");
int i = 0;
for (OWorkload workload : workloads) {
if (i++ > 0)
output.append(",");
output.append(workload.getFinalResultAsJson());
}
output.append("]}");
OIOUtils.writeFile(new File(settings.resultOutputFile), output.toString());
} catch (IOException e) {
System.err.println("\nError on writing the result file : " + e.getMessage());
}
}
use of com.orientechnologies.orient.stresstest.workload.OWorkload in project orientdb by orientechnologies.
the class OStressTester method execute.
@SuppressWarnings("unchecked")
public int execute() throws Exception {
int returnCode = 0;
// we don't want logs from DB
OLogManager.instance().setConsoleLevel("SEVERE");
// creates the temporary DB where to execute the test
ODatabaseUtils.createDatabase(databaseIdentifier);
System.out.println(String.format("Created database [%s].", databaseIdentifier.getUrl()));
try {
for (OWorkload workload : workloads) {
consoleProgressWriter = new OConsoleProgressWriter(workload);
consoleProgressWriter.start();
consoleProgressWriter.printMessage(String.format("\nStarting workload %s (concurrencyLevel=%d)...", workload.getName(), settings.concurrencyLevel));
final long startTime = System.currentTimeMillis();
workload.execute(settings, databaseIdentifier);
final long endTime = System.currentTimeMillis();
consoleProgressWriter.sendShutdown();
System.out.println(String.format("\n- Total execution time: %.3f secs", ((float) (endTime - startTime) / 1000f)));
System.out.println(workload.getFinalResult());
dumpHaMetrics();
if (settings.checkDatabase && workload instanceof OCheckWorkload) {
System.out.println(String.format("- Checking database..."));
((OCheckWorkload) workload).check(databaseIdentifier);
System.out.println(String.format("- Check completed"));
}
}
if (settings.resultOutputFile != null)
writeFile();
} catch (Exception ex) {
System.err.println("\nAn error has occurred while running the stress test: " + ex.getMessage());
returnCode = 1;
} finally {
// we don't need to drop the in-memory DB
if (settings.keepDatabaseAfterTest || databaseIdentifier.getMode() == OMode.MEMORY)
consoleProgressWriter.printMessage(String.format("\nDatabase is available on [%s].", databaseIdentifier.getUrl()));
else {
ODatabaseUtils.dropDatabase(databaseIdentifier);
consoleProgressWriter.printMessage(String.format("\nDropped database [%s].", databaseIdentifier.getUrl()));
}
}
return returnCode;
}
Aggregations