SlideShare a Scribd company logo
1 of 28
Stream on File 
Terence Yim
What is Stream? 
● Primary means for data collection in Reactor 
o REST API to send individual event 
● Consumable by Reactor Programs 
o Flow 
o MapReduce
Why on File? 
● Data eventually persisted to file 
o LevelDB -> local file 
o HBase -> HDFS 
● Fewer intermediate layer == Performance ++
10K Architecture 
Client 
Client 
Client 
. . . 
. . 
Client 
Writer 
Writer 
R 
O 
U 
T 
E 
R 
Files 
Files 
Flowlet 
HTTP 
POST 
Write 
Write 
Read 
Read 
HBase 
States
Directory Structure 
/[stream_name] 
/[generation] 
/[partition_start_ts].[partition_duration] 
/[name_prefix].[sequence].("dat"|"idx")
Directory Structure 
/who 
Stream name = who 
/who/00001 
Generation = 1 
/who/00001/1401408000.86400 
Partition start time = 2014-05-30 GMT 
Partition duration = 1 day
File name 
● Only one writer per file 
o One file prefix per writer instance 
● Don’t use HDFS append 
o Monotonic increase sequence number 
o Open file => find the highest sequence number + 1 
/who/00001/1401408000.86400/file.0.000000.dat 
File prefix = “file.0”. Written by writer instance “0” 
Sequence = 0. First file created by the writer 
Suffix = “dat”, an event file
Event File Format 
"E1" Properties Header 
= Map<String, String> 
Timestamp Block size Event 
Data Block 
Event ... Event 
Timestamp Block size Event 
Data Block 
Event ... Event 
Timestamp Block size Event 
Data Block 
Event ... Event 
... 
Timestamp Tail 
= -1 
● Avro binary serialize “Properties” and “Event” 
● Event schema stored in Properties
Writer Latency 
● Latency 
o Speed perceived by a client 
o Lower the better 
● Guarantee no data loss 
o Minimum latency == File sync time
Writer Throughput 
● Throughput 
o Flow rate 
o Higher the better 
● Buffer events gives better throughput 
o Higher latency? 
● Many concurrent clients 
o More events buffered write
Inside Writer 
Stream Writer 
Netty HTTP 
Handler 
Thread 
Handler 
Thread 
Handler 
Thread 
Handler 
Thread 
File Writer 
HDFS
How to synchronize 
access to File Writer?
Concurrent Stream Writer 
1. Create an event and enqueue it to a Concurrent Queue 
2. Use CAS to try setting an atomic boolean flag to true 
3. If successfully (winner), proceed to run step 4-7, loser go to step 8 
4. Dequeue events and write to file until the queue is empty 
5. Perform a file sync to persist all data being written 
6. Set the state of each events that are written to COMPLETED 
7. Set the atomic boolean back to false 
o Other threads should see states written in step 6 (happened-before) 
8. If the event owned by this thread is NOT COMPLETED, go back to step 2. 
o Call Thread.yield() before go to step 2
Correctness 
● Guarantee no losing events 
o Winner, always drain queue 
 Own event should be in the queue 
o Losers, either 
 Current winner starts drains after enqueue 
 Loop and retry, either 
● Become winner 
● Other winner start drains
Scalability 
● One file per writer process 
o No communication between writers 
● Linearly scalable writes 
o Simply add more writer processes
How to tail stream?
Merge on Consume 
File1 File2 File3 
Multi-file reader 
Merge by event timestamp
Tailing HDFS file 
● HDFS doesn’t support tail 
o EOFException when no more data 
 Writer not yet closed 
o Re-open DFSInputStream on EOFException 
o Read until seeing timestamp = -1
Writer Crashes 
● File writer might crash before closing 
o No tail “-1” timestamp written 
● Writer restart creates new file 
o New sequence or new partition 
● Reader regularly looks for new file 
o No event read 
 Look for file with next sequence 
 Look for new partition based on current time
Filtering 
● ReadFilter 
o By event timestamp 
 Skip one data block 
 TTL 
