Search in sources :

Example 1 with BinnedTimeValues

use of alma.acs.algorithms.DataBinner.BinnedTimeValues in project ACS by ACS-Community.

the class OrbProfilerStatisticsTest method testFinishedRequestBinning.

@Test
public void testFinishedRequestBinning() throws Exception {
    OrbProfilerParser parser = new OrbProfilerParser(logger);
    List<ProfilerMessage> messages = parser.parse(new File("hibernateCdbJDal-2011-09-12T153856.txt"));
    OrbProfilerStatistics stat = new OrbProfilerStatistics(messages, logger);
    List<TimeValue<Integer>> callsGetDao = stat.getFinishedRequests("get_DAO");
    assertEquals(8415, callsGetDao.size());
    //		System.out.println("*** Last 10 get_DAO calls with response times in ms ***");
    //		for (int i = callsGetDao.size()-11; i < callsGetDao.size(); i++) {
    //			TimeValue call = callsGetDao.get(i);
    //			System.out.println(timeString(call.timeMillis) + "\t(=" + call.timeMillis + ")\t" + call.value);
    //		}
    final int binIntervalMillis = 1000;
    DataBinner binner = new DataBinner();
    List<BinnedTimeValues<Integer>> binnedData = binner.binTimedData(callsGetDao, binIntervalMillis);
    //		System.out.println("*** Binned get_DAO calls per " + binIntervalMillis + " ms ***");
    //		for (BinnedTimeValues binnedTimeValues : binnedData) {
    //			// todo Calculate max or average
    //			String msg = timeString(binnedTimeValues.timeMillis) + '\t' + binnedTimeValues.binnedData.size(); // + '\t' + binnedTimeValues.binnedData;
    //			System.out.println(msg);
    //		}
    // 4281 one-second bins
    assertEquals(4281, binnedData.size());
    // center time of first bin
    assertEquals("2011-09-12T15:40:47.500", timeString(binnedData.get(0).timeMillis));
    // first bin must have 3 calls
    assertEquals(3, binnedData.get(0).binnedData.size());
    // first call in first bin
    assertEquals("2011-09-12T15:40:47.605", timeString(binnedData.get(0).binnedData.get(0).timeMillis));
    // center time of second bin
    assertEquals("2011-09-12T15:40:48.500", timeString(binnedData.get(1).timeMillis));
    // second bin must have 4 calls
    assertEquals(4, binnedData.get(1).binnedData.size());
    // center time of third bin
    assertEquals("2011-09-12T15:40:49.500", timeString(binnedData.get(2).timeMillis));
    // third bin must be empty
    assertEquals(0, binnedData.get(2).binnedData.size());
}
Also used : BinnedTimeValues(alma.acs.algorithms.DataBinner.BinnedTimeValues) File(java.io.File) TimeValue(alma.acs.algorithms.DataBinner.TimeValue) DataBinner(alma.acs.algorithms.DataBinner) Test(org.junit.Test)

Example 2 with BinnedTimeValues

use of alma.acs.algorithms.DataBinner.BinnedTimeValues in project ACS by ACS-Community.

the class CdbCallStatistics method getCallFrequency.

/**
	 * @param operationName Can be null, to use calls to all operations.
	 */
public void getCallFrequency(String operationName) throws FileNotFoundException {
    OrbProfilerStatistics stat = new OrbProfilerStatistics(messages, logger);
    final int binIntervalMillis = 1000;
    List<TimeValue<Integer>> allCalls = stat.getFinishedRequests(operationName);
    Collections.sort(allCalls);
    DataBinner binner = new DataBinner();
    List<BinnedTimeValues<Integer>> binnedAllCalls = binner.binTimedData(allCalls, binIntervalMillis);
    String outFileName = getFileNameBase() + "_callFrequency" + (operationName != null ? operationName : "") + ".txt";
    File outFile = new File(outFileName);
    PrintStream pr = new PrintStream(outFile);
    pr.println("time" + delim + "#calls/s" + delim + "duration max" + delim + "duration average");
    for (BinnedTimeValues<Integer> binnedTimeValues : binnedAllCalls) {
        List<TimeValue<Integer>> timeValuesPerBin = binnedTimeValues.binnedData;
        DescriptiveStatistics callTimeStats = new DescriptiveStatistics();
        for (TimeValue<Integer> timeValue : timeValuesPerBin) {
            callTimeStats.addValue(timeValue.value);
        }
        // or timeValuesPerBin.size();
        long numCallsPerBin = callTimeStats.getN();
        pr.println(timeString(binnedTimeValues.timeMillis) + delim + numCallsPerBin + delim + (numCallsPerBin > 0 ? df2.format(callTimeStats.getMax()) : 0) + delim + (numCallsPerBin > 0 ? df2.format(callTimeStats.getMean()) : 0));
    }
    pr.close();
    logger.info("Wrote " + outFile.getAbsolutePath());
}
Also used : PrintStream(java.io.PrintStream) DescriptiveStatistics(org.apache.commons.math.stat.descriptive.DescriptiveStatistics) DataBinner(alma.acs.algorithms.DataBinner) BinnedTimeValues(alma.acs.algorithms.DataBinner.BinnedTimeValues) File(java.io.File) TimeValue(alma.acs.algorithms.DataBinner.TimeValue)

