SlideShare a Scribd company logo
1
Building Streaming Applications with
Apache Apex
Thomas Weise <thw@apache.org> @thweise
PMC Chair Apache Apex, Architect DataTorrent
Big Data Spain, Madrid, Nov 18th 2016
Agenda
3
• Application Development Model
• Creating Apex Application - Project S tructure
• Apex APIs
• Configuration Example
• Operator APIs
• Overview of Operator Library
• Frequently used Connectors
• S tateful Transformation & Windowing
• S calability – Partitioning
• End-to-end Exactly Once
Application Development Model
4
▪Stream is a sequence of data tuples
▪Operator takes one or more input streams, performs computations & emits one or more output streams
• Each Operator is YOUR custom business logic in java, or built-in operator from our open source library
• Operator has many instances that run in parallel and each instance is single-threaded
▪Directed Acyclic Graph (DAG) is made up of operators and streams
Directed Acyclic Graph (DAG)
Output
Stream
Tupl
e
Tupl
e
er
Operator
er
Operator
er
Operator
er
Operator
er
Operator
er
Operator
Creating Apex Application Project
5
chinmay@chinmay-VirtualBox:~/src$ mvn archetype:generate -DarchetypeGroupId=org.apache.apex -
DarchetypeArtifactId=apex-app-archetype -DarchetypeVersion=LATEST -DgroupId=com.example -
Dpackage=com.example.myapexapp -DartifactId=myapexapp -Dversion=1.0-SNAPSHOT
…
…
...
Confirm properties configuration:
groupId: com.example
artifactId: myapexapp
version: 1.0-SNAPSHOT
package: com.example.myapexapp
archetypeVersion: LATEST
Y: : Y
…
…
...
[INFO] project created from Archetype in dir: /media/sf_workspace/src/myapexapp
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.141 s
[INFO] Finished at: 2016-11-15T14:06:56+05:30
[INFO] Final Memory: 18M/216M
[INFO] ------------------------------------------------------------------------
chinmay@chinmay-VirtualBox:~/src$
https://www.youtube.com/watch?v=z-eeh-tjQrc
Apex Application Project Structure
6
• pom.xml
•Defines project structure and
dependencies
•Application.java
•Defines the DAG
•RandomNumberGenerator.java
•S ample Operator
•properties.xml
•Contains operator and application
properties and attributes
•ApplicationTest.java
•S ample test to test application in local
mode
APIs: Compositional (Low level)
7
Input Parser Counter Output
CountsWordsLines
Kafka Database
Filter
Filtered
Apex APIs: Declarative (High Level)
8
File
Input
Parser
Word
Counter
Console
Output
CountsWordsLines
Folder StdOut
StreamFactory.fromFolder("/tmp")
.flatMap(input -> Arrays.asList(input.split(" ")), name("Words"))
.window(new WindowOption.GlobalWindow(),
new TriggerOption().accumulatingFiredPanes().withEarlyFiringsAtEvery(1))
.countByKey(input -> new Tuple.PlainTuple<>(new KeyValPair<>(input, 1L)), name("countByKey"))
.map(input -> input.getValue(), name("Counts"))
.print(name("Console"))
.populateDag(dag);
APIs: S QL
9
Kafka
Input
CSV
Parser
Filter CSV
Formattter
FilteredWordsLines
Kafka File
Project
Projected Line
Writer
Formatted
SQLExecEnvironment.getEnvironment()
.registerTable("ORDERS",
new KafkaEndpoint(conf.get("broker"), conf.get("topic"),
new CSVMessageFormat(conf.get("schemaInDef"))))
.registerTable("SALES",
new FileEndpoint(conf.get("destFolder"), conf.get("destFileName"),
new CSVMessageFormat(conf.get("schemaOutDef"))))
.registerFunction("APEXCONCAT", this.getClass(), "apex_concat_str")
.executeSQL(dag,
"INSERT INTO SALES " +
"SELECT STREAM ROWTIME, FLOOR(ROWTIME TO DAY), APEXCONCAT('OILPAINT', SUBSTRING(PRODUCT, 6, 7) " +
"FROM ORDERS WHERE ID > 3 AND PRODUCT LIKE 'paint%'");
APIs: Beam
10
• Apex Runner for Apache Beam is now available!!
•Build once run-anywhere model
•Beam S treaming applications can be run on apex runner:
public static void main(String[] args) {
Options options = PipelineOptionsFactory.fromArgs(args).withValidation().as(Options.class);
// Run with Apex runner
options.setRunner(ApexRunner.class);
Pipeline p = Pipeline.create(options);
p.apply("ReadLines", TextIO.Read.from(options.getInput()))
.apply(new CountWords())
.apply(MapElements.via(new FormatAsTextFn()))
.apply("WriteCounts", TextIO.Write.to(options.getOutput()));
.run().waitUntilFinish();
}
APIs: S AMOA
11
•Build once run-anywhere model for online machine learning algorithms
•Any machine learning algorithm present in S AMOA can be run directly on Apex.
•Uses Apex Iteration S upport
•Following example does classification of input data from HDFS using VHT algorithm on
Apex:
ᵒ bin/samoa apex ../SAMOA-Apex-0.4.0-incubating-SNAPSHOT.jar "PrequentialEvaluation
-d /tmp/dump.csv
-l (classifiers.trees.VerticalHoeffdingTree -p 1)
-s (org.apache.samoa.streams.ArffFileStream
-s HDFSFileStreamSource
-f /tmp/user/input/covtypeNorm.arff)"
Configuration (properties.xml)
12
Input Parser Counter Output
CountsWordsLines
Kafka Database
Filter
Filtered
Streaming Window
Processing Time Window
13
•Finite time sliced windows based on processing (event arrival) time
•Used for bookkeeping of streaming application
•Derived Windows are: Checkpoint Windows, Committed Windows
Operator APIs
14
Next
streaming
window
Next
streaming
window
Input Adapters - S tarting of the pipeline. Interacts with external system to generate stream
Generic Operators - Processing part of pipeline
Output Adapters - Last operator in pipeline. Interacts with external system to finalize the processed stream
OutputPort::emit()
Operator Library
15
RDBMS
• JDBC
• MySQL
• Oracle
• MemSQL
NoSQL
• Cassandra, HBase
• Aerospike, Accumulo
• Couchbase/ CouchDB
• Redis, MongoDB
• Geode
Messaging
• Kafka
• JMS (ActiveMQ etc.)
• Kinesis, SQS
• Flume, NiFi
File Systems
• HDFS/ Hive
• Local File
• S3
Parsers
• XML
• JSON
• CSV
• Avro
• Parquet
Transformations
• Filters, Expression, Enrich
• Windowing, Aggregation
• Join
• Dedup
Analytics
• Dimensional Aggregations
(with state management for
historical data + query)
Protocols
• HTTP
• FTP
• WebSocket
• MQTT
• SMTP
Other
• Elastic Search
• Script (JavaScript, Python, R)
• Solr
• Twitter
Frequently used Connectors
Kafka Input
16
KafkaSinglePortInputOperator KafkaSinglePortByteArrayInputOperator
Library malhar-contrib malhar-kafka
Kafka Consumer 0.8 0.9
Emit Type byte[] byte[]
Fault-Tolerance At Least Once, Exactly Once At Least Once, Exactly Once
Scalability Static and Dynamic (with Kafka
metadata)
Static and Dynamic (with Kafka metadata)
Multi-Cluster/Topic Yes Yes
Idempotent Yes Yes
Partition Strategy 1:1, 1:M 1:1, 1:M
Frequently used Connectors
Kafka Output
17
KafkaSinglePortOutputOperator KafkaSinglePortExactlyOnceOutputOperator
Library malhar-contrib malhar-kafka
Kafka Producer 0.8 0.9
Fault-Tolerance At Least Once At Least Once, Exactly Once
Scalability Static and Dynamic (with Kafka
metadata)
Static and Dynamic, Automatic Partitioning
based on Kafka metadata
Multi-Cluster/Topic Yes Yes
Idempotent Yes Yes
Partition Strategy 1:1, 1:M 1:1, 1:M
Frequently used Connectors
File Input
18
•AbstractFileInputOperator
•Used to read a file from source and
emit the content of the file to
downstream operator
•Operator is idempotent
•S upports Partitioning
•Few Concrete Impl
•FileLineInputOperator
•AvroFileInputOperator
•ParquetFilePOJ OReader
•https://www.datatorrent.com/blog/f
ault-tolerant-file-processing/
Frequently used Connectors
File Output
19
•AbstractFileOutputOperator
•Writes data to a file
•S upports Partitions
•Exactly-once results
•Upstream operators should be
idempotent
•Few Concrete Impl
•S tringFileOutputOperator
•https://www.datatorrent.com/blog/f
ault-tolerant-file-processing/
Windowing Support
20
• Event-time Windows
• Computation based on event-time present in the tuple
• Types of event-time windows:
ᵒ Global : S ingle event-time window throughout the lifecycle of application
ᵒ Timed : Tuple is assigned to single, non-overlapping, fixed width windows
immediately followed by next window
ᵒ Sliding Time : Tuple is can be assigned to multiple, overlapping fixed width windows.
ᵒ Session : Tuple is assigned to single, variable width windows with predefined min gap
Stateful Windowed Processing
21
• WindowedOperator (org.apache.apex:malhar-library)
• Used to process data based on Event time as contrary to ingression time
• S upports windowing semantics of Apache Beam model
• Features:
ᵒ Watermarks
ᵒ Allowed Lateness
ᵒ Accumulation
ᵒ Accumulation Modes: Accumulating, Discarding, Accumulating & Retracting
ᵒ Triggers
• S torage
ᵒ In memory (checkpointed)
ᵒ Managed S tate
Stateful Windowed Processing
Compositional API
22
@Override
public void populateDAG(DAG dag, Configuration configuration)
{
WordGenerator inputOperator = new WordGenerator();
KeyedWindowedOperatorImpl windowedOperator = new KeyedWindowedOperatorImpl();
Accumulation<Long, MutableLong, Long> sum = new SumAccumulation();
windowedOperator.setAccumulation(sum);
windowedOperator.setDataStorage(new InMemoryWindowedKeyedStorage<String, MutableLong>());
windowedOperator.setRetractionStorage(new InMemoryWindowedKeyedStorage<String, Long>());
windowedOperator.setWindowStateStorage(new InMemoryWindowedStorage<WindowState>());
windowedOperator.setWindowOption(new WindowOption.TimeWindows(Duration.standardMinutes(1)));
windowedOperator.setTriggerOption(TriggerOption.AtWatermark()
.withEarlyFiringsAtEvery(Duration.millis(1000))
.accumulatingAndRetractingFiredPanes());
windowedOperator.setAllowedLateness(Duration.millis(14000));
ConsoleOutputOperator outputOperator = new ConsoleOutputOperator();
dag.addOperator("inputOperator", inputOperator);
dag.addOperator("windowedOperator", windowedOperator);
dag.addOperator("outputOperator", outputOperator);
dag.addStream("input_windowed", inputOperator.output, windowedOperator.input);
dag.addStream("windowed_output", windowedOperator.output, outputOperator.input);
}
Stateful Windowed Processing
Declarative API
23
StreamFactory.fromFolder("/tmp")
.flatMap(input -> Arrays.asList(input.split(" ")), name("ExtractWords"))
.map(input -> new TimestampedTuple<>(System.currentTimeMillis(), input), name("AddTimestampFn"))
.window(new TimeWindows(Duration.standardMinutes(WINDOW_SIZE)),
new TriggerOption().accumulatingFiredPanes().withEarlyFiringsAtEvery(1))
.countByKey(input -> new TimestampedTuple<>(input.getTimestamp(), new KeyValPair<>(input.getValue(),
1L))), name("countWords"))
.map(new FormatAsTableRowFn(), name("FormatAsTableRowFn"))
.print(name("console"))
.populateDag(dag);
•Goal: low latency and high throughput
•Replicate processing logic, partition data/stream
•Configurable (Application.java or properties.xml)
•StreamCodec
•Controls distribution of tuples to downstream
partitions
•Unifier (combine results of partitions)
•Passthrough unifier added by platform to merge
results from upstream partitions
•Can also be customized
•Type of partitions
•Static partitions - S tatically partition at launch time
•Dynamic partitions - Partitions changing at runtime
based on latency and/or throughput
•Parallel partitions - Upstream and downstream
operators using same partition scheme
S calability - Partitioning
24
Scalability - Partitioning (contd.)
25
0 1 2 3
Logical DAG
0 1 2 U
Physical DAG
1
1 2
2
3
Parallel
Partitions
M x N
Partitions
OR
Shuffle
<configuration>
<property>
<name>dt.operator.1.attr.PARTITIONER</name>
<value>com.datatorrent.common.partitioner.StatelessPartitioner:3</value>
</property>
<property>
<name>dt.operator.2.port.inputPortName.attr.PARTITION_PARALLEL</name>
<value>true</value>
</property>
</configuration>
End-to-End Exactly-Once
26
Input Counter Store
Aggregate
CountsWords
Kafka Database
● Input
○ Uses com.datatorrent.contrib.kafka.KafkaSinglePortStringInputOperator
○ Emits words as a stream
○ Operator is idempotent
● Counter
○ com.datatorrent.lib.algo.UniqueCounter
● Store
○ Uses CountStoreOperator
○ Inserts into JDBC
○ Exactly-once results (End-To-End Exactly-once = At-least-once + Idempotency + Consistent State)
https://github.com/DataTorrent/examples/blob/master/tutorials/exactly-once
https://www.datatorrent.com/blog/end-to-end-exactly-once-with-apache-apex/
End-to-End Exactly-Once (contd.)
27
Input Counter Store
Aggregate
CountsWords
Kafka Database
public static class CountStoreOperator extends AbstractJdbcTransactionableOutputOperator<KeyValPair<String, Integer>>
{
public static final String SQL =
"MERGE INTO words USING (VALUES ?, ?) I (word, wcount)"
+ " ON (words.word=I.word)"
+ " WHEN MATCHED THEN UPDATE SET words.wcount = words.wcount + I.wcount"
+ " WHEN NOT MATCHED THEN INSERT (word, wcount) VALUES (I.word, I.wcount)";
@Override
protected String getUpdateCommand()
{
return SQL;
}
@Override
protected void setStatementParameters(PreparedStatement statement, KeyValPair<String, Integer> tuple) throws SQLException
{
statement.setString(1, tuple.getKey());
statement.setInt(2, tuple.getValue());
}
}
End-to-End Exactly-Once (contd.)
28
https://www.datatorrent.com/blog/fault-tolerant-file-processing/
Who is using Apex?
29
• Powered by Apex
ᵒ http://apex.apache.org/powered-by-apex.html
ᵒ Also using Apex? Let us know to be added: users@apex.apache.org or @ApacheApex
• Pubmatic
ᵒ https://www.youtube.com/watch?v=JSXpgfQFcU8
• GE
ᵒ https://www.youtube.com/watch?v=hmaSkXhHNu0
ᵒ http://www.slideshare.net/ApacheApex/ge-iot-predix-time-series-data-ingestion-service-
using-apache-apex-hadoop
• SilverSpring Networks
ᵒ https://www.youtube.com/watch?v=8VORISKeSjI
ᵒ http://www.slideshare.net/ApacheApex/iot-big-data-ingestion-and-processing-in-hadoop-by-
silver-spring-networks
Resources
30
• http://apex.apache.org/
• Learn more - http://apex.apache.org/docs.html
• Get involved - http://apex.apache.org/community.html
• Download - http://apex.apache.org/downloads.html
• Follow @ApacheApex - https://twitter.com/apacheapex
• Meetups - https://www.meetup.com/topics/apache-apex/
• Examples - https://github.com/DataTorrent/examples
• Slideshare - http://www.slideshare.net/ApacheApex/presentations
• https://www.youtube.com/results?search_query=apache+apex
• Free Enterprise License for S tartups -
https://www.datatorrent.com/product/startup-accelerator/
Q&A
31