o By file offset 
 Skip one event 
 RoundRobin consumer
Consumer states 
● Exactly once processing guarantee 
o Resilience to consumer crashes 
● States persisted to HBase/LevelDB 
o Transactional 
o Key 
 {generation, file_name, offset} 
o Value 
 {write_pointer, instance_id, state}
Consumer IO 
● Each dequeue from stream, batch size = N 
o RoundRobin, FIFO (size = 1) 
 ~ (N * size) reads/skips from file readers 
 Batch write of N rows to HBase on commit 
o FIFO (size >= 2) 
 ~ (N * size) reads from file readers 
 O(N * size) checkAndPut to HBase 
 Batch write of N rows to HBase on commit
Consumer State Store 
● Per consumer instance 
o List of file offsets 
 [ {file1, offset1}, {file2, offset2} ] 
o Events before the offset are processed 
 Perceived by this instance 
o Resume from last good offset 
o Persisted periodically in post commit hook 
 Also on close
Consumer Reconfiguration 
● Change flowlet instances 
o Reset consumers’ states 
 Smallest offset for each file 
o Make sure no events left unprocessed
Truncation 
● Atomic increment generation 
o Uses ZooKeeper in distributed mode 
 PropertyStore 
● Supports read-compare-and-set 
o Notify all writers and flowlets 
 Writer close current file writer 
● Reopen with new generation on next write 
 Flowlet suspend and resume 
● Close and reopen stream consumer with new generation
Futures 
● Dynamic scaling of writer instances 
o Through ResourceCoordinator 
● TTL 
o Through PropertyStore
Thank You

More Related Content

What's hot

Fluentd Project Intro at Kubecon 2019 EU
Fluentd Project Intro at Kubecon 2019 EUFluentd Project Intro at Kubecon 2019 EU
Fluentd Project Intro at Kubecon 2019 EUN Masahiro
 
HTTP::Parser::XS - writing a fast & secure XS module
HTTP::Parser::XS - writing a fast & secure XS moduleHTTP::Parser::XS - writing a fast & secure XS module
HTTP::Parser::XS - writing a fast & secure XS moduleKazuho Oku
 
The Patterns of Distributed Logging and Containers
The Patterns of Distributed Logging and ContainersThe Patterns of Distributed Logging and Containers
The Patterns of Distributed Logging and ContainersSATOSHI TAGOMORI
 
Advanced VCL Workshop - Rogier Mulhuijzen and Stephen Basile at Fastly Altitu...
Advanced VCL Workshop - Rogier Mulhuijzen and Stephen Basile at Fastly Altitu...Advanced VCL Workshop - Rogier Mulhuijzen and Stephen Basile at Fastly Altitu...
Advanced VCL Workshop - Rogier Mulhuijzen and Stephen Basile at Fastly Altitu...Fastly
 
Coding for concurrency
Coding for concurrencyCoding for concurrency
Coding for concurrencyTùng Hà Sơn
 
Replication and replica sets
Replication and replica setsReplication and replica sets
Replication and replica setsChris Westin
 
Fluentd and Distributed Logging at Kubecon
Fluentd and Distributed Logging at KubeconFluentd and Distributed Logging at Kubecon
Fluentd and Distributed Logging at KubeconN Masahiro
 
Fluentd v1 and future at techtalk
Fluentd v1 and future at techtalkFluentd v1 and future at techtalk
Fluentd v1 and future at techtalkN Masahiro
 
Concurrency - responsiveness in .NET
Concurrency - responsiveness in .NETConcurrency - responsiveness in .NET
Concurrency - responsiveness in .NETMårten Rånge
 
Flink Forward Berlin 2017: Stefan Richter - A look at Flink's internal data s...
Flink Forward Berlin 2017: Stefan Richter - A look at Flink's internal data s...Flink Forward Berlin 2017: Stefan Richter - A look at Flink's internal data s...
Flink Forward Berlin 2017: Stefan Richter - A look at Flink's internal data s...Flink Forward
 
Building your First gRPC Service
Building your First gRPC ServiceBuilding your First gRPC Service
Building your First gRPC ServiceJessie Barnett
 
