Search in sources :

Example 1 with Histogram

use of org.HdrHistogram_voltpatches.Histogram in project voltdb by VoltDB.

the class LatencyLogger method main.

public static void main(String[] args) throws Exception {
    final String hostname;
    if (args.length == 1) {
        readHistogramFromFile(args[0]);
        return;
    }
    if (args.length != 3) {
        if (args.length == 4) {
            hostname = args[3];
        } else {
            System.out.println(usage());
            return;
        }
    } else {
        hostname = args[0];
    }
    final String server = args[0];
    int dur = 0;
    try {
        dur = Integer.valueOf(args[2]);
        if (dur < 1) {
            throw new NumberFormatException();
        }
    } catch (NumberFormatException e) {
        System.out.println("reportIntervalSeconds should be greater than or equal to 1");
        System.out.println(usage());
        System.exit(0);
    }
    final int duration = dur;
    // start with an empty password
    String username = "";
    String password = "";
    // if credentials set in env, use them
    if (System.getenv().containsKey("VOLTDBUSER")) {
        username = System.getenv("VOLTDBUSER");
    }
    if (System.getenv().containsKey("VOLTDBPASSWORD")) {
        password = System.getenv("VOLTDBPASSWORD");
    }
    // create the client with our credentials
    ClientConfig clientConfig = new ClientConfig(username, password);
    final Client c = ClientFactory.createClient(clientConfig);
    int port = 0;
    try {
        port = Integer.valueOf(args[1]);
    } catch (NumberFormatException e) {
        System.out.println("Failed to parse port number.");
        System.out.println("Usage server port reportIntervalSeconds");
        System.exit(0);
    }
    System.out.println("Connecting to " + server + " port " + port);
    c.createConnection(args[0], port);
    System.out.printf("%12s, %10s, %10s, %10s, %10s, %10s, %10s, %10s\n", "TIMESTAMP", "COUNT", "TPS", "95", "99", "99.9", "99.99", "99.999");
    final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
    ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor();
    ses.scheduleAtFixedRate(new Runnable() {

        @Override
        public void run() {
            VoltTable table = null;
            try {
                table = c.callProcedure("@Statistics", "LATENCY_HISTOGRAM", 0).getResults()[0];
            } catch (IOException | ProcCallException e) {
                System.out.println("Failed to get statistics:");
                e.printStackTrace();
                System.exit(0);
            }
            List<String> hostnames = new ArrayList<String>();
            String tableHostname = "";
            while (!hostname.equalsIgnoreCase(tableHostname)) {
                if (!table.advanceRow()) {
                    System.out.println("Server host name " + server + " not found. Valid host names are " + hostnames.toString());
                    System.exit(0);
                }
                tableHostname = table.getString(2);
                hostnames.add(tableHostname);
            }
            Date now = new Date(table.getLong(0));
            Histogram newHistogram = AbstractHistogram.fromCompressedBytes(table.getVarbinary(4), CompressionStrategySnappy.INSTANCE);
            Histogram diffHistogram;
            if (m_histogramData == null) {
                diffHistogram = newHistogram;
            } else {
                diffHistogram = Histogram.diff(newHistogram, m_histogramData);
            }
            long totalCount = diffHistogram.getTotalCount();
            if (totalCount > 0) {
                System.out.printf("%12s, %10d, %10.0f, %8.2fms, %8.2fms, %8.2fms, %8.2fms, %8.2fms\n", sdf.format(now), totalCount, ((double) totalCount / duration), (diffHistogram.getValueAtPercentile(95.0D) / 1000.0D), (diffHistogram.getValueAtPercentile(99) / 1000.0D), (diffHistogram.getValueAtPercentile(99.9) / 1000.0D), (diffHistogram.getValueAtPercentile(99.99) / 1000.0D), (diffHistogram.getValueAtPercentile(99.999) / 1000.0D));
            } else {
                System.out.printf("%12s, %10d, %10d, %8.2fms, %8.2fms, %8.2fms, %8.2fms, %8.2fms\n", sdf.format(now), totalCount, 0, 0D, 0D, 0D, 0D, 0D);
            }
            m_histogramData = AbstractHistogram.fromCompressedBytes(table.getVarbinary(4), CompressionStrategySnappy.INSTANCE);
            ;
        }
    }, 0, duration, TimeUnit.SECONDS);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) AbstractHistogram(org.HdrHistogram_voltpatches.AbstractHistogram) Histogram(org.HdrHistogram_voltpatches.Histogram) VoltTable(org.voltdb.VoltTable) Date(java.util.Date) ArrayList(java.util.ArrayList) List(java.util.List) ClientConfig(org.voltdb.client.ClientConfig) Client(org.voltdb.client.Client) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with Histogram