More Related Content

PDF
Low Latency Polyglot Model Scoring using Apache Apex
PPTX
Big Data Berlin v8.0 Stream Processing with Apache Apex
PPTX
Ingestion and Dimensions Compute and Enrich using Apache Apex
PPTX
Next Gen Big Data Analytics with Apache Apex
PPTX
Apache Beam (incubating)
PPTX
Intro to Apache Apex - Next Gen Native Hadoop Platform - Hackac
PPTX
Java High Level Stream API
PDF
Actionable Insights with Apache Apex at Apache Big Data 2017 by Devendra Tagare
Low Latency Polyglot Model Scoring using Apache Apex
Big Data Berlin v8.0 Stream Processing with Apache Apex
Ingestion and Dimensions Compute and Enrich using Apache Apex
Next Gen Big Data Analytics with Apache Apex
Apache Beam (incubating)
Intro to Apache Apex - Next Gen Native Hadoop Platform - Hackac
Java High Level Stream API
Actionable Insights with Apache Apex at Apache Big Data 2017 by Devendra Tagare

What's hot (20)

PDF
Large-Scale Stream Processing in the Hadoop Ecosystem - Hadoop Summit 2016
PPTX
Architectual Comparison of Apache Apex and Spark Streaming
PDF
From Batch to Streaming with Apache Apex Dataworks Summit 2017
PDF
Large-Scale Stream Processing in the Hadoop Ecosystem
PPTX
Intro to Apache Apex @ Women in Big Data
PPTX
Intro to Apache Apex - Next Gen Platform for Ingest and Transform
PDF
Apache Big Data EU 2016: Next Gen Big Data Analytics with Apache Apex
PDF
Developing streaming applications with apache apex (strata + hadoop world)
PDF
Spark Summit EU talk by Ram Sriharsha and Vlad Feinberg
PPTX
Assaf Araki – Real Time Analytics at Scale
PDF
Building your first aplication using Apache Apex
PPTX
Unifying Stream, SWL and CEP for Declarative Stream Processing with Apache Flink
PPTX
Introduction to Apache Apex
PPTX
Debunking Common Myths in Stream Processing
PDF
Apache Spark vs Apache Flink
PDF
Apache con big data 2015 - Data Science from the trenches
PDF
Albert Bifet – Apache Samoa: Mining Big Data Streams with Apache Flink
PPTX
Apache Big Data 2016: Next Gen Big Data Analytics with Apache Apex
PDF
Extending The Yahoo Streaming Benchmark to Apache Apex
PPTX
Introduction to Real-Time Data Processing
Large-Scale Stream Processing in the Hadoop Ecosystem - Hadoop Summit 2016
Architectual Comparison of Apache Apex and Spark Streaming
From Batch to Streaming with Apache Apex Dataworks Summit 2017
Large-Scale Stream Processing in the Hadoop Ecosystem
Intro to Apache Apex @ Women in Big Data
Intro to Apache Apex - Next Gen Platform for Ingest and Transform
Apache Big Data EU 2016: Next Gen Big Data Analytics with Apache Apex
Developing streaming applications with apache apex (strata + hadoop world)
Spark Summit EU talk by Ram Sriharsha and Vlad Feinberg
Assaf Araki – Real Time Analytics at Scale
Building your first aplication using Apache Apex
Unifying Stream, SWL and CEP for Declarative Stream Processing with Apache Flink
Introduction to Apache Apex
Debunking Common Myths in Stream Processing
Apache Spark vs Apache Flink
Apache con big data 2015 - Data Science from the trenches
Albert Bifet – Apache Samoa: Mining Big Data Streams with Apache Flink
Apache Big Data 2016: Next Gen Big Data Analytics with Apache Apex
Extending The Yahoo Streaming Benchmark to Apache Apex
Introduction to Real-Time Data Processing
Ad

