Search in sources :

Example 11 with Benchmark

use of com.cinchapi.common.profile.Benchmark in project concourse by cinchapi.

the class ByteableCollectionsTest method testNewVsDeprecatedPerformance.

@Test
public void testNewVsDeprecatedPerformance() throws IOException, InterruptedException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    List<Value> values = Lists.newArrayList();
    while (baos.size() < Math.pow(2, 24)) {
        Value value = TestData.getValue();
        baos.write(ByteBuffers.getByteArray(value.getBytes()));
        values.add(value);
    }
    ByteBuffer bytes = ByteableCollections.toByteBuffer(values);
    Path file = Paths.get(TestData.getTemporaryTestFile());
    String $file = file.toString();
    FileSystem.writeBytes(bytes, $file);
    int bufferSize = 8192;
    Benchmark benchmark1 = new Benchmark(TimeUnit.MILLISECONDS) {

        @Override
        public void action() {
            CloseableIterator<ByteBuffer> it = ByteableCollections.stream(file, bufferSize);
            while (it.hasNext()) {
                Value.fromByteBuffer(it.next());
            }
            it.closeQuietly();
        }
    };
    Benchmark benchmark2 = new Benchmark(TimeUnit.MILLISECONDS) {

        @SuppressWarnings("deprecation")
        @Override
        public void action() {
            Iterator<ByteBuffer> it = ByteableCollections.streamingIterator($file, bufferSize);
            while (it.hasNext()) {
                Value.fromByteBuffer(it.next());
            }
        }
    };
    AtomicDouble avg1 = new AtomicDouble();
    AtomicDouble avg2 = new AtomicDouble();
    CountUpLatch latch = new CountUpLatch();
    Thread t1 = new Thread(() -> {
        double avg = benchmark1.average(10);
        System.out.println("New: " + avg);
        avg1.set(avg);
        latch.countUp();
    });
    Thread t2 = new Thread(() -> {
        double avg = benchmark2.average(10);
        System.out.println("Deprecated: " + avg);
        avg2.set(avg);
        latch.countUp();
    });
    List<Thread> threads = Lists.newArrayList(t1, t2);
    Collections.shuffle(threads);
    for (Thread thread : threads) {
        thread.start();
    }
    latch.await(2);
    Assert.assertTrue(avg1.get() < avg2.get());
}
Also used : Path(java.nio.file.Path) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuffer(java.nio.ByteBuffer) CountUpLatch(com.cinchapi.common.concurrent.CountUpLatch) Value(com.cinchapi.concourse.server.model.Value) Benchmark(com.cinchapi.common.profile.Benchmark) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest) Test(org.junit.Test)

Example 12 with Benchmark

use of com.cinchapi.common.profile.Benchmark in project concourse by cinchapi.

the class StoresTest method testBenchmarkSelectKeysRecordsOptionalAtomicWithNavigation.

@Test
public void testBenchmarkSelectKeysRecordsOptionalAtomicWithNavigation() {
    AtomicSupport store = getStore();
    setupNavigationGraph(store);
    // @formatter:off
    List<String> keys = ImmutableList.of("job.title", "job.company.name", "student.name", "student.email", "job.company.website", "association", "foo.bar", "student.association", "job.company.$id$", "student.name.$id$", "job.company");
    // @formatter:on
    Benchmark serial = new Benchmark(TimeUnit.MICROSECONDS) {

        @Override
        public void action() {
            for (String key : keys) {
                Stores.serialSelect(store, key, 1);
            }
        }
    };
    Benchmark bulk = new Benchmark(TimeUnit.MICROSECONDS) {

        @Override
        public void action() {
            Stores.select(store, keys, 1);
        }
    };
    double serialTime = serial.average(5);
    double bulkTime = bulk.average(5);
    System.out.println("multiple navigation serial = " + serialTime);
    System.out.println("multiple navigation BULK = " + bulkTime);
}
Also used : AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) Benchmark(com.cinchapi.common.profile.Benchmark) Test(org.junit.Test)

Example 13 with Benchmark

use of com.cinchapi.common.profile.Benchmark in project concourse by cinchapi.

the class StoresTest method testBenchmarkSelectKeysRecordsOptionalAtomicWithNoNavigation.

@Test
public void testBenchmarkSelectKeysRecordsOptionalAtomicWithNoNavigation() {
    AtomicSupport store = getStore();
    setupNavigationGraph(store);
    // @formatter:off
    List<String> keys = ImmutableList.of("job", "student", "association", "foo");
    // @formatter:on
    Benchmark serial = new Benchmark(TimeUnit.MICROSECONDS) {

        @Override
        public void action() {
            for (String key : keys) {
                Stores.serialSelect(store, key, 1);
            }
        }
    };
    Benchmark bulk = new Benchmark(TimeUnit.MICROSECONDS) {

        @Override
        public void action() {
            Stores.select(store, keys, 1);
        }
    };
    double serialTime = serial.average(5);
    double bulkTime = bulk.average(5);
    System.out.println("multiple serial = " + serialTime);
    System.out.println("multiple BULK = " + bulkTime);
}
Also used : AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) Benchmark(com.cinchapi.common.profile.Benchmark) Test(org.junit.Test)

Example 14 with Benchmark

use of com.cinchapi.common.profile.Benchmark in project concourse by cinchapi.

