1 package org.jgroups.tests.perf; 2 3 import java.io.FileInputStream ; 4 import java.io.FileNotFoundException ; 5 import java.io.FileWriter ; 6 import java.io.IOException ; 7 import java.util.ArrayList ; 8 import java.util.Properties ; 9 10 11 23 public class PerformanceTestGenerator { 24 Properties configProperties = null; 25 private long totalDataBytes; 26 private int[] numOfSenders; 27 private int[] messageSizes; 28 private int numNodes; 29 private int interval; 30 31 32 public PerformanceTestGenerator(Properties config) { 33 configProperties = config; 34 } 35 36 39 public static void main(String [] args) { 40 Properties config = null; 41 for(int i=0; i < args.length; i++) { 42 if("-config".equals(args[i])) { 43 String config_file=args[++i]; 44 config = new Properties (); 45 try { 46 config.load(new FileInputStream (config_file)); 47 } catch (FileNotFoundException e) { 48 System.err.println("File " + config_file + " not found"); 49 return; 50 } catch (IOException e) { 51 System.err.println("Error reading configuration file " + config_file); 52 return; 53 } 54 continue; 55 } 56 System.out.println("PerformanceTestGenerator -config <file>"); 57 return; 58 } 59 60 try { 61 PerformanceTestGenerator t=new PerformanceTestGenerator(config); 62 t.parse(); 63 t.generateTestConfigFiles(); 64 65 } 66 catch(Exception e) { 67 e.printStackTrace(); 68 } 69 } 70 71 private void parse() throws Exception { 72 73 numNodes = Integer.parseInt(configProperties.getProperty("nodes")); 74 totalDataBytes = Long.parseLong(configProperties.getProperty("total_data")); 75 numOfSenders = tokenizeAndConvert(configProperties.getProperty("number_of_senders"),","); 76 messageSizes = tokenizeAndConvert(configProperties.getProperty("message_sizes"),","); 77 interval = Integer.parseInt(configProperties.getProperty("interval")); 78 } 79 private void generateFile(int numOfSenders, int messageSize,int nodeCount) { 80 FileWriter fw = null; 81 long numOfMessages = (totalDataBytes/messageSize); 82 try { 83 fw = new FileWriter ("config_"+numOfSenders + "_" +nodeCount +"_"+ messageSize + ".txt"); 84 fw.write("transport=org.jgroups.tests.perf.transports.JGroupsTransport\n"); 85 fw.write("msg_size="+messageSize+"\n"); 86 fw.write("num_msgs="+(numOfMessages/numOfSenders) +"\n"); 87 fw.write("num_senders="+numOfSenders+"\n"); 88 fw.write("num_members="+nodeCount+"\n"); 89 fw.write("log_interval="+interval+"\n"); 90 fw.close(); 91 } catch (IOException e) { 92 e.printStackTrace(); 93 } 94 95 } 96 public static String [] tokenize(String s, String delim) { 97 if (s == null || s.length() == 0) { 98 return new String [0]; 99 } 100 if (delim == null || delim.length() == 0) { 101 return new String [] { s }; 102 } 103 104 ArrayList tokens = new ArrayList (); 105 106 int pos = 0; 107 int delPos = 0; 108 while ((delPos = s.indexOf(delim, pos)) != -1) { 109 tokens.add(s.substring(pos, delPos)); 110 pos = delim.length() + delPos; 111 } 112 tokens.add(s.substring(pos)); 113 return (String []) tokens.toArray(new String [tokens.size()]); 114 } 115 116 public static int[] tokenizeAndConvert(String s, String delim) { 117 String stokens [] = tokenize(s,delim); 118 int result [] = new int[stokens.length]; 119 for (int i = 0; i < stokens.length; i++) { 120 result[i]=Integer.parseInt(stokens[i]); 121 } 122 return result; 123 } 124 125 private void generateTestConfigFiles() { 126 for (int i = 0; i < numOfSenders.length; i++) { 127 for (int j = 0; j < messageSizes.length; j++) { 128 generateFile(numOfSenders[i],messageSizes[j],numNodes); 129 } 130 } 131 } 132 133 } 134 | Popular Tags |