Viewers also liked (20)

PDF
Case of success: Visualization as an example for exercising democratic transp...
PDF
Big Migrations: Moving elephant herds by Carlos Izquierdo
PDF
Assessing spatial accessibility to primary health care services in the Metrop...
PDF
Advanced data science algorithms applied to scalable stream processing by Dav...
PDF
Enabling the Bank of the Future by Ignacio Bernal
PDF
Finding the needle in the haystack: how Nestle is leveraging big data to defe...
PDF
From data to AI with the Machine Learning Canvas by Louis Dorard Slides
PDF
Converging Big Data and Application Infrastructure by Steven Poutsy
PDF
Big data in 140 characters by Joe Rice
PDF
Are we reaching a Data Science Singularity? How Cognitive Computing is emergi...
PDF
Why Apache Flink is better than Spark by Rubén Casado
PDF
VP of WW Partners by Alan Chhabra
PDF
From data to numbers to knowledge: semantic embeddings By Alvaro Barbero
PDF
Migration and Coexistence between Relational and NoSQL Databases by Manuel H...
PDF
Top industry use cases for streaming analytics
PPTX
Apache Flink: Real-World Use Cases for Streaming Analytics
PDF
HOW TO APPLY BIG DATA ANALYTICS AND MACHINE LEARNING TO REAL TIME PROCESSING ...
PDF
Introduction to Apache Apex by Thomas Weise
PPTX
DEPOTnext 23 February 2017- Orange Sky Laundry
PDF
The Rise of Engineering-Driven Analytics by Loren Shure
Case of success: Visualization as an example for exercising democratic transp...
Big Migrations: Moving elephant herds by Carlos Izquierdo
Assessing spatial accessibility to primary health care services in the Metrop...
Advanced data science algorithms applied to scalable stream processing by Dav...
Enabling the Bank of the Future by Ignacio Bernal
Finding the needle in the haystack: how Nestle is leveraging big data to defe...
From data to AI with the Machine Learning Canvas by Louis Dorard Slides
Converging Big Data and Application Infrastructure by Steven Poutsy
Big data in 140 characters by Joe Rice
Are we reaching a Data Science Singularity? How Cognitive Computing is emergi...
Why Apache Flink is better than Spark by Rubén Casado
VP of WW Partners by Alan Chhabra
From data to numbers to knowledge: semantic embeddings By Alvaro Barbero
Migration and Coexistence between Relational and NoSQL Databases by Manuel H...
Top industry use cases for streaming analytics
Apache Flink: Real-World Use Cases for Streaming Analytics
HOW TO APPLY BIG DATA ANALYTICS AND MACHINE LEARNING TO REAL TIME PROCESSING ...
Introduction to Apache Apex by Thomas Weise
DEPOTnext 23 February 2017- Orange Sky Laundry
The Rise of Engineering-Driven Analytics by Loren Shure
Ad

