Search in sources :

Example 1 with Measurements

use of site.ycsb.measurements.Measurements in project YCSB by brianfrankcooper.

the class TestMeasurementsExporter method testJSONArrayMeasurementsExporter.

@Test
public void testJSONArrayMeasurementsExporter() throws IOException {
    Properties props = new Properties();
    props.put(Measurements.MEASUREMENT_TYPE_PROPERTY, "histogram");
    props.put(OneMeasurementHistogram.VERBOSE_PROPERTY, "true");
    Measurements mm = new Measurements(props);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    JSONArrayMeasurementsExporter export = new JSONArrayMeasurementsExporter(out);
    long min = 5000;
    long max = 100000;
    ZipfianGenerator zipfian = new ZipfianGenerator(min, max);
    for (int i = 0; i < 1000; i++) {
        int rnd = zipfian.nextValue().intValue();
        mm.measure("UPDATE", rnd);
    }
    mm.exportMeasurements(export);
    export.close();
    ObjectMapper mapper = new ObjectMapper();
    JsonNode json = mapper.readTree(out.toString("UTF-8"));
    assertTrue(json.isArray());
    assertEquals(json.get(0).get("measurement").asText(), "Operations");
    assertEquals(json.get(4).get("measurement").asText(), "MaxLatency(us)");
    assertEquals(json.get(11).get("measurement").asText(), "4");
}
Also used : ZipfianGenerator(site.ycsb.generator.ZipfianGenerator) Measurements(site.ycsb.measurements.Measurements) JsonNode(org.codehaus.jackson.JsonNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.testng.annotations.Test)

Example 2 with Measurements

use of site.ycsb.measurements.Measurements in project YCSB by brianfrankcooper.

the class HBaseClient2 method cleanup.

/**
 * Cleanup any state for this DB. Called once per DB instance; there is one DB
 * instance per client thread.
 */
@Override
public void cleanup() throws DBException {
    // Get the measurements instance as this is the only client that should
    // count clean up time like an update if client-side buffering is
    // enabled.
    Measurements measurements = Measurements.getMeasurements();
    try {
        long st = System.nanoTime();
        if (bufferedMutator != null) {
            bufferedMutator.close();
        }
        if (currentTable != null) {
            currentTable.close();
        }
        long en = System.nanoTime();
        final String type = clientSideBuffering ? "UPDATE" : "CLEANUP";
        measurements.measure(type, (int) ((en - st) / 1000));
        int threadCount = THREAD_COUNT.decrementAndGet();
        if (threadCount <= 0) {
            // Means we are done so ok to shut down the Connection.
            synchronized (THREAD_COUNT) {
                if (connection != null) {
                    connection.close();
                    connection = null;
                }
            }
        }
    } catch (IOException e) {
        throw new DBException(e);
    }
}
Also used : DBException(site.ycsb.DBException) Measurements(site.ycsb.measurements.Measurements) IOException(java.io.IOException)

Example 3 with Measurements

use of site.ycsb.measurements.Measurements in project YCSB by brianfrankcooper.

the class HBaseClient1 method cleanup.

/**
 * Cleanup any state for this DB. Called once per DB instance; there is one DB
 * instance per client thread.
 */
@Override
public void cleanup() throws DBException {
    // Get the measurements instance as this is the only client that should
    // count clean up time like an update if client-side buffering is
    // enabled.
    Measurements measurements = Measurements.getMeasurements();
    try {
        long st = System.nanoTime();
        if (bufferedMutator != null) {
            bufferedMutator.close();
        }
        if (currentTable != null) {
            currentTable.close();
        }
        long en = System.nanoTime();
        final String type = clientSideBuffering ? "UPDATE" : "CLEANUP";
        measurements.measure(type, (int) ((en - st) / 1000));
        int threadCount = THREAD_COUNT.decrementAndGet();
        if (threadCount <= 0) {
            // Means we are done so ok to shut down the Connection.
            synchronized (THREAD_COUNT) {
                if (connection != null) {
                    connection.close();
                    connection = null;
                }
            }
        }
    } catch (IOException e) {
        throw new DBException(e);
    }
}
Also used : DBException(site.ycsb.DBException) Measurements(site.ycsb.measurements.Measurements) IOException(java.io.IOException)

Aggregations

Measurements (site.ycsb.measurements.Measurements)3 IOException (java.io.IOException)2 DBException (site.ycsb.DBException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Properties (java.util.Properties)1 JsonNode (org.codehaus.jackson.JsonNode)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 Test (org.testng.annotations.Test)1 ZipfianGenerator (site.ycsb.generator.ZipfianGenerator)1