phoenix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From codymarcel <...@git.apache.org>
Subject [GitHub] phoenix pull request: PHOENIX-2182
Date Tue, 01 Sep 2015 21:25:02 GMT
Github user codymarcel commented on a diff in the pull request:

    https://github.com/apache/phoenix/pull/115#discussion_r38474158
  
    --- Diff: phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/ResultsComparator.java
---
    @@ -0,0 +1,353 @@
    +package org.apache.phoenix.pherf.util;
    +
    +import java.io.FileNotFoundException;
    +import java.io.FileReader;
    +import java.io.PrintWriter;
    +import java.io.UnsupportedEncodingException;
    +import java.text.DecimalFormat;
    +import java.text.SimpleDateFormat;
    +import java.util.Date;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +import java.util.TreeMap;
    +
    +import org.apache.commons.csv.CSVFormat;
    +import org.apache.commons.csv.CSVParser;
    +import org.apache.commons.csv.CSVRecord;
    +import org.apache.phoenix.pherf.PherfConstants;
    +import org.apache.phoenix.pherf.result.file.ResultFileDetails;
    +
    +/**
    + * Compare results based on set threshold and render results as Google Charts
    + */
    +public class ResultsComparator {
    +
    +	private String[] labels;
    +	private final Map<String, DataNode> datanodes = new TreeMap<String, DataNode>();
    +	private final PherfConstants constants = PherfConstants.create();
    +	private final String resultDir = constants.getProperty("pherf.default.results.dir");
    +	private final double threshold = Double.parseDouble(constants.getProperty("pherf.default.comparison.threshold"));
    +
    +	public ResultsComparator(String labels) {
    +		this.setLabelsAsString(labels);
    +	}
    +	
    +	String[] getLabels() {
    +		return labels;
    +	}
    +
    +	void setLabels(String[] labels) {
    +		this.labels = labels;
    +	}
    +
    +	void setLabelsAsString(String labels) {
    +		this.labels = labels.split(",");
    +	}
    +	
    +	public void readAndRender() {
    +		try {
    +			for (String label : labels) {
    +				read(label);
    +			}
    +			renderAsGoogleChartsHTML();
    +
    +		} catch (Exception e) {
    +			e.printStackTrace();
    +		}
    +	}
    +
    +	/**
    +	 * Reads aggregate file and convert it to DataNode 
    +	 * @param label
    +	 * @throws Exception
    +	 */
    +    private void read(String label) throws Exception {
    +		String resultFileName = resultDir 
    +				+ PherfConstants.PATH_SEPARATOR
    +				+ PherfConstants.RESULT_PREFIX 
    +				+ label
    +				+ ResultFileDetails.CSV_AGGREGATE_PERFORMANCE.getExtension();
    +
    +    	FileReader in = new FileReader(resultFileName);
    +    	final CSVParser parser = new CSVParser(in, CSVFormat.DEFAULT.withHeader());
    +
    +        for (CSVRecord record : parser) {
    +            String group = record.get("QUERY_GROUP");
    +            String query = record.get("QUERY");
    +            String explain = record.get("EXPLAIN_PLAN");
    +            String tenantId = record.get("TENANT_ID");
    +            long avgTime = Long.parseLong(record.get("AVG_TIME_MS"));
    +            long minTime = Long.parseLong(record.get("AVG_MIN_TIME_MS"));
    +            long numRuns = Long.parseLong(record.get("RUN_COUNT"));
    +            long rowCount = Long.parseLong(record.get("RESULT_ROW_COUNT"));
    +            Node node = new Node(minTime, avgTime, numRuns, explain, query, tenantId,
label, rowCount);
    +            
    +            if (datanodes.containsKey(group)) {
    +            	datanodes.get(group).getDataSet().put(label, node);
    +            } else {
    +            	datanodes.put(group, new DataNode(label, node));
    +            }
    +        }
    +        parser.close();
    +    }
    +
    +    /**
    +     * Verifies if the first result is within the set 
    +     * threshold of pherf.default.comparison.threshold
    +     * set in pherf.properties files
    +     * @param threshold
    +     * @return
    +     */
    +    private boolean verifyWithinThreshold(double threshold) {
    +    	long resetTimeToCompare = -1;
    +    	long timeToCompare = resetTimeToCompare;
    +    	for (Map.Entry<String, DataNode> dn : datanodes.entrySet()) {    	   	
    +        	for (Map.Entry<String, Node> node : dn.getValue().getDataSet().entrySet())
{
    +        		if (timeToCompare == -1) {
    +        			timeToCompare = node.getValue().getMinTime();
    +        		}
    +				if ((((double) (timeToCompare - node.getValue().getMinTime())) / (double) node
    +						.getValue().getMinTime()) > threshold) {
    +					return false;
    +				}
    +        	}
    +        	timeToCompare = resetTimeToCompare;
    +    	}
    +    	return true;
    +    }
    +    
    +    /**
    +     * Render results as Google charts
    +     * @throws FileNotFoundException
    +     * @throws UnsupportedEncodingException
    +     */
    +    private void renderAsGoogleChartsHTML() throws FileNotFoundException, UnsupportedEncodingException
{
    --- End diff --
    
    Should all this chart stuff go in a util object? It seems unrelated to a Result comparison.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message