Similar to Stream Processing use cases and applications with Apache Apex by Thomas Weise (20)

PDF
BigDataSpain 2016: Stream Processing Applications with Apache Apex
PDF
Apache Big Data EU 2016: Building Streaming Applications with Apache Apex
PPTX
Intro to Apache Apex (next gen Hadoop) & comparison to Spark Streaming
PPTX
Deep Dive into Apache Apex App Development
PPTX
Thomas Weise, Apache Apex PMC Member and Architect/Co-Founder, DataTorrent - ...
PPTX
Introduction to Apache Apex and writing a big data streaming application
PDF
Building Your First Apache Apex Application
PPTX
Hadoop Summit SJ 2016: Next Gen Big Data Analytics with Apache Apex
PDF
BigDataSpain 2016: Introduction to Apache Apex
PPTX
Apache Apex: Stream Processing Architecture and Applications
PPTX
Apache Apex: Stream Processing Architecture and Applications
PDF
Streaming architecture patterns
PPTX
Stream Processing with Apache Apex
PPSX
GE IOT Predix Time Series & Data Ingestion Service using Apache Apex (Hadoop)
PDF
Real-time Stream Processing using Apache Apex
PDF
Introduction to Apache Apex - CoDS 2016
PPTX
Spark Streaming & Kafka-The Future of Stream Processing
PPTX
Spark Streaming& Kafka-The Future of Stream Processing by Hari Shreedharan of...
PDF
Visualizing Big Data in Realtime
PPTX
Introduction to Apache Apex
BigDataSpain 2016: Stream Processing Applications with Apache Apex
Apache Big Data EU 2016: Building Streaming Applications with Apache Apex
Intro to Apache Apex (next gen Hadoop) & comparison to Spark Streaming
Deep Dive into Apache Apex App Development
Thomas Weise, Apache Apex PMC Member and Architect/Co-Founder, DataTorrent - ...
Introduction to Apache Apex and writing a big data streaming application
Building Your First Apache Apex Application
Hadoop Summit SJ 2016: Next Gen Big Data Analytics with Apache Apex
BigDataSpain 2016: Introduction to Apache Apex
Apache Apex: Stream Processing Architecture and Applications
Apache Apex: Stream Processing Architecture and Applications
Streaming architecture patterns
Stream Processing with Apache Apex
GE IOT Predix Time Series & Data Ingestion Service using Apache Apex (Hadoop)
Real-time Stream Processing using Apache Apex
Introduction to Apache Apex - CoDS 2016
Spark Streaming & Kafka-The Future of Stream Processing
Spark Streaming& Kafka-The Future of Stream Processing by Hari Shreedharan of...
Visualizing Big Data in Realtime
Introduction to Apache Apex