CCResourceAsyncLoader
CCResourceAsyncLoaderCCResourceAsyncLoader
CCResourceAsyncLoaderKeisuke Hata
 
Bind How To
Bind How ToBind How To
Bind How Tocntlinux
 
I know what your packet did last hop using packet histories to troubleshoot...
I know what your packet did last hop  using  packet histories to troubleshoot...I know what your packet did last hop  using  packet histories to troubleshoot...
I know what your packet did last hop using packet histories to troubleshoot...承達 蔡
 

What's hot (20)

Fluentd Project Intro at Kubecon 2019 EU
Fluentd Project Intro at Kubecon 2019 EUFluentd Project Intro at Kubecon 2019 EU
Fluentd Project Intro at Kubecon 2019 EU
 
Experimental dtrace
Experimental dtraceExperimental dtrace
Experimental dtrace
 
Kraken mesoscon 2018
Kraken mesoscon 2018Kraken mesoscon 2018
Kraken mesoscon 2018
 
Http request smuggling
Http request smugglingHttp request smuggling
Http request smuggling
 
Linux50commands
Linux50commandsLinux50commands
Linux50commands
 
HTTP::Parser::XS - writing a fast & secure XS module
HTTP::Parser::XS - writing a fast & secure XS moduleHTTP::Parser::XS - writing a fast & secure XS module
HTTP::Parser::XS - writing a fast & secure XS module
 
The Patterns of Distributed Logging and Containers
The Patterns of Distributed Logging and ContainersThe Patterns of Distributed Logging and Containers
The Patterns of Distributed Logging and Containers
 
Advanced VCL Workshop - Rogier Mulhuijzen and Stephen Basile at Fastly Altitu...
Advanced VCL Workshop - Rogier Mulhuijzen and Stephen Basile at Fastly Altitu...Advanced VCL Workshop - Rogier Mulhuijzen and Stephen Basile at Fastly Altitu...
Advanced VCL Workshop - Rogier Mulhuijzen and Stephen Basile at Fastly Altitu...
 
Coding for concurrency
Coding for concurrencyCoding for concurrency
Coding for concurrency
 
Replication and replica sets
Replication and replica setsReplication and replica sets
Replication and replica sets
 
Fluentd and Distributed Logging at Kubecon
Fluentd and Distributed Logging at KubeconFluentd and Distributed Logging at Kubecon
Fluentd and Distributed Logging at Kubecon
 
Fluentd v1 and future at techtalk
Fluentd v1 and future at techtalkFluentd v1 and future at techtalk
Fluentd v1 and future at techtalk
 
Concurrency - responsiveness in .NET
Concurrency - responsiveness in .NETConcurrency - responsiveness in .NET
Concurrency - responsiveness in .NET
 
gRPC
gRPCgRPC
gRPC
 
Flink Forward Berlin 2017: Stefan Richter - A look at Flink's internal data s...
Flink Forward Berlin 2017: Stefan Richter - A look at Flink's internal data s...Flink Forward Berlin 2017: Stefan Richter - A look at Flink's internal data s...
Flink Forward Berlin 2017: Stefan Richter - A look at Flink's internal data s...
 
Building your First gRPC Service
Building your First gRPC ServiceBuilding your First gRPC Service
Building your First gRPC Service
 
CCResourceAsyncLoader
CCResourceAsyncLoaderCCResourceAsyncLoader
CCResourceAsyncLoader
 
Fluentd 101
Fluentd 101Fluentd 101
Fluentd 101
 
Bind How To
Bind How ToBind How To
Bind How To
 
I know what your packet did last hop using packet histories to troubleshoot...
I know what your packet did last hop  using  packet histories to troubleshoot...I know what your packet did last hop  using  packet histories to troubleshoot...
I know what your packet did last hop using packet histories to troubleshoot...
 

Similar to Brown Bag : CDAP (f.k.a Reactor) Streams Deep DiveStream on file brown bag

Ingestion file copy using apex
Ingestion   file copy using apexIngestion   file copy using apex
Ingestion file copy using apexApache Apex
 