use of org.HdrHistogram_voltpatches.Histogram in project voltdb by VoltDB.

the class TestStatisticsSuite method testLatencyCompressed.

public void testLatencyCompressed() throws Exception {
    System.out.println("\n\nTESTING LATENCY_COMPRESSED STATS\n\n\n");
    Client client = getFullyConnectedClient();
    ColumnInfo[] expectedSchema = new ColumnInfo[5];
    expectedSchema[0] = new ColumnInfo("TIMESTAMP", VoltType.BIGINT);
    expectedSchema[1] = new ColumnInfo("HOST_ID", VoltType.INTEGER);
    expectedSchema[2] = new ColumnInfo("HOSTNAME", VoltType.STRING);
    expectedSchema[3] = new ColumnInfo("SITE_ID", VoltType.INTEGER);
    expectedSchema[4] = new ColumnInfo("HISTOGRAM", VoltType.VARBINARY);
    VoltTable expectedTable = new VoltTable(expectedSchema);
    VoltTable[] results = null;
    // Do some stuff to generate some latency stats
    for (int i = 0; i < SITES * HOSTS; i++) {
        results = client.callProcedure("NEW_ORDER.insert", i).getResults();
    }
    results = client.callProcedure("@Statistics", "LATENCY_COMPRESSED", 0).getResults();
    // one aggregate table returned
    assertEquals(1, results.length);
    System.out.println("Test latency_compressed table: " + results[0].toString());
    validateSchema(results[0], expectedTable);
    // should have at least one row from each host
    results[0].advanceRow();
    Map<String, String> columnTargets = new HashMap<String, String>();
    columnTargets.put("HOSTNAME", results[0].getString("HOSTNAME"));
    validateRowSeenAtAllHosts(results[0], columnTargets, false);
    // actually, there are 26 rows per host so:
    assertEquals(HOSTS, results[0].getRowCount());
    // Check for non-zero invocations (ENG-4668)
    long invocations = 0;
    results[0].resetRowPosition();
    while (results[0].advanceRow()) {
        byte[] histogramBytes = results[0].getVarbinary("HISTOGRAM");
        Histogram h = AbstractHistogram.fromCompressedBytes(histogramBytes, CompressionStrategySnappy.INSTANCE);
        invocations += h.getTotalCount();
    }
    assertTrue(invocations > 0);
}
Also used : AbstractHistogram(org.HdrHistogram_voltpatches.AbstractHistogram) Histogram(org.HdrHistogram_voltpatches.Histogram) HashMap(java.util.HashMap) ColumnInfo(org.voltdb.VoltTable.ColumnInfo) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable)

Example 3 with Histogram

use of org.HdrHistogram_voltpatches.Histogram in project voltdb by VoltDB.

the class LatencyLogger method readHistogramFromFile.