More from Big Data Spain (20)

PDF
Big Data, Big Quality? by Irene Gonzálvez at Big Data Spain 2017
PDF
Scaling a backend for a big data and blockchain environment by Rafael Ríos at...
PDF
AI: The next frontier by Amparo Alonso at Big Data Spain 2017
PDF
Disaster Recovery for Big Data by Carlos Izquierdo at Big Data Spain 2017
PDF
Presentation: Boost Hadoop and Spark with in-memory technologies by Akmal Cha...
PDF
Data science for lazy people, Automated Machine Learning by Diego Hueltes at ...
PDF
Training Deep Learning Models on Multiple GPUs in the Cloud by Enrique Otero ...
PDF
Unbalanced data: Same algorithms different techniques by Eric Martín at Big D...
PDF
State of the art time-series analysis with deep learning by Javier Ordóñez at...
PDF
Trading at market speed with the latest Kafka features by Iñigo González at B...
PDF
Unified Stream Processing at Scale with Apache Samza by Jake Maes at Big Data...
PDF
The Analytic Platform behind IBM’s Watson Data Platform by Luciano Resende a...
PDF
Artificial Intelligence and Data-centric businesses by Óscar Méndez at Big Da...
PDF
Why big data didn’t end causal inference by Totte Harinen at Big Data Spain 2017
PDF
Meme Index. Analyzing fads and sensations on the Internet by Miguel Romero at...
PDF
Vehicle Big Data that Drives Smart City Advancement by Mike Branch at Big Dat...
PDF
End of the Myth: Ultra-Scalable Transactional Management by Ricardo Jiménez-P...
PDF
Attacking Machine Learning used in AntiVirus with Reinforcement by Rubén Mart...
PDF
More people, less banking: Blockchain by Salvador Casquero at Big Data Spain ...
PDF
Make the elephant fly, once again by Sourygna Luangsay at Big Data Spain 2017
Big Data, Big Quality? by Irene Gonzálvez at Big Data Spain 2017
Scaling a backend for a big data and blockchain environment by Rafael Ríos at...
AI: The next frontier by Amparo Alonso at Big Data Spain 2017
Disaster Recovery for Big Data by Carlos Izquierdo at Big Data Spain 2017
Presentation: Boost Hadoop and Spark with in-memory technologies by Akmal Cha...
Data science for lazy people, Automated Machine Learning by Diego Hueltes at ...
Training Deep Learning Models on Multiple GPUs in the Cloud by Enrique Otero ...
Unbalanced data: Same algorithms different techniques by Eric Martín at Big D...
State of the art time-series analysis with deep learning by Javier Ordóñez at...
Trading at market speed with the latest Kafka features by Iñigo González at B...
Unified Stream Processing at Scale with Apache Samza by Jake Maes at Big Data...
The Analytic Platform behind IBM’s Watson Data Platform by Luciano Resende a...
Artificial Intelligence and Data-centric businesses by Óscar Méndez at Big Da...
Why big data didn’t end causal inference by Totte Harinen at Big Data Spain 2017
Meme Index. Analyzing fads and sensations on the Internet by Miguel Romero at...
Vehicle Big Data that Drives Smart City Advancement by Mike Branch at Big Dat...
End of the Myth: Ultra-Scalable Transactional Management by Ricardo Jiménez-P...
Attacking Machine Learning used in AntiVirus with Reinforcement by Rubén Mart...
More people, less banking: Blockchain by Salvador Casquero at Big Data Spain ...
Make the elephant fly, once again by Sourygna Luangsay at Big Data Spain 2017

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
cuic standard and advanced reporting.pdf
PPT
Teaching material agriculture food technology
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Modernizing your data center with Dell and AMD
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
NewMind AI Weekly Chronicles - August'25 Week I
Transforming Manufacturing operations through Intelligent Integrations
cuic standard and advanced reporting.pdf
Teaching material agriculture food technology
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
The Rise and Fall of 3GPP – Time for a Sabbatical?
NewMind AI Monthly Chronicles - July 2025
Modernizing your data center with Dell and AMD
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Reach Out and Touch Someone: Haptics and Empathic Computing
Diabetes mellitus diagnosis method based random forest with bat algorithm
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
The AUB Centre for AI in Media Proposal.docx
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
madgavkar20181017ppt McKinsey Presentation.pdf
Understanding_Digital_Forensics_Presentation.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Network Security Unit 5.pdf for BCA BBA.