Example 3 with BinnedTimeValues

use of alma.acs.algorithms.DataBinner.BinnedTimeValues in project ACS by ACS-Community.

the class ManagerStdoutParserTest method testParseManagerOutput.

@Test
public void testParseManagerOutput() throws Exception, ParseException {
    String fileName = "sampleOutput/acsManager_2012-03-20_16.48.20.642";
    ManagerStdoutParser parser = new ManagerStdoutParser(logger);
    List<ComponentRequest> requests = parser.parse(new File(fileName));
    // to select only logs between these two timestamps
    long t0 = IsoDateFormat.parseIsoTimestamp("2011-11-13T20:47:17.328").getTime();
    long t1 = IsoDateFormat.parseIsoTimestamp("2011-11-13T21:29:48.314").getTime();
    List<TimeValue<ComponentRequest>> data = new ArrayList<TimeValue<ComponentRequest>>();
    for (ComponentRequest r : requests) {
        //			if (r.timeRequested >= t0 && r.timeRequested <= t1) {
        data.add(new TimeValue<ComponentRequest>(r.timeRequested, r));
        System.out.println(toISO(r.timeRequested) + ", " + (r.timeProvided - r.timeRequested) + ", " + r.key.curl.substring(8) + ", " + r.key.clientName);
    //			}
    }
    Collections.sort(data);
    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(2);
    int binIntervalSec = 5;
    DataBinner binner = new DataBinner();
    List<BinnedTimeValues<ComponentRequest>> binned = binner.binTimedData(data, binIntervalSec * 1000);
    //		System.out.println("Time interval\t#Requests by 'Python Client'/" + binIntervalSec + 
    //				"s\t#Requests by other clients/" + binIntervalSec + "s" + "\t" + "Average response time/ms");
    System.out.println("Time interval\t#Requests/" + binIntervalSec + "s interval\tAverage response time/ms");
    for (BinnedTimeValues<ComponentRequest> binnedTimeValues : binned) {
        long timeCurrentBin = binnedTimeValues.timeMillis;
        List<TimeValue<ComponentRequest>> valuesCurrentBin = binnedTimeValues.binnedData;
        int numCallsPythonClient = 0;
        int numCallsOtherClients = 0;
        DescriptiveStatistics callTimeStats = new DescriptiveStatistics();
        for (TimeValue<ComponentRequest> timeValue : valuesCurrentBin) {
            ComponentRequest r = timeValue.value;
            if (r.key.clientName.equals("Python Client")) {
                numCallsPythonClient++;
            } else {
                numCallsOtherClients++;
            }
            // duration in ms
            callTimeStats.addValue(r.timeProvided - r.timeRequested);
        }
        System.out.println(toISO(timeCurrentBin) + "\t" + (numCallsPythonClient + numCallsOtherClients) + "\t" + df.format(callTimeStats.getMean()));
    }
}
Also used : DescriptiveStatistics(org.apache.commons.math.stat.descriptive.DescriptiveStatistics) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) DataBinner(alma.acs.algorithms.DataBinner) ComponentRequest(alma.acs.manager.logparser.ManagerStdoutParser.ComponentRequest) BinnedTimeValues(alma.acs.algorithms.DataBinner.BinnedTimeValues) File(java.io.File) TimeValue(alma.acs.algorithms.DataBinner.TimeValue) Test(org.junit.Test)

Aggregations

DataBinner (alma.acs.algorithms.DataBinner)3 BinnedTimeValues (alma.acs.algorithms.DataBinner.BinnedTimeValues)3 TimeValue (alma.acs.algorithms.DataBinner.TimeValue)3 File (java.io.File)3 DescriptiveStatistics (org.apache.commons.math.stat.descriptive.DescriptiveStatistics)2 Test (org.junit.Test)2 ComponentRequest (alma.acs.manager.logparser.ManagerStdoutParser.ComponentRequest)1 PrintStream (java.io.PrintStream)1 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1