the class StoresTest method testBenchmarkSelectKeyRecordsOptionalAtomicWithNoNavigation.

@Test
public void testBenchmarkSelectKeyRecordsOptionalAtomicWithNoNavigation() {
    AtomicSupport store = getStore();
    setupNavigationGraph(store);
    // @formatter:off
    List<String> keys = ImmutableList.of("job");
    // @formatter:on
    Benchmark serial = new Benchmark(TimeUnit.MICROSECONDS) {

        @Override
        public void action() {
            Stores.serialSelect(store, keys.get(0), 1);
        }
    };
    Benchmark bulk = new Benchmark(TimeUnit.MICROSECONDS) {

        @Override
        public void action() {
            Stores.select(store, keys, 1);
        }
    };
    double serialTime = serial.average(5);
    double bulkTime = bulk.average(5);
    System.out.println("single serial = " + serialTime);
    System.out.println("single BULK = " + bulkTime);
}
Also used : AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) Benchmark(com.cinchapi.common.profile.Benchmark) Test(org.junit.Test)

Example 15 with Benchmark

use of com.cinchapi.common.profile.Benchmark in project concourse by cinchapi.

the class TMapsTest method testTObjectResultDatasetPutPerformance.

@Test
public void testTObjectResultDatasetPutPerformance() throws InterruptedException {
    // Constraint: Putting into a Dataset can't be more than an order of
    // magnitude slower...
    Map<Long, Map<String, Set<TObject>>> spec = Maps.newLinkedHashMap();
    int rounds = 1000;
    TimeUnit unit = TimeUnit.MICROSECONDS;
    for (int i = 0; i < rounds; ++i) {
        String key = Random.getSimpleString();
        Set<TObject> values = Sets.newLinkedHashSet();
        for (int j = 0; j < 10; ++j) {
            values.add(Convert.javaToThrift(Random.getObject()));
        }
        Map<String, Set<TObject>> entry = Maps.newLinkedHashMapWithExpectedSize(1);
        entry.put(key, values);
        spec.put((long) i, entry);
    }
    Map<Long, Map<String, Set<TObject>>> map = Maps.newLinkedHashMap();
    Map<Long, Map<String, Set<TObject>>> dataset = new LazyTrackingTObjectResultDataset();
    Benchmark mapBench = new Benchmark(unit) {

        @Override
        public void action() {
            spec.forEach((record, data) -> {
                TMaps.putResultDatasetOptimized(map, record, data);
            });
        }
    };
    Benchmark datasetBench = new Benchmark(unit) {

        @Override
        public void action() {
            spec.forEach((record, data) -> {
                TMaps.putResultDatasetOptimized(dataset, record, data);
            });
        }
    };
    AtomicLong datasetTime = new AtomicLong(0);
    AtomicLong mapTime = new AtomicLong(0);
    CountDownLatch latch = new CountDownLatch(2);
    Thread t1 = new Thread(() -> {
        datasetTime.set(datasetBench.run());
        latch.countDown();
    });
    Thread t2 = new Thread(() -> {
        mapTime.set(mapBench.run());
        latch.countDown();
    });
    t2.start();
    t1.start();
    latch.await();
    double datasetTimeDigits = Math.ceil(Math.log10(datasetTime.get()));
    double mapTimeDigits = Math.ceil(Math.log10(mapTime.get()));
    System.out.println(AnyStrings.format("Dataset = {} {} with {} digits", datasetTime.get(), unit, datasetTimeDigits));
    System.out.println(AnyStrings.format("Map = {} {} with {} digits", mapTime.get(), unit, mapTimeDigits));
    Assert.assertTrue(AnyStrings.format("Datset took {} {} and Map took {} {}", datasetTime.get(), unit, mapTime.get(), unit), datasetTimeDigits - mapTimeDigits <= 1);
}
Also used : TObject(com.cinchapi.concourse.thrift.TObject) Set(java.util.Set) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) Benchmark(com.cinchapi.common.profile.Benchmark) TimeUnit(java.util.concurrent.TimeUnit) Map(java.util.Map) LazyTrackingTObjectResultDataset(com.cinchapi.concourse.server.plugin.data.LazyTrackingTObjectResultDataset) Test(org.junit.Test)

Aggregations

Benchmark (com.cinchapi.common.profile.Benchmark)23 Test (org.junit.Test)23 AtomicSupport (com.cinchapi.concourse.server.storage.AtomicSupport)4 TObject (com.cinchapi.concourse.thrift.TObject)2 CountUpLatch (com.cinchapi.common.concurrent.CountUpLatch)1 CsvImporter (com.cinchapi.concourse.importer.CsvImporter)1 Importer (com.cinchapi.concourse.importer.Importer)1 Value (com.cinchapi.concourse.server.model.Value)1 LazyTrackingTObjectResultDataset (com.cinchapi.concourse.server.plugin.data.LazyTrackingTObjectResultDataset)1 StoreTest (com.cinchapi.concourse.server.storage.StoreTest)1 ClientServerTest (com.cinchapi.concourse.test.ClientServerTest)1 ConcourseBaseTest (com.cinchapi.concourse.test.ConcourseBaseTest)1 Random (com.cinchapi.concourse.util.Random)1 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ByteBuffer (java.nio.ByteBuffer)1 Path (java.nio.file.Path)1 Map (java.util.Map)1 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1