Stream Processing use cases and applications with Apache Apex by Thomas Weise

  • 1. 1
  • 2. Building Streaming Applications with Apache Apex Thomas Weise <[email protected]> @thweise PMC Chair Apache Apex, Architect DataTorrent Big Data Spain, Madrid, Nov 18th 2016
  • 3. Agenda 3 • Application Development Model • Creating Apex Application - Project S tructure • Apex APIs • Configuration Example • Operator APIs • Overview of Operator Library • Frequently used Connectors • S tateful Transformation & Windowing • S calability – Partitioning • End-to-end Exactly Once
  • 4. Application Development Model 4 ▪Stream is a sequence of data tuples ▪Operator takes one or more input streams, performs computations & emits one or more output streams • Each Operator is YOUR custom business logic in java, or built-in operator from our open source library • Operator has many instances that run in parallel and each instance is single-threaded ▪Directed Acyclic Graph (DAG) is made up of operators and streams Directed Acyclic Graph (DAG) Output Stream Tupl e Tupl e er Operator er Operator er Operator er Operator er Operator er Operator
  • 5. Creating Apex Application Project 5 chinmay@chinmay-VirtualBox:~/src$ mvn archetype:generate -DarchetypeGroupId=org.apache.apex - DarchetypeArtifactId=apex-app-archetype -DarchetypeVersion=LATEST -DgroupId=com.example - Dpackage=com.example.myapexapp -DartifactId=myapexapp -Dversion=1.0-SNAPSHOT … … ... Confirm properties configuration: groupId: com.example artifactId: myapexapp version: 1.0-SNAPSHOT package: com.example.myapexapp archetypeVersion: LATEST Y: : Y … … ... [INFO] project created from Archetype in dir: /media/sf_workspace/src/myapexapp [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 13.141 s [INFO] Finished at: 2016-11-15T14:06:56+05:30 [INFO] Final Memory: 18M/216M [INFO] ------------------------------------------------------------------------ chinmay@chinmay-VirtualBox:~/src$ https://www.youtube.com/watch?v=z-eeh-tjQrc
  • 6. Apex Application Project Structure 6 • pom.xml •Defines project structure and dependencies •Application.java •Defines the DAG •RandomNumberGenerator.java •S ample Operator •properties.xml •Contains operator and application properties and attributes •ApplicationTest.java •S ample test to test application in local mode
  • 7. APIs: Compositional (Low level) 7 Input Parser Counter Output CountsWordsLines Kafka Database Filter Filtered
  • 8. Apex APIs: Declarative (High Level) 8 File Input Parser Word Counter Console Output CountsWordsLines Folder StdOut StreamFactory.fromFolder("/tmp") .flatMap(input -> Arrays.asList(input.split(" ")), name("Words")) .window(new WindowOption.GlobalWindow(), new TriggerOption().accumulatingFiredPanes().withEarlyFiringsAtEvery(1)) .countByKey(input -> new Tuple.PlainTuple<>(new KeyValPair<>(input, 1L)), name("countByKey")) .map(input -> input.getValue(), name("Counts")) .print(name("Console")) .populateDag(dag);
  • 9. APIs: S QL 9 Kafka Input CSV Parser Filter CSV Formattter FilteredWordsLines Kafka File Project Projected Line Writer Formatted SQLExecEnvironment.getEnvironment() .registerTable("ORDERS", new KafkaEndpoint(conf.get("broker"), conf.get("topic"), new CSVMessageFormat(conf.get("schemaInDef")))) .registerTable("SALES", new FileEndpoint(conf.get("destFolder"), conf.get("destFileName"), new CSVMessageFormat(conf.get("schemaOutDef")))) .registerFunction("APEXCONCAT", this.getClass(), "apex_concat_str") .executeSQL(dag, "INSERT INTO SALES " + "SELECT STREAM ROWTIME, FLOOR(ROWTIME TO DAY), APEXCONCAT('OILPAINT', SUBSTRING(PRODUCT, 6, 7) " + "FROM ORDERS WHERE ID > 3 AND PRODUCT LIKE 'paint%'");
  • 10. APIs: Beam 10 • Apex Runner for Apache Beam is now available!! •Build once run-anywhere model •Beam S treaming applications can be run on apex runner: public static void main(String[] args) { Options options = PipelineOptionsFactory.fromArgs(args).withValidation().as(Options.class); // Run with Apex runner options.setRunner(ApexRunner.class); Pipeline p = Pipeline.create(options); p.apply("ReadLines", TextIO.Read.from(options.getInput())) .apply(new CountWords()) .apply(MapElements.via(new FormatAsTextFn())) .apply("WriteCounts", TextIO.Write.to(options.getOutput())); .run().waitUntilFinish(); }
  • 11. APIs: S AMOA 11 •Build once run-anywhere model for online machine learning algorithms •Any machine learning algorithm present in S AMOA can be run directly on Apex. •Uses Apex Iteration S upport •Following example does classification of input data from HDFS using VHT algorithm on Apex: ᵒ bin/samoa apex ../SAMOA-Apex-0.4.0-incubating-SNAPSHOT.jar "PrequentialEvaluation -d /tmp/dump.csv -l (classifiers.trees.VerticalHoeffdingTree -p 1) -s (org.apache.samoa.streams.ArffFileStream -s HDFSFileStreamSource -f /tmp/user/input/covtypeNorm.arff)"
  • 12. Configuration (properties.xml) 12 Input Parser Counter Output CountsWordsLines Kafka Database Filter Filtered
  • 13. Streaming Window Processing Time Window 13 •Finite time sliced windows based on processing (event arrival) time •Used for bookkeeping of streaming application •Derived Windows are: Checkpoint Windows, Committed Windows
  • 14. Operator APIs 14 Next streaming window Next streaming window Input Adapters - S tarting of the pipeline. Interacts with external system to generate stream Generic Operators - Processing part of pipeline Output Adapters - Last operator in pipeline. Interacts with external system to finalize the processed stream OutputPort::emit()
  • 15. Operator Library 15 RDBMS • JDBC • MySQL • Oracle • MemSQL NoSQL • Cassandra, HBase • Aerospike, Accumulo • Couchbase/ CouchDB • Redis, MongoDB • Geode Messaging • Kafka • JMS (ActiveMQ etc.) • Kinesis, SQS • Flume, NiFi File Systems • HDFS/ Hive • Local File • S3 Parsers • XML • JSON • CSV • Avro • Parquet Transformations • Filters, Expression, Enrich • Windowing, Aggregation • Join • Dedup Analytics • Dimensional Aggregations (with state management for historical data + query) Protocols • HTTP • FTP • WebSocket • MQTT • SMTP Other • Elastic Search • Script (JavaScript, Python, R) • Solr • Twitter
  • 16. Frequently used Connectors Kafka Input 16 KafkaSinglePortInputOperator KafkaSinglePortByteArrayInputOperator Library malhar-contrib malhar-kafka Kafka Consumer 0.8 0.9 Emit Type byte[] byte[] Fault-Tolerance At Least Once, Exactly Once At Least Once, Exactly Once Scalability Static and Dynamic (with Kafka metadata) Static and Dynamic (with Kafka metadata) Multi-Cluster/Topic Yes Yes Idempotent Yes Yes Partition Strategy 1:1, 1:M 1:1, 1:M
  • 17. Frequently used Connectors Kafka Output 17 KafkaSinglePortOutputOperator KafkaSinglePortExactlyOnceOutputOperator Library malhar-contrib malhar-kafka Kafka Producer 0.8 0.9 Fault-Tolerance At Least Once At Least Once, Exactly Once Scalability Static and Dynamic (with Kafka metadata) Static and Dynamic, Automatic Partitioning based on Kafka metadata Multi-Cluster/Topic Yes Yes Idempotent Yes Yes Partition Strategy 1:1, 1:M 1:1, 1:M
  • 18. Frequently used Connectors File Input 18 •AbstractFileInputOperator •Used to read a file from source and emit the content of the file to downstream operator •Operator is idempotent •S upports Partitioning •Few Concrete Impl •FileLineInputOperator •AvroFileInputOperator •ParquetFilePOJ OReader •https://www.datatorrent.com/blog/f ault-tolerant-file-processing/
  • 19. Frequently used Connectors File Output 19 •AbstractFileOutputOperator •Writes data to a file •S upports Partitions •Exactly-once results •Upstream operators should be idempotent •Few Concrete Impl •S tringFileOutputOperator •https://www.datatorrent.com/blog/f ault-tolerant-file-processing/
  • 20. Windowing Support 20 • Event-time Windows • Computation based on event-time present in the tuple • Types of event-time windows: ᵒ Global : S ingle event-time window throughout the lifecycle of application ᵒ Timed : Tuple is assigned to single, non-overlapping, fixed width windows immediately followed by next window ᵒ Sliding Time : Tuple is can be assigned to multiple, overlapping fixed width windows. ᵒ Session : Tuple is assigned to single, variable width windows with predefined min gap
  • 21. Stateful Windowed Processing 21 • WindowedOperator (org.apache.apex:malhar-library) • Used to process data based on Event time as contrary to ingression time • S upports windowing semantics of Apache Beam model • Features: ᵒ Watermarks ᵒ Allowed Lateness ᵒ Accumulation ᵒ Accumulation Modes: Accumulating, Discarding, Accumulating & Retracting ᵒ Triggers • S torage ᵒ In memory (checkpointed) ᵒ Managed S tate
  • 22. Stateful Windowed Processing Compositional API 22 @Override public void populateDAG(DAG dag, Configuration configuration) { WordGenerator inputOperator = new WordGenerator(); KeyedWindowedOperatorImpl windowedOperator = new KeyedWindowedOperatorImpl(); Accumulation<Long, MutableLong, Long> sum = new SumAccumulation(); windowedOperator.setAccumulation(sum); windowedOperator.setDataStorage(new InMemoryWindowedKeyedStorage<String, MutableLong>()); windowedOperator.setRetractionStorage(new InMemoryWindowedKeyedStorage<String, Long>()); windowedOperator.setWindowStateStorage(new InMemoryWindowedStorage<WindowState>()); windowedOperator.setWindowOption(new WindowOption.TimeWindows(Duration.standardMinutes(1))); windowedOperator.setTriggerOption(TriggerOption.AtWatermark() .withEarlyFiringsAtEvery(Duration.millis(1000)) .accumulatingAndRetractingFiredPanes()); windowedOperator.setAllowedLateness(Duration.millis(14000)); ConsoleOutputOperator outputOperator = new ConsoleOutputOperator(); dag.addOperator("inputOperator", inputOperator); dag.addOperator("windowedOperator", windowedOperator); dag.addOperator("outputOperator", outputOperator); dag.addStream("input_windowed", inputOperator.output, windowedOperator.input); dag.addStream("windowed_output", windowedOperator.output, outputOperator.input); }
  • 23. Stateful Windowed Processing Declarative API 23 StreamFactory.fromFolder("/tmp") .flatMap(input -> Arrays.asList(input.split(" ")), name("ExtractWords")) .map(input -> new TimestampedTuple<>(System.currentTimeMillis(), input), name("AddTimestampFn")) .window(new TimeWindows(Duration.standardMinutes(WINDOW_SIZE)), new TriggerOption().accumulatingFiredPanes().withEarlyFiringsAtEvery(1)) .countByKey(input -> new TimestampedTuple<>(input.getTimestamp(), new KeyValPair<>(input.getValue(), 1L))), name("countWords")) .map(new FormatAsTableRowFn(), name("FormatAsTableRowFn")) .print(name("console")) .populateDag(dag);
  • 24. •Goal: low latency and high throughput •Replicate processing logic, partition data/stream •Configurable (Application.java or properties.xml) •StreamCodec •Controls distribution of tuples to downstream partitions •Unifier (combine results of partitions) •Passthrough unifier added by platform to merge results from upstream partitions •Can also be customized •Type of partitions •Static partitions - S tatically partition at launch time •Dynamic partitions - Partitions changing at runtime based on latency and/or throughput •Parallel partitions - Upstream and downstream operators using same partition scheme S calability - Partitioning 24
  • 25. Scalability - Partitioning (contd.) 25 0 1 2 3 Logical DAG 0 1 2 U Physical DAG 1 1 2 2 3 Parallel Partitions M x N Partitions OR Shuffle <configuration> <property> <name>dt.operator.1.attr.PARTITIONER</name> <value>com.datatorrent.common.partitioner.StatelessPartitioner:3</value> </property> <property> <name>dt.operator.2.port.inputPortName.attr.PARTITION_PARALLEL</name> <value>true</value> </property> </configuration>
  • 26. End-to-End Exactly-Once 26 Input Counter Store Aggregate CountsWords Kafka Database ● Input ○ Uses com.datatorrent.contrib.kafka.KafkaSinglePortStringInputOperator ○ Emits words as a stream ○ Operator is idempotent ● Counter ○ com.datatorrent.lib.algo.UniqueCounter ● Store ○ Uses CountStoreOperator ○ Inserts into JDBC ○ Exactly-once results (End-To-End Exactly-once = At-least-once + Idempotency + Consistent State) https://github.com/DataTorrent/examples/blob/master/tutorials/exactly-once https://www.datatorrent.com/blog/end-to-end-exactly-once-with-apache-apex/
  • 27. End-to-End Exactly-Once (contd.) 27 Input Counter Store Aggregate CountsWords Kafka Database public static class CountStoreOperator extends AbstractJdbcTransactionableOutputOperator<KeyValPair<String, Integer>> { public static final String SQL = "MERGE INTO words USING (VALUES ?, ?) I (word, wcount)" + " ON (words.word=I.word)" + " WHEN MATCHED THEN UPDATE SET words.wcount = words.wcount + I.wcount" + " WHEN NOT MATCHED THEN INSERT (word, wcount) VALUES (I.word, I.wcount)"; @Override protected String getUpdateCommand() { return SQL; } @Override protected void setStatementParameters(PreparedStatement statement, KeyValPair<String, Integer> tuple) throws SQLException { statement.setString(1, tuple.getKey()); statement.setInt(2, tuple.getValue()); } }
  • 29. Who is using Apex? 29 • Powered by Apex ᵒ http://apex.apache.org/powered-by-apex.html ᵒ Also using Apex? Let us know to be added: [email protected] or @ApacheApex • Pubmatic ᵒ https://www.youtube.com/watch?v=JSXpgfQFcU8 • GE ᵒ https://www.youtube.com/watch?v=hmaSkXhHNu0 ᵒ http://www.slideshare.net/ApacheApex/ge-iot-predix-time-series-data-ingestion-service- using-apache-apex-hadoop • SilverSpring Networks ᵒ https://www.youtube.com/watch?v=8VORISKeSjI ᵒ http://www.slideshare.net/ApacheApex/iot-big-data-ingestion-and-processing-in-hadoop-by- silver-spring-networks
  • 30. Resources 30 • http://apex.apache.org/ • Learn more - http://apex.apache.org/docs.html • Get involved - http://apex.apache.org/community.html • Download - http://apex.apache.org/downloads.html • Follow @ApacheApex - https://twitter.com/apacheapex • Meetups - https://www.meetup.com/topics/apache-apex/ • Examples - https://github.com/DataTorrent/examples • Slideshare - http://www.slideshare.net/ApacheApex/presentations • https://www.youtube.com/results?search_query=apache+apex • Free Enterprise License for S tartups - https://www.datatorrent.com/product/startup-accelerator/