Search in sources :

Example 1 with SpillableMapImpl

use of org.apache.apex.malhar.lib.state.spillable.SpillableMapImpl in project apex-malhar by apache.

the class SpillableDSBenchmarkTest method testSpillableMap.

@Test
public void testSpillableMap() {
    byte[] ID1 = new byte[] { (byte) 1 };
    ManagedStateSpillableStateStore store = new ManagedStateSpillableStateStore();
    ((TFileImpl.DTFileImpl) store.getFileAccess()).setBasePath("target/temp");
    StringSerde keySerde = createKeySerde();
    Serde<String> valueSerde = createValueSerde();
    SpillableMapImpl<String, String> map = new SpillableMapImpl<String, String>(store, ID1, 0L, keySerde, valueSerde);
    store.setup(testMeta.operatorContext);
    map.setup(testMeta.operatorContext);
    final long startTime = System.currentTimeMillis();
    long windowId = 0;
    store.beginWindow(++windowId);
    map.beginWindow(windowId);
    int outputTimes = 0;
    for (int i = 0; i < loopCount; ++i) {
        putEntry(map);
        if (i % tuplesPerWindow == 0) {
            map.endWindow();
            store.endWindow();
            if (i % (tuplesPerWindow * checkPointWindows) == 0) {
                store.beforeCheckpoint(windowId);
                if (windowId > commitDelays) {
                    store.committed(windowId - commitDelays);
                }
            }
            // next window
            store.beginWindow(++windowId);
            map.beginWindow(windowId);
        }
        long spentTime = System.currentTimeMillis() - startTime;
        if (spentTime > outputTimes * 5000) {
            ++outputTimes;
            logger.info("Total Statistics: Spent {} mills for {} operation. average/second: {}", spentTime, i, i * 1000 / spentTime);
            checkEnvironment();
        }
    }
    long spentTime = System.currentTimeMillis() - startTime;
    logger.info("Spent {} mills for {} operation. average: {}", spentTime, loopCount, loopCount / spentTime);
}
Also used : SpillableMapImpl(org.apache.apex.malhar.lib.state.spillable.SpillableMapImpl) StringSerde(org.apache.apex.malhar.lib.utils.serde.StringSerde) ManagedStateSpillableStateStore(org.apache.apex.malhar.lib.state.spillable.managed.ManagedStateSpillableStateStore) Test(org.junit.Test)

Aggregations

SpillableMapImpl (org.apache.apex.malhar.lib.state.spillable.SpillableMapImpl)1 ManagedStateSpillableStateStore (org.apache.apex.malhar.lib.state.spillable.managed.ManagedStateSpillableStateStore)1 StringSerde (org.apache.apex.malhar.lib.utils.serde.StringSerde)1 Test (org.junit.Test)1