Search in sources :

Example 36 with KafkaStreams

use of org.apache.kafka.streams.KafkaStreams in project kafka by apache.

the class SimpleBenchmark method kStreamKStreamJoin.

/**
     * Measure the performance of a KStream-KStream left join. The setup is such that each
     * KStream record joins to exactly one element in the other KStream
     */
public void kStreamKStreamJoin(String kStreamTopic1, String kStreamTopic2) throws Exception {
    if (maybeSetupPhase(kStreamTopic1, "simple-benchmark-produce-kstream-topic1", false)) {
        maybeSetupPhase(kStreamTopic2, "simple-benchmark-produce-kstream-topic2", false);
        return;
    }
    CountDownLatch latch = new CountDownLatch(1);
    // setup join
    Properties props = setStreamProperties("simple-benchmark-kstream-kstream-join");
    final KafkaStreams streams = createKafkaStreamsKStreamKStreamJoin(props, kStreamTopic1, kStreamTopic2, latch);
    // run benchmark
    runGenericBenchmark(streams, "Streams KStreamKStream LeftJoin Performance [records/latency/rec-sec/MB-sec  joined]: ", latch);
}
Also used : KafkaStreams(org.apache.kafka.streams.KafkaStreams) CountDownLatch(java.util.concurrent.CountDownLatch) Properties(java.util.Properties)

Example 37 with KafkaStreams

use of org.apache.kafka.streams.KafkaStreams in project kafka by apache.

the class SimpleBenchmark method createKafkaStreamsWithExceptionHandler.

private KafkaStreams createKafkaStreamsWithExceptionHandler(final KStreamBuilder builder, final Properties props) {
    final KafkaStreams streamsClient = new KafkaStreams(builder, props);
    streamsClient.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            System.out.println("FATAL: An unexpected exception is encountered on thread " + t + ": " + e);
            streamsClient.close(30, TimeUnit.SECONDS);
        }
    });
    return streamsClient;
}
Also used : KafkaStreams(org.apache.kafka.streams.KafkaStreams)

Example 38 with KafkaStreams

use of org.apache.kafka.streams.KafkaStreams in project kafka by apache.

the class SimpleBenchmark method count.

/**
     * Measure the performance of a simple aggregate like count.
     * Counts the occurrence of numbers (note that normally people count words, this
     * example counts numbers)
     * @param countTopic Topic where numbers are stored
     * @throws Exception
     */
public void count(String countTopic) throws Exception {
    if (maybeSetupPhase(countTopic, "simple-benchmark-produce-count", false)) {
        return;
    }
    CountDownLatch latch = new CountDownLatch(1);
    Properties props = setStreamProperties("simple-benchmark-count");
    final KafkaStreams streams = createCountStreams(props, countTopic, latch);
    runGenericBenchmark(streams, "Streams Count Performance [records/latency/rec-sec/MB-sec counted]: ", latch);
}
Also used : KafkaStreams(org.apache.kafka.streams.KafkaStreams) CountDownLatch(java.util.concurrent.CountDownLatch) Properties(java.util.Properties)

Example 39 with KafkaStreams

use of org.apache.kafka.streams.KafkaStreams in project kafka by apache.

the class SimpleBenchmark method processStreamWithCachedStateStore.

public void processStreamWithCachedStateStore(String topic) throws Exception {
    if (maybeSetupPhase(topic, "simple-benchmark-process-stream-with-cached-state-store-load", true)) {
        return;
    }
    CountDownLatch latch = new CountDownLatch(1);
    final KafkaStreams streams = createKafkaStreamsWithStateStore(topic, latch, true);
    long latency = startStreamsThread(streams, latch);
    printResults("Streams Performance [records/latency/rec-sec/MB-sec source+cache+store]: ", latency);
}
Also used : KafkaStreams(org.apache.kafka.streams.KafkaStreams) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 40 with KafkaStreams

use of org.apache.kafka.streams.KafkaStreams in project kafka by apache.

the class SimpleBenchmark method createCountStreams.

private KafkaStreams createCountStreams(Properties streamConfig, String topic, final CountDownLatch latch) {
    final KStreamBuilder builder = new KStreamBuilder();
    final KStream<Integer, byte[]> input = builder.stream(topic);
    input.groupByKey().count("tmpStoreName").foreach(new CountDownAction(latch));
    return new KafkaStreams(builder, streamConfig);
}
Also used : KStreamBuilder(org.apache.kafka.streams.kstream.KStreamBuilder) KafkaStreams(org.apache.kafka.streams.KafkaStreams)

Aggregations

KafkaStreams (org.apache.kafka.streams.KafkaStreams)40 Properties (java.util.Properties)24 KStreamBuilder (org.apache.kafka.streams.kstream.KStreamBuilder)23 Test (org.junit.Test)15 KeyValue (org.apache.kafka.streams.KeyValue)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 TestCondition (org.apache.kafka.test.TestCondition)5 StreamsConfig (org.apache.kafka.streams.StreamsConfig)4 ValueJoiner (org.apache.kafka.streams.kstream.ValueJoiner)4 ValueMapper (org.apache.kafka.streams.kstream.ValueMapper)4 Field (java.lang.reflect.Field)3 ArrayList (java.util.ArrayList)3 Metrics (org.apache.kafka.common.metrics.Metrics)3 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)3 DefaultKafkaClientSupplier (org.apache.kafka.streams.processor.internals.DefaultKafkaClientSupplier)3 StreamThread (org.apache.kafka.streams.processor.internals.StreamThread)3 MockKeyValueMapper (org.apache.kafka.test.MockKeyValueMapper)3 KafkaProducer (org.apache.kafka.clients.producer.KafkaProducer)2 KafkaStreamsTest (org.apache.kafka.streams.KafkaStreamsTest)2 Windowed (org.apache.kafka.streams.kstream.Windowed)2