Flink Forward SF 2017: Srikanth Satya & Tom Kaitchuck - Pravega: Storage Rei...
Flink Forward SF 2017: Srikanth Satya & Tom Kaitchuck -  Pravega: Storage Rei...Flink Forward SF 2017: Srikanth Satya & Tom Kaitchuck -  Pravega: Storage Rei...
Flink Forward SF 2017: Srikanth Satya & Tom Kaitchuck - Pravega: Storage Rei...Flink Forward
 
Reading and Writing Files
Reading and Writing FilesReading and Writing Files
Reading and Writing Filesprimeteacher32
 
Dfs (Distributed computing)
Dfs (Distributed computing)Dfs (Distributed computing)
Dfs (Distributed computing)Sri Prasanna
 
Building a Unified Logging Layer with Fluentd, Elasticsearch and Kibana
Building a Unified Logging Layer with Fluentd, Elasticsearch and KibanaBuilding a Unified Logging Layer with Fluentd, Elasticsearch and Kibana
Building a Unified Logging Layer with Fluentd, Elasticsearch and KibanaMushfekur Rahman
 
Stream or segment : what is the best way to access your events in Pulsar_Neng
Stream or segment : what is the best way to access your events in Pulsar_NengStream or segment : what is the best way to access your events in Pulsar_Neng
Stream or segment : what is the best way to access your events in Pulsar_NengStreamNative
 
Centralized logging with Flume
Centralized logging with FlumeCentralized logging with Flume
Centralized logging with FlumeRatnakar Pawar
 
Virtual Flink Forward 2020: Build your next-generation stream platform based ...
Virtual Flink Forward 2020: Build your next-generation stream platform based ...Virtual Flink Forward 2020: Build your next-generation stream platform based ...
Virtual Flink Forward 2020: Build your next-generation stream platform based ...Flink Forward
 
GC free coding in @Java presented @Geecon
GC free coding in @Java presented @GeeconGC free coding in @Java presented @Geecon
GC free coding in @Java presented @GeeconPeter Lawrey
 
Linux System Programming - Buffered I/O
Linux System Programming - Buffered I/O Linux System Programming - Buffered I/O
Linux System Programming - Buffered I/O YourHelper1
 
Logging for Production Systems in The Container Era
Logging for Production Systems in The Container EraLogging for Production Systems in The Container Era
Logging for Production Systems in The Container EraSadayuki Furuhashi
 
Fault-Tolerant File Input & Output
Fault-Tolerant File Input & OutputFault-Tolerant File Input & Output
Fault-Tolerant File Input & OutputApache Apex
 
SANS Windows Artifact Analysis 2012
SANS Windows Artifact Analysis 2012SANS Windows Artifact Analysis 2012
SANS Windows Artifact Analysis 2012Rian Yulian
 
Design Web Service API by HungerStation
Design Web Service API by HungerStationDesign Web Service API by HungerStation
Design Web Service API by HungerStationArabNet ME
 
Unified Batch & Stream Processing with Apache Samza
Unified Batch & Stream Processing with Apache SamzaUnified Batch & Stream Processing with Apache Samza
Unified Batch & Stream Processing with Apache SamzaDataWorks Summit
 
M|18 Architectural Overview: MariaDB MaxScale
M|18 Architectural Overview: MariaDB MaxScaleM|18 Architectural Overview: MariaDB MaxScale
M|18 Architectural Overview: MariaDB MaxScaleMariaDB plc
 
Routing trillion events per day @twitter
Routing trillion events per day @twitterRouting trillion events per day @twitter
Routing trillion events per day @twitterlohitvijayarenu
 
February 2017 HUG: Exactly-once end-to-end processing with Apache Apex
February 2017 HUG: Exactly-once end-to-end processing with Apache ApexFebruary 2017 HUG: Exactly-once end-to-end processing with Apache Apex
February 2017 HUG: Exactly-once end-to-end processing with Apache ApexYahoo Developer Network
 

Similar to Brown Bag : CDAP (f.k.a Reactor) Streams Deep DiveStream on file brown bag (20)

Ingestion file copy using apex
Ingestion   file copy using apexIngestion   file copy using apex
Ingestion file copy using apex
 
Flink Forward SF 2017: Srikanth Satya & Tom Kaitchuck - Pravega: Storage Rei...
Flink Forward SF 2017: Srikanth Satya & Tom Kaitchuck -  Pravega: Storage Rei...Flink Forward SF 2017: Srikanth Satya & Tom Kaitchuck -  Pravega: Storage Rei...
Flink Forward SF 2017: Srikanth Satya & Tom Kaitchuck - Pravega: Storage Rei...
 
Reading and Writing Files
Reading and Writing FilesReading and Writing Files
Reading and Writing Files
 
Dfs (Distributed computing)
Dfs (Distributed computing)Dfs (Distributed computing)
Dfs (Distributed computing)
 
Gfs
GfsGfs
Gfs
 
Building a Unified Logging Layer with Fluentd, Elasticsearch and Kibana
Building a Unified Logging Layer with Fluentd, Elasticsearch and KibanaBuilding a Unified Logging Layer with Fluentd, Elasticsearch and Kibana
Building a Unified Logging Layer with Fluentd, Elasticsearch and Kibana
 
Stream or segment : what is the best way to access your events in Pulsar_Neng
Stream or segment : what is the best way to access your events in Pulsar_NengStream or segment : what is the best way to access your events in Pulsar_Neng
Stream or segment : what is the best way to access your events in Pulsar_Neng
 
Centralized logging with Flume
Centralized logging with FlumeCentralized logging with Flume
Centralized logging with Flume
 
Virtual Flink Forward 2020: Build your next-generation stream platform based ...
Virtual Flink Forward 2020: Build your next-generation stream platform based ...Virtual Flink Forward 2020: Build your next-generation stream platform based ...
Virtual Flink Forward 2020: Build your next-generation stream platform based ...
 
GC free coding in @Java presented @Geecon
GC free coding in @Java presented @GeeconGC free coding in @Java presented @Geecon
GC free coding in @Java presented @Geecon
 
Linux System Programming - Buffered I/O
Linux System Programming - Buffered I/O Linux System Programming - Buffered I/O
Linux System Programming - Buffered I/O
 
Logging for Production Systems in The Container Era
Logging for Production Systems in The Container EraLogging for Production Systems in The Container Era
Logging for Production Systems in The Container Era
 
Fault-Tolerant File Input & Output
Fault-Tolerant File Input & OutputFault-Tolerant File Input & Output
Fault-Tolerant File Input & Output
 
SANS Windows Artifact Analysis 2012
SANS Windows Artifact Analysis 2012SANS Windows Artifact Analysis 2012
SANS Windows Artifact Analysis 2012
 
Design Web Service API by HungerStation
Design Web Service API by HungerStationDesign Web Service API by HungerStation
Design Web Service API by HungerStation
 
Unified Batch & Stream Processing with Apache Samza
Unified Batch & Stream Processing with Apache SamzaUnified Batch & Stream Processing with Apache Samza
Unified Batch & Stream Processing with Apache Samza
 
The basics of fluentd
The basics of fluentdThe basics of fluentd
The basics of fluentd
 
M|18 Architectural Overview: MariaDB MaxScale
M|18 Architectural Overview: MariaDB MaxScaleM|18 Architectural Overview: MariaDB MaxScale
M|18 Architectural Overview: MariaDB MaxScale
 
Routing trillion events per day @twitter
Routing trillion events per day @twitterRouting trillion events per day @twitter
Routing trillion events per day @twitter
 
February 2017 HUG: Exactly-once end-to-end processing with Apache Apex
February 2017 HUG: Exactly-once end-to-end processing with Apache ApexFebruary 2017 HUG: Exactly-once end-to-end processing with Apache Apex
February 2017 HUG: Exactly-once end-to-end processing with Apache Apex
 

More from Cask Data

Introducing a horizontally scalable, inference-based business Rules Engine fo...
Introducing a horizontally scalable, inference-based business Rules Engine fo...Introducing a horizontally scalable, inference-based business Rules Engine fo...
Introducing a horizontally scalable, inference-based business Rules Engine fo...Cask Data
 
Transaction in HBase, by Andreas Neumann, Cask
Transaction in HBase, by Andreas Neumann, CaskTransaction in HBase, by Andreas Neumann, Cask
Transaction in HBase, by Andreas Neumann, CaskCask Data
 
#BDAM: EDW Optimization with Hadoop and CDAP, by Sagar Kapare from Cask
#BDAM: EDW Optimization with Hadoop and CDAP, by Sagar Kapare from Cask #BDAM: EDW Optimization with Hadoop and CDAP, by Sagar Kapare from Cask
#BDAM: EDW Optimization with Hadoop and CDAP, by Sagar Kapare from Cask Cask Data
 
"Who Moved my Data? - Why tracking changes and sources of data is critical to...
"Who Moved my Data? - Why tracking changes and sources of data is critical to..."Who Moved my Data? - Why tracking changes and sources of data is critical to...
"Who Moved my Data? - Why tracking changes and sources of data is critical to...Cask Data
 
Building Enterprise Grade Applications in Yarn with Apache Twill
Building Enterprise Grade Applications in Yarn with Apache TwillBuilding Enterprise Grade Applications in Yarn with Apache Twill
Building Enterprise Grade Applications in Yarn with Apache TwillCask Data
 
Webinar: What's new in CDAP 3.5?
Webinar: What's new in CDAP 3.5?Webinar: What's new in CDAP 3.5?
Webinar: What's new in CDAP 3.5?Cask Data
 
Transactions Over Apache HBase
Transactions Over Apache HBaseTransactions Over Apache HBase
Transactions Over Apache HBaseCask Data
 
ACID Transactions in Apache Phoenix with Apache Tephra™ (incubating), by Poor...
ACID Transactions in Apache Phoenix with Apache Tephra™ (incubating), by Poor...ACID Transactions in Apache Phoenix with Apache Tephra™ (incubating), by Poor...
ACID Transactions in Apache Phoenix with Apache Tephra™ (incubating), by Poor...Cask Data
 
Logging infrastructure for Microservices using StreamSets Data Collector
Logging infrastructure for Microservices using StreamSets Data CollectorLogging infrastructure for Microservices using StreamSets Data Collector
Logging infrastructure for Microservices using StreamSets Data CollectorCask Data
 
Introducing Athena: 08/19 Big Data Application Meetup, Talk #3
Introducing Athena: 08/19 Big Data Application Meetup, Talk #3 Introducing Athena: 08/19 Big Data Application Meetup, Talk #3
Introducing Athena: 08/19 Big Data Application Meetup, Talk #3 Cask Data
 
NRT Event Processing with Guaranteed Delivery of HTTP Callbacks, HBaseCon 2015
NRT Event Processing with Guaranteed Delivery of HTTP Callbacks, HBaseCon 2015NRT Event Processing with Guaranteed Delivery of HTTP Callbacks, HBaseCon 2015
NRT Event Processing with Guaranteed Delivery of HTTP Callbacks, HBaseCon 2015Cask Data
 
HBase Meetup @ Cask HQ 09/25
HBase Meetup @ Cask HQ 09/25HBase Meetup @ Cask HQ 09/25
HBase Meetup @ Cask HQ 09/25Cask Data
 

More from Cask Data (13)

Introducing a horizontally scalable, inference-based business Rules Engine fo...
Introducing a horizontally scalable, inference-based business Rules Engine fo...Introducing a horizontally scalable, inference-based business Rules Engine fo...
Introducing a horizontally scalable, inference-based business Rules Engine fo...
 
About CDAP
About CDAPAbout CDAP
About CDAP
 
Transaction in HBase, by Andreas Neumann, Cask
Transaction in HBase, by Andreas Neumann, CaskTransaction in HBase, by Andreas Neumann, Cask
Transaction in HBase, by Andreas Neumann, Cask
 
#BDAM: EDW Optimization with Hadoop and CDAP, by Sagar Kapare from Cask
#BDAM: EDW Optimization with Hadoop and CDAP, by Sagar Kapare from Cask #BDAM: EDW Optimization with Hadoop and CDAP, by Sagar Kapare from Cask
#BDAM: EDW Optimization with Hadoop and CDAP, by Sagar Kapare from Cask
 
"Who Moved my Data? - Why tracking changes and sources of data is critical to...
"Who Moved my Data? - Why tracking changes and sources of data is critical to..."Who Moved my Data? - Why tracking changes and sources of data is critical to...
"Who Moved my Data? - Why tracking changes and sources of data is critical to...
 
Building Enterprise Grade Applications in Yarn with Apache Twill
Building Enterprise Grade Applications in Yarn with Apache TwillBuilding Enterprise Grade Applications in Yarn with Apache Twill
Building Enterprise Grade Applications in Yarn with Apache Twill
 
Webinar: What's new in CDAP 3.5?
Webinar: What's new in CDAP 3.5?Webinar: What's new in CDAP 3.5?
Webinar: What's new in CDAP 3.5?
 
Transactions Over Apache HBase
Transactions Over Apache HBaseTransactions Over Apache HBase
Transactions Over Apache HBase
 
ACID Transactions in Apache Phoenix with Apache Tephra™ (incubating), by Poor...
ACID Transactions in Apache Phoenix with Apache Tephra™ (incubating), by Poor...ACID Transactions in Apache Phoenix with Apache Tephra™ (incubating), by Poor...
ACID Transactions in Apache Phoenix with Apache Tephra™ (incubating), by Poor...
 
Logging infrastructure for Microservices using StreamSets Data Collector
Logging infrastructure for Microservices using StreamSets Data CollectorLogging infrastructure for Microservices using StreamSets Data Collector
Logging infrastructure for Microservices using StreamSets Data Collector
 
Introducing Athena: 08/19 Big Data Application Meetup, Talk #3
Introducing Athena: 08/19 Big Data Application Meetup, Talk #3 Introducing Athena: 08/19 Big Data Application Meetup, Talk #3
Introducing Athena: 08/19 Big Data Application Meetup, Talk #3
 
NRT Event Processing with Guaranteed Delivery of HTTP Callbacks, HBaseCon 2015
NRT Event Processing with Guaranteed Delivery of HTTP Callbacks, HBaseCon 2015NRT Event Processing with Guaranteed Delivery of HTTP Callbacks, HBaseCon 2015
NRT Event Processing with Guaranteed Delivery of HTTP Callbacks, HBaseCon 2015
 
HBase Meetup @ Cask HQ 09/25
HBase Meetup @ Cask HQ 09/25HBase Meetup @ Cask HQ 09/25
HBase Meetup @ Cask HQ 09/25
 

Recently uploaded

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Recently uploaded (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

Brown Bag : CDAP (f.k.a Reactor) Streams Deep DiveStream on file brown bag

  • 1. Stream on File Terence Yim
  • 2.
  • 3. What is Stream? ● Primary means for data collection in Reactor o REST API to send individual event ● Consumable by Reactor Programs o Flow o MapReduce
  • 4. Why on File? ● Data eventually persisted to file o LevelDB -> local file o HBase -> HDFS ● Fewer intermediate layer == Performance ++
  • 5. 10K Architecture Client Client Client . . . . . Client Writer Writer R O U T E R Files Files Flowlet HTTP POST Write Write Read Read HBase States
  • 6. Directory Structure /[stream_name] /[generation] /[partition_start_ts].[partition_duration] /[name_prefix].[sequence].("dat"|"idx")
  • 7. Directory Structure /who Stream name = who /who/00001 Generation = 1 /who/00001/1401408000.86400 Partition start time = 2014-05-30 GMT Partition duration = 1 day
  • 8. File name ● Only one writer per file o One file prefix per writer instance ● Don’t use HDFS append o Monotonic increase sequence number o Open file => find the highest sequence number + 1 /who/00001/1401408000.86400/file.0.000000.dat File prefix = “file.0”. Written by writer instance “0” Sequence = 0. First file created by the writer Suffix = “dat”, an event file
  • 9. Event File Format "E1" Properties Header = Map<String, String> Timestamp Block size Event Data Block Event ... Event Timestamp Block size Event Data Block Event ... Event Timestamp Block size Event Data Block Event ... Event ... Timestamp Tail = -1 ● Avro binary serialize “Properties” and “Event” ● Event schema stored in Properties
  • 10. Writer Latency ● Latency o Speed perceived by a client o Lower the better ● Guarantee no data loss o Minimum latency == File sync time
  • 11. Writer Throughput ● Throughput o Flow rate o Higher the better ● Buffer events gives better throughput o Higher latency? ● Many concurrent clients o More events buffered write
  • 12. Inside Writer Stream Writer Netty HTTP Handler Thread Handler Thread Handler Thread Handler Thread File Writer HDFS
  • 13. How to synchronize access to File Writer?
  • 14. Concurrent Stream Writer 1. Create an event and enqueue it to a Concurrent Queue 2. Use CAS to try setting an atomic boolean flag to true 3. If successfully (winner), proceed to run step 4-7, loser go to step 8 4. Dequeue events and write to file until the queue is empty 5. Perform a file sync to persist all data being written 6. Set the state of each events that are written to COMPLETED 7. Set the atomic boolean back to false o Other threads should see states written in step 6 (happened-before) 8. If the event owned by this thread is NOT COMPLETED, go back to step 2. o Call Thread.yield() before go to step 2
  • 15. Correctness ● Guarantee no losing events o Winner, always drain queue  Own event should be in the queue o Losers, either  Current winner starts drains after enqueue  Loop and retry, either ● Become winner ● Other winner start drains
  • 16. Scalability ● One file per writer process o No communication between writers ● Linearly scalable writes o Simply add more writer processes
  • 17. How to tail stream?
  • 18. Merge on Consume File1 File2 File3 Multi-file reader Merge by event timestamp
  • 19. Tailing HDFS file ● HDFS doesn’t support tail o EOFException when no more data  Writer not yet closed o Re-open DFSInputStream on EOFException o Read until seeing timestamp = -1
  • 20. Writer Crashes ● File writer might crash before closing o No tail “-1” timestamp written ● Writer restart creates new file o New sequence or new partition ● Reader regularly looks for new file o No event read  Look for file with next sequence  Look for new partition based on current time
  • 21. Filtering ● ReadFilter o By event timestamp  Skip one data block  TTL o By file offset  Skip one event  RoundRobin consumer
  • 22. Consumer states ● Exactly once processing guarantee o Resilience to consumer crashes ● States persisted to HBase/LevelDB o Transactional o Key  {generation, file_name, offset} o Value  {write_pointer, instance_id, state}
  • 23. Consumer IO ● Each dequeue from stream, batch size = N o RoundRobin, FIFO (size = 1)  ~ (N * size) reads/skips from file readers  Batch write of N rows to HBase on commit o FIFO (size >= 2)  ~ (N * size) reads from file readers  O(N * size) checkAndPut to HBase  Batch write of N rows to HBase on commit
  • 24. Consumer State Store ● Per consumer instance o List of file offsets  [ {file1, offset1}, {file2, offset2} ] o Events before the offset are processed  Perceived by this instance o Resume from last good offset o Persisted periodically in post commit hook  Also on close
  • 25. Consumer Reconfiguration ● Change flowlet instances o Reset consumers’ states  Smallest offset for each file o Make sure no events left unprocessed
  • 26. Truncation ● Atomic increment generation o Uses ZooKeeper in distributed mode  PropertyStore ● Supports read-compare-and-set o Notify all writers and flowlets  Writer close current file writer ● Reopen with new generation on next write  Flowlet suspend and resume ● Close and reopen stream consumer with new generation
  • 27. Futures ● Dynamic scaling of writer instances o Through ResourceCoordinator ● TTL o Through PropertyStore