Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added transaction support + chart report generation from command line. #20

Merged
merged 22 commits into from Nov 8, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion framework/src/main/java/org/radargun/CacheWrapper.java
Expand Up @@ -70,8 +70,18 @@ public interface CacheWrapper
*/
Object getReplicatedData(String bucket, String key) throws Exception;

Object startTransaction();
/**
* Starts a transaction against the cache node. All the put, get, empty invocations after this method returns will
* take place in the scope of the transaction started. The transaction will be completed by invoking {@link #endTransaction(boolean)}.
* @throws RuntimeException if a particular cache implementation does not support transactions it should throw a
* RuntimeException to signal that.
*/
void startTransaction();

/**
* Called in conjunction with {@link #startTransaction()} in order to complete a transaction by either committing or rolling it back.
* @param successful commit or rollback?
*/
void endTransaction(boolean successful);

public int size();
Expand Down
14 changes: 11 additions & 3 deletions framework/src/main/java/org/radargun/LaunchMaster.java
@@ -1,6 +1,8 @@
package org.radargun;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.radargun.config.ConfigParser;
import org.radargun.config.MasterConfig;

Expand All @@ -11,14 +13,17 @@
*/
public class LaunchMaster {

private static Log log = LogFactory.getLog(LaunchMaster.class);

public static void main(String[] args) throws Exception {

File currentDir = new File(".");
System.out.println("Running in directory: " + currentDir.getAbsolutePath());
String message = "Running in directory: " + currentDir.getAbsolutePath();
out(message);

String config = getConfigOrExit(args);

System.out.println("Configuration file is: " + config);
out("Configuration file is: " + config);

ConfigParser configParser = ConfigParser.getConfigParser();
MasterConfig masterConfig = configParser.parseConfig(config);
Expand Down Expand Up @@ -52,7 +57,10 @@ private static void launchOld(String config) throws Exception {
System.err.println("No such file: " + configFile.getAbsolutePath());
printUsageAndExit();
}
}


private static void out(String message) {
System.out.println(message);
log.info(message);
}
}
19 changes: 12 additions & 7 deletions framework/src/main/java/org/radargun/config/DomConfigParser.java
Expand Up @@ -91,13 +91,7 @@ private void parseProductsElement(Element configRoot, ScalingBenchmarkConfig pro
for (int configIndex = 0; configIndex < configs.getLength(); configIndex++) {
Element configEl = (Element) configs.item(configIndex);
String configName = configEl.getAttribute("name");
Properties configAttributes = new Properties();
NamedNodeMap attributes = configEl.getAttributes();
for (int j = 0; j < attributes.getLength(); j++) {
String name = attributes.item(j).getNodeName();
String value = attributes.item(j).getNodeValue();
configAttributes.put(name, value);
}
Properties configAttributes = getAttributes(configEl);

ScalingBenchmarkConfig clone = prototype.clone();
clone.setProductName(productName);
Expand All @@ -111,6 +105,17 @@ private void parseProductsElement(Element configRoot, ScalingBenchmarkConfig pro
}
}

public static Properties getAttributes(Element configEl) {
NamedNodeMap attributes = configEl.getAttributes();
Properties configAttributes = new Properties();
for (int j = 0; j < attributes.getLength(); j++) {
String name = attributes.item(j).getNodeName();
String value = attributes.item(j).getNodeValue();
configAttributes.put(name, value);
}
return configAttributes;
}

private MasterConfig parseMaster(Element configRoot, ScalingBenchmarkConfig prototype) {
MasterConfig masterConfig;
Element masterEl = (Element) configRoot.getElementsByTagName("master").item(0);
Expand Down
13 changes: 8 additions & 5 deletions framework/src/main/java/org/radargun/local/LocalBenchmark.java
Expand Up @@ -5,6 +5,7 @@
import org.radargun.CacheWrapper;
import org.radargun.CacheWrapperStressor;
import org.radargun.ShutDownHook;
import org.radargun.utils.TypedProperties;
import org.radargun.utils.Utils;

import java.io.File;
Expand All @@ -16,6 +17,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
* @author Mircea.Markus@jboss.com
Expand All @@ -28,7 +30,7 @@ public class LocalBenchmark {
private static final String REPORTS_DIR = "reports";

private List<CacheWrapperStressor> stressors = new ArrayList<CacheWrapperStressor>();
private LinkedHashMap<String, List<String>> product2Config = new LinkedHashMap<String, List<String>>();
private LinkedHashMap<String, List<Properties>> product2Config = new LinkedHashMap<String, List<Properties>>();
private boolean headerGenerted = false;
private List<ReportDesc> reportDescs = new ArrayList<ReportDesc>();

Expand All @@ -43,12 +45,13 @@ public LocalBenchmark() {

public void benchmark() throws Exception {
log.info("Starting benchmark with " + Utils.kb(initialFreeMemory) + " kb initial free memory.");
for (Map.Entry<String, List<String>> product : product2Config.entrySet()) {
for (String config : product.getValue()) {
for (Map.Entry<String, List<Properties>> product : product2Config.entrySet()) {
for (Properties configProps : product.getValue()) {
final String config = configProps.getProperty("name");
log.info("Processing " + product.getKey() + "-" + config);
CacheWrapper wrapper = getCacheWrapper(product.getKey());
try {
wrapper.setUp(config, true, -1, null);
wrapper.setUp(config, true, -1, new TypedProperties(configProps));

Map<String, String> results = null;
for (CacheWrapperStressor stressor : stressors) {
Expand Down Expand Up @@ -165,7 +168,7 @@ public void addStressor(CacheWrapperStressor stressor) {
stressors.add(stressor);
}

public void addProductConfig(String productName, List<String> configs) {
public void addProductConfig(String productName, List<Properties> configs) {
product2Config.put(productName, configs);
}

Expand Down
Expand Up @@ -4,6 +4,7 @@
import org.apache.commons.logging.LogFactory;
import org.radargun.CacheWrapperStressor;
import org.radargun.config.ConfigHelper;
import org.radargun.config.DomConfigParser;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Expand All @@ -16,6 +17,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
* @author Mircea.Markus@jboss.com
Expand Down Expand Up @@ -71,12 +73,11 @@ private void parseProductsElement(Element configRoot, LocalBenchmark localBenchm
Element nodeEl = (Element) node;
String productName = nodeEl.getNodeName();
NodeList configs = nodeEl.getElementsByTagName("config");
List<String> configNames = new ArrayList<String>();
List<Properties> configNames = new ArrayList<Properties>();

for (int configIndex = 0; configIndex < configs.getLength(); configIndex++) {
Element configEl = (Element) configs.item(configIndex);
String configName = configEl.getAttribute("name");
configNames.add(configName);
configNames.add(DomConfigParser.getAttributes(configEl));
}
localBenchmark.addProductConfig(productName, configNames);
}
Expand Down
@@ -0,0 +1,116 @@
package org.radargun.reporting;

import sun.awt.image.OffScreenImage;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import java.util.SortedMap;
import java.util.StringTokenizer;
import java.util.TreeMap;

/**
* @author Mircea Markus
*/
public class LineReportGenerator {

private static final String REPORT_PNG = "report";

public static void main(String[] args) throws Exception {

if (args.length == 0) {
printHelpAndExit();
}

Properties props = new Properties();
FileReader reader = new FileReader(args[0]);
try {
props.load(reader);
} catch (IOException e) {
System.err.println("Could not load the report descriptor:" + e.getMessage());
printHelpAndExit();
} finally {
reader.close();
}

String dir = props.getProperty("csv-dir");
String reportFile = props.getProperty("chart", REPORT_PNG);
String title = props.getProperty("title");
String xLabels = props.getProperty("x-label");
String yLabels = props.getProperty("y-label");
String subtitle = props.getProperty("subtitle");
String items = props.getProperty("items");

if (dir == null || title == null || yLabels == null || subtitle == null || items == null) {
printHelpAndExit();
}


LineClusterReport lcr = new LineClusterReport();

lcr.setReportFile(".", reportFile);

lcr.init(xLabels, yLabels, title, subtitle);

StringTokenizer st = new StringTokenizer(items, ":" );
while (st.hasMoreElements()) {
String item = st.nextToken().trim();
int firstRoundBracket = item.indexOf("(");
String fileNamePrefix = item.substring(0, firstRoundBracket);
int indexOfComma = item.indexOf(",");
Integer columnIndex = Integer.parseInt(item.substring(firstRoundBracket + 1, indexOfComma).trim());
String itemNameInReport = item.substring(indexOfComma+1, item.indexOf(")"));
SortedMap<Integer, Double> values = getValues(dir, columnIndex, fileNamePrefix);
for (Map.Entry<Integer, Double> me : values.entrySet()) {
lcr.addCategory(itemNameInReport, me.getKey(), me.getValue());
}
}

lcr.generate();
}

private static SortedMap<Integer, Double> getValues(final String dir, final Integer columnIndex, final String fileNamePrefix) throws Exception {
File f = new File(dir);
String[] files = f.list(new FilenameFilter() {
@Override
public boolean accept(File file, String s) {
return s.indexOf(fileNamePrefix) == 0;
}
});
SortedMap<Integer, Double> result = new TreeMap<Integer, Double>();
if (files == null) throw new RuntimeException("Could not find any files with prefix:" + fileNamePrefix + " in directory " + f.getAbsolutePath());
for (String file : files) {
FileReader reader = new FileReader(new File(dir, file));
BufferedReader br = new BufferedReader(reader);
br.readLine();//skip header
Double sum = 0d;
int count = 0;
String line;
while ((line = br.readLine()) != null) {
StringTokenizer st = new StringTokenizer(line, ",");
for (int i = 0; i <= columnIndex; i++) {
if (!st.hasMoreElements()) throw new RuntimeException("No column with index " + columnIndex + " in file '" + fileNamePrefix + "'");
String value = st.nextToken();
if (i == columnIndex) {
sum += (Double.valueOf(value));
count++;
break;
}
}
}
int numNodes = Integer.parseInt(file.substring(fileNamePrefix.length(), file.indexOf(".")));
result.put(numNodes, sum/count);
}
return result;
}

private static void printHelpAndExit() {
System.out.println("Usage: ./chart.sh <chart-descriptor>");
System.out.println("For an example of a chart descriptor look at <RADARGUN_HOME>/chart_descriptor.properties ");
System.exit(1);
}
}
Expand Up @@ -54,11 +54,17 @@ public class WebSessionBenchmarkStage extends AbstractDistStage {

private boolean reportNanos = false;

private String keyGeneratorClass = StringKeyGenerator.class.getName();;
private String keyGeneratorClass = StringKeyGenerator.class.getName();


private CacheWrapper cacheWrapper;

private boolean useTransactions = false;

private boolean commitTransactions = true;

private int transactionSize = 1;

public DistStageAck executeOnSlave() {
DefaultDistStageAck result = new DefaultDistStageAck(slaveIndex, slaveState.getLocalAddress());
this.cacheWrapper = slaveState.getCacheWrapper();
Expand All @@ -78,6 +84,9 @@ public DistStageAck executeOnSlave() {
putGetStressor.setSizeOfAnAttribute(sizeOfAnAttribute);
putGetStressor.setWritePercentage(writePercentage);
putGetStressor.setKeyGeneratorClass(keyGeneratorClass);
putGetStressor.setUseTransactions(useTransactions);
putGetStressor.setCommitTransactions(commitTransactions);
putGetStressor.setTransactionSize(transactionSize);

try {
Map<String, String> results = putGetStressor.stress(cacheWrapper);
Expand Down Expand Up @@ -160,6 +169,30 @@ public void setKeyGeneratorClass(String keyGeneratorClass) {
this.keyGeneratorClass = keyGeneratorClass;
}

public int getTransactionSize() {
return transactionSize;
}

public void setTransactionSize(int transactionSize) {
this.transactionSize = transactionSize;
}

public boolean isUseTransactions() {
return useTransactions;
}

public void setUseTransactions(boolean useTransactions) {
this.useTransactions = useTransactions;
}

public boolean isCommitTransactions() {
return commitTransactions;
}

public void setCommitTransactions(boolean commitTransactions) {
this.commitTransactions = commitTransactions;
}

@Override
public String toString() {
return "WebSessionBenchmarkStage {" +
Expand All @@ -171,6 +204,9 @@ public String toString() {
", numOfThreads=" + numOfThreads +
", reportNanos=" + reportNanos +
", cacheWrapper=" + cacheWrapper +
", useTransactions=" + useTransactions +
", commitTransactions=" + commitTransactions +
", transactionSize=" + transactionSize +
", " + super.toString();
}
}