001: package org.jgroups.tests.perf;
002:
003: import java.io.FileInputStream;
004: import java.io.FileNotFoundException;
005: import java.io.FileWriter;
006: import java.io.IOException;
007: import java.util.ArrayList;
008: import java.util.Properties;
009:
010: /**
011: * Utility tool that creates configuration files for automated performance tests.
012: * PerformanceTestGenerator, given an input file with -config flag, generates
013: * test files that are used in conjunction with bin/clusterperfromancetest.sh.
014: * The number of test files generated is numOfSenders*messageSizes.
015: *
016: * Default configuration file used for this utility is conf/performancetestconfig.txt
017: * See bin/clusterperformancetest.sh
018: *
019: * @author Vladimir Blagojevic
020: * @version $Id$
021: */
022: public class PerformanceTestGenerator {
023: Properties configProperties = null;
024: private long totalDataBytes;
025: private int[] numOfSenders;
026: private int[] messageSizes;
027: private int numNodes;
028: private int interval;
029:
030: public PerformanceTestGenerator(Properties config) {
031: configProperties = config;
032: }
033:
034: /**
035: * @param args
036: */
037: public static void main(String[] args) {
038: Properties config = null;
039: for (int i = 0; i < args.length; i++) {
040: if ("-config".equals(args[i])) {
041: String config_file = args[++i];
042: config = new Properties();
043: try {
044: config.load(new FileInputStream(config_file));
045: } catch (FileNotFoundException e) {
046: System.err.println("File " + config_file
047: + " not found");
048: return;
049: } catch (IOException e) {
050: System.err
051: .println("Error reading configuration file "
052: + config_file);
053: return;
054: }
055: continue;
056: }
057: System.out
058: .println("PerformanceTestGenerator -config <file>");
059: return;
060: }
061:
062: try {
063: PerformanceTestGenerator t = new PerformanceTestGenerator(
064: config);
065: t.parse();
066: t.generateTestConfigFiles();
067:
068: } catch (Exception e) {
069: e.printStackTrace();
070: }
071: }
072:
073: private void parse() throws Exception {
074:
075: numNodes = Integer.parseInt(configProperties
076: .getProperty("nodes"));
077: totalDataBytes = Long.parseLong(configProperties
078: .getProperty("total_data"));
079: numOfSenders = tokenizeAndConvert(configProperties
080: .getProperty("number_of_senders"), ",");
081: messageSizes = tokenizeAndConvert(configProperties
082: .getProperty("message_sizes"), ",");
083: interval = Integer.parseInt(configProperties
084: .getProperty("interval"));
085: }
086:
087: private void generateFile(int numOfSenders, int messageSize,
088: int nodeCount) {
089: FileWriter fw = null;
090: long numOfMessages = (totalDataBytes / messageSize);
091: try {
092: fw = new FileWriter("config_" + numOfSenders + "_"
093: + nodeCount + "_" + messageSize + ".txt");
094: fw
095: .write("transport=org.jgroups.tests.perf.transports.JGroupsTransport\n");
096: fw.write("msg_size=" + messageSize + "\n");
097: fw.write("num_msgs=" + (numOfMessages / numOfSenders)
098: + "\n");
099: fw.write("num_senders=" + numOfSenders + "\n");
100: fw.write("num_members=" + nodeCount + "\n");
101: fw.write("log_interval=" + interval + "\n");
102: fw.close();
103: } catch (IOException e) {
104: e.printStackTrace();
105: }
106:
107: }
108:
109: public static String[] tokenize(String s, String delim) {
110: if (s == null || s.length() == 0) {
111: return new String[0];
112: }
113: if (delim == null || delim.length() == 0) {
114: return new String[] { s };
115: }
116:
117: ArrayList tokens = new ArrayList();
118:
119: int pos = 0;
120: int delPos = 0;
121: while ((delPos = s.indexOf(delim, pos)) != -1) {
122: tokens.add(s.substring(pos, delPos));
123: pos = delim.length() + delPos;
124: }
125: tokens.add(s.substring(pos));
126: return (String[]) tokens.toArray(new String[tokens.size()]);
127: }
128:
129: public static int[] tokenizeAndConvert(String s, String delim) {
130: String stokens[] = tokenize(s, delim);
131: int result[] = new int[stokens.length];
132: for (int i = 0; i < stokens.length; i++) {
133: result[i] = Integer.parseInt(stokens[i]);
134: }
135: return result;
136: }
137:
138: private void generateTestConfigFiles() {
139: for (int i = 0; i < numOfSenders.length; i++) {
140: for (int j = 0; j < messageSizes.length; j++) {
141: generateFile(numOfSenders[i], messageSizes[j], numNodes);
142: }
143: }
144: }
145:
146: }
|