public static void readHistogramFromFile(String filename) {
    System.out.println("Reading histograms from " + filename);
    Hashtable<String, Histogram> histograms = new Hashtable<String, Histogram>();
    Hashtable<String, Long> timestamps = new Hashtable<String, Long>();
    System.out.printf("%23s, %32s, %10s, %10s, %10s, %10s, %10s, %10s, %10s\n", "TIMESTAMP", "HOST NAME", "COUNT", "TPS", "95", "99", "99.9", "99.99", "99.999");
    try {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
        String line = null;
        while ((line = bufferedReader.readLine()) != null) {
            StringTokenizer st = new StringTokenizer(line, ",");
            String time = st.nextToken().replaceAll("^\"|\"$", "");
            String host_id = st.nextToken().replaceAll("^\"|\"$", "");
            String host_name = st.nextToken().replaceAll("^\"|\"$", "");
            String site_id = st.nextToken().replaceAll("^\"|\"$", "");
            String histogram_val = st.nextToken().replaceAll("^\"|\"$", "");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            String friendly_ts = sdf.format(new Date(Long.parseLong(time)));
            byte[] raw_histogram = Encoder.hexDecode(histogram_val);
            Histogram newHistogram = AbstractHistogram.fromCompressedBytes(raw_histogram, CompressionStrategySnappy.INSTANCE);
            // Look for a prior histogram for this host
            Histogram priorHistogram = histograms.get(host_name);
            Long priorTime = timestamps.get(host_name);
            Histogram diffHistogram;
            long diffTime;
            if (priorHistogram == null) {
                diffHistogram = newHistogram;
                diffTime = 1;
            } else {
                diffHistogram = Histogram.diff(newHistogram, priorHistogram);
                diffTime = (Long.parseLong(time) - priorTime) / 1000;
            }
            // Set the most recent histogram as the prior histogram for this hostname.
            histograms.put(host_name, newHistogram);
            timestamps.put(host_name, Long.parseLong(time));
            long totalCount = diffHistogram.getTotalCount();
            if (totalCount > 0) {
                System.out.printf("%23s, %32s, %10d, %10.0f, %8.2fms, %8.2fms, %8.2fms, %8.2fms, %8.2fms\n", friendly_ts, host_name, totalCount, (double) totalCount / diffTime, (diffHistogram.getValueAtPercentile(95.0D) / 1000.0D), (diffHistogram.getValueAtPercentile(99) / 1000.0D), (diffHistogram.getValueAtPercentile(99.9) / 1000.0D), (diffHistogram.getValueAtPercentile(99.99) / 1000.0D), (diffHistogram.getValueAtPercentile(99.999) / 1000.0D));
            } else {
                System.out.printf("%23s, %32s, %10d, %10d, %8.2fms, %8.2fms, %8.2fms, %8.2fms, %8.2fms\n", friendly_ts, host_name, totalCount, 0, 0D, 0D, 0D, 0D, 0D);
            }
        }
        bufferedReader.close();
    } catch (FileNotFoundException e) {
        System.err.println("Histogram file '" + filename + "' could not be found.");
        System.exit(-1);
    } catch (IOException e) {
        System.err.println(e.getMessage());
        System.exit(-1);
    }
//System.out.println("Number of Histograms: " + histograms.size());
}
Also used : AbstractHistogram(org.HdrHistogram_voltpatches.AbstractHistogram) Histogram(org.HdrHistogram_voltpatches.Histogram) InputStreamReader(java.io.InputStreamReader) Hashtable(java.util.Hashtable) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Date(java.util.Date) StringTokenizer(java.util.StringTokenizer) BufferedReader(java.io.BufferedReader) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

AbstractHistogram (org.HdrHistogram_voltpatches.AbstractHistogram)3 Histogram (org.HdrHistogram_voltpatches.Histogram)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 VoltTable (org.voltdb.VoltTable)2 Client (org.voltdb.client.Client)2 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 List (java.util.List)1 StringTokenizer (java.util.StringTokenizer)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ColumnInfo (org.voltdb.VoltTable.ColumnInfo)1 ClientConfig (org.voltdb.client.ClientConfig)1