diff options
author | Alex Rudyy <orudyy@apache.org> | 2014-03-11 14:08:44 +0000 |
---|---|---|
committer | Alex Rudyy <orudyy@apache.org> | 2014-03-11 14:08:44 +0000 |
commit | cb7ce18283b628ece9fdf67bbce96c0257227b59 (patch) | |
tree | ff58707eb6369d5aa70331bbc40481dec35e7779 | |
parent | 949e9f7f6e07fff5fadde2bbf20cde5fcc20be0a (diff) | |
download | qpid-python-cb7ce18283b628ece9fdf67bbce96c0257227b59.tar.gz |
QPID-5612: JMS benchmarking tool fixes
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1576355 13f79535-47bb-0310-9956-ffa450edef68
5 files changed, 99 insertions, 49 deletions
diff --git a/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/ArgumentParser.java b/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/ArgumentParser.java index e962bfe799..e7421fb9b3 100644 --- a/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/ArgumentParser.java +++ b/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/ArgumentParser.java @@ -29,6 +29,12 @@ public class ArgumentParser for(String arg: args) { String[] splitArg = arg.split("="); + if (splitArg.length == 1 && splitArg[0].equals("-h")) + { + initialValues.put("-h", null); + continue; + } + if(splitArg.length != 2) { throw new IllegalArgumentException("arguments must have format <name>=<value>: " + arg); diff --git a/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/Benchmark.java b/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/Benchmark.java index 4ebbaf7da3..01aefb0977 100644 --- a/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/Benchmark.java +++ b/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/Benchmark.java @@ -20,7 +20,9 @@ */ package org.apache.qpid.disttest; +import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -37,6 +39,7 @@ import org.apache.qpid.disttest.controller.Controller; import org.apache.qpid.disttest.controller.ResultsForAllTests; import org.apache.qpid.disttest.controller.config.Config; import org.apache.qpid.disttest.controller.config.ConfigReader; +import org.apache.qpid.disttest.controller.config.TestConfig; import org.apache.qpid.disttest.jms.ControllerJmsDelegate; import org.apache.qpid.disttest.results.BenchmarkResultWriter; import org.apache.qpid.disttest.results.ResultsWriter; @@ -63,7 +66,7 @@ public class Benchmark private static final String REPORT_MESSAGE_TOTALS = "report-message-totals"; private static final String JNDI_CONFIG_PROP = "jndi-config"; - private static final String JNDI_CONFIG_DEFAULT = "perftests-jndi.properties"; + private static final String JNDI_CONFIG_DEFAULT = "jndi.properties"; private static final String TEST_CONFIG_PROP = "test-config"; @SuppressWarnings("serial") @@ -74,8 +77,6 @@ public class Benchmark put(REPORT_MESSAGE_TOTALS, "false"); }}; - private final ConfigFileHelper _configFileHelper = new ConfigFileHelper(); - private final Aggregator _aggregator = new Aggregator(); public static void main(String[] args) throws Exception @@ -89,16 +90,43 @@ public class Benchmark { ArgumentParser argumentParser = new ArgumentParser(); argumentParser.parseArgumentsIntoConfig(getCliOptions(), args); + if (_cliOptions.containsKey("-h")) + { + printHelp(null); + } } + private void printHelp(String message) + { + if (message != null) + { + System.out.println(message); + System.out.println(); + } + System.out.println("Usage:"); + System.out.println("java -cp \"<classpath>\" -Dqpid.disttest.duration=<test duration in milliseconds> -Dqpid.disttest.messageSize=<message size in bytes> org.apache.qpid.disttest.Benchmark [-h] [report-message-totals=<false|true>] [jndi-config=<path/to/jndi.properties>] [test-config=<path/to/test/configuration>]"); + System.out.println(" -h prints this help"); + System.out.println(" report-message-totals optional flag to report total payload. Default is false"); + System.out.println(" jndi-config path to jndi properties. Default is jndi.properties"); + System.out.println(" test-config path to test configuration. If not set, defaults to a built in bench mark test script. Alternative testscript(s) can be run by setting this option to a directory or file. If the former, all testscripts within the directory are executed."); + System.out.println(); + System.out.println("Supported JVM settings:"); + System.out.println(" qpid.disttest.duration overridden test duration in milliseconds"); + System.out.println(" qpid.disttest.messageSize overridden message size in bytes"); + System.exit(0); + } private Context getContext() { String jndiConfig = getJndiConfig(); + if (jndiConfig == null) + { + printHelp("JNDI configuration is not provided"); + } + try { - final Properties properties = new Properties(); - properties.load(new FileInputStream(jndiConfig)); + final Properties properties = loadProperties(jndiConfig); return new InitialContext(properties); } catch (Exception e) @@ -107,6 +135,32 @@ public class Benchmark } } + private Properties loadProperties(String jndiConfig) throws IOException, FileNotFoundException + { + final Properties properties = new Properties(); + InputStream inStream = getClass().getResourceAsStream(jndiConfig); + if (inStream == null) + { + if (!new File(jndiConfig).exists()) + { + printHelp("Cannot find " + jndiConfig); + } + inStream = new FileInputStream(jndiConfig); + } + + try + { + properties.load(inStream); + } + finally + { + if (inStream != null) + { + inStream.close(); + } + } + return properties; + } private void doBenchMark() throws Exception { @@ -115,7 +169,7 @@ public class Benchmark try { - runTests(jmsDelegate); + runTests(jmsDelegate, context); } finally { @@ -137,29 +191,22 @@ public class Benchmark { return _cliOptions; } - private void runTests(ControllerJmsDelegate jmsDelegate) + private void runTests(ControllerJmsDelegate jmsDelegate, Context context) { Controller controller = new Controller(jmsDelegate, DistributedTestConstants.REGISTRATION_TIMEOUT, DistributedTestConstants.COMMAND_RESPONSE_TIMEOUT); String testConfigPath = getCliOptions().get(TEST_CONFIG_PROP); - List<String> testConfigFiles = _configFileHelper.getTestConfigFiles(testConfigPath); - createClients(testConfigFiles); - + Config testConfig = buildTestConfigFrom(testConfigPath); + createClients(testConfig, context); + controller.setConfig(testConfig); try { List<ResultsForAllTests> results = new ArrayList<ResultsForAllTests>(); - for (String testConfigFile : testConfigFiles) - { - final Config testConfig = buildTestConfigFrom(testConfigFile); - controller.setConfig(testConfig); - - controller.awaitClientRegistrations(); + controller.awaitClientRegistrations(); - LOGGER.info("Running test : " + testConfigFile); - ResultsForAllTests testResult = runTest(controller, testConfigFile); - results.add(testResult); - } + ResultsForAllTests testResult = runTest(controller, testConfig, testConfigPath); + results.add(testResult); } catch(Exception e) { @@ -171,13 +218,9 @@ public class Benchmark } } - private ResultsForAllTests runTest(Controller controller, String testConfigFile) + private ResultsForAllTests runTest(Controller controller, Config testConfig, String testConfigFile) { ResultsWriter _resultsWriter = new BenchmarkResultWriter(getReportMessageTotals()); - - final Config testConfig = buildTestConfigFrom(testConfigFile); - controller.setConfig(testConfig); - ResultsForAllTests rawResultsForAllTests = controller.runAllTests(); ResultsForAllTests resultsForAllTests = _aggregator.aggregateResults(rawResultsForAllTests); @@ -186,22 +229,15 @@ public class Benchmark return resultsForAllTests; } - private void createClients(final List<String> testConfigFiles) + private void createClients(Config testConfig, Context context) { - int maxNumberOfClients = 0; - for (String testConfigFile : testConfigFiles) - { - final Config testConfig = buildTestConfigFrom(testConfigFile); - final int numClients = testConfig.getTotalNumberOfClients(); - maxNumberOfClients = Math.max(numClients, maxNumberOfClients); - } + int maxNumberOfClients = testConfig.getTotalNumberOfClients(); //we must create the required test clients, running in single-jvm mode for (int i = 1; i <= maxNumberOfClients; i++) { ClientRunner clientRunner = new ClientRunner(); - clientRunner.setJndiPropertiesFileLocation(getJndiConfig()); - clientRunner.runClients(); + clientRunner.runClients(context); } } @@ -219,7 +255,15 @@ public class Benchmark } else { - testConfig = configReader.getConfigFromFile(testConfigFile); + ConfigFileHelper configFileHelper = new ConfigFileHelper(); + List<String> files = configFileHelper.getTestConfigFiles(testConfigFile); + List<TestConfig> tests = new ArrayList<TestConfig>(); + for (String file : files) + { + Config config = configReader.getConfigFromFile(file); + tests.addAll(config.getTestConfigs()); + } + testConfig = new Config(tests); } } catch (IOException e) diff --git a/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/ClientRunner.java b/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/ClientRunner.java index 9c2f4a3d95..7450610597 100644 --- a/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/ClientRunner.java +++ b/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/ClientRunner.java @@ -57,9 +57,13 @@ public class ClientRunner extends AbstractRunner */ public void runClients() { - int numClients = Integer.parseInt(getCliOptions().get(NUM_OF_CLIENTS_PROP)); - Context context = getContext(); + runClients(context); + } + + public void runClients(Context context) + { + int numClients = Integer.parseInt(getCliOptions().get(NUM_OF_CLIENTS_PROP)); for(int i = 1; i <= numClients; i++) { diff --git a/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/Config.java b/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/Config.java index fe56137276..1698008418 100644 --- a/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/Config.java +++ b/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/Config.java @@ -33,6 +33,11 @@ public class Config _tests = Collections.emptyList(); } + public Config(List<TestConfig> tests) + { + _tests = tests; + } + public Config(TestConfig... tests) { _tests = Arrays.asList(tests); @@ -63,7 +68,7 @@ public class Config return Collections.unmodifiableList(testInstances); } - List<TestConfig> getTestConfigs() + public List<TestConfig> getTestConfigs() { return Collections.unmodifiableList(_tests); } diff --git a/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/ProducerConfig.java b/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/ProducerConfig.java index a5f6fb84cf..b35321fe5d 100644 --- a/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/ProducerConfig.java +++ b/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/ProducerConfig.java @@ -40,9 +40,6 @@ public class ProducerConfig extends ParticipantConfig private long _startDelay; private String _messageProviderName; - /** used to ensure we only log about the overridden message size once */ - private boolean _alreadyLoggedAboutOverriddenMessageSize; - // For Gson public ProducerConfig() { @@ -109,13 +106,7 @@ public class ProducerConfig extends ParticipantConfig try { int overriddenMessageSize = Integer.valueOf(overriddenMessageSizeString); - - if(!_alreadyLoggedAboutOverriddenMessageSize) - { - LOGGER.info("Applied overridden maximum duration " + overriddenMessageSize); - _alreadyLoggedAboutOverriddenMessageSize = true; - } - + LOGGER.info("Applied overridden message size " + overriddenMessageSize); return overriddenMessageSize; } catch (NumberFormatException e) |