SlideShare une entreprise Scribd logo
1  sur  31
Télécharger pour lire hors ligne
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
OSGi Community Event 2016
co-located at
EclipseCon Europe 2016
Scalable Event Processing
Pushing the limits with Push Streams!
Tim Ward
http://www.paremus.com
info@paremus.com
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
•Chief Technology Officer at Paremus

•8 years developing OSGi specifications

•Chair of the OSGi IoT Expert Group

•Interested in Asynchronous Distributed Systems

•Author of Manning’s Enterprise OSGi in Action

•http://www.manning.com/cummins
Who is Tim Ward?
@TimothyWard
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Working with Data
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Iteration in Java
We’ve probably all written this code:

for(int i =0; i < list.size(); i ++) {
MyData data = list.get(i);
…
} and this code:

Iterator<MyData> it = list.iterator();
while(it.hasNext()) {
MyData data = it.next();
…
}and this code:

for(MyData data : list) {
…
}
Data is everywhere, and Java’s collections make processing data easy
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Problems with iteration
Whilst Java iteration is easy, it’s still easy to make mistakes:
This is bad for Linked Lists!

for(int i =0; i < list.size(); i ++) {
MyData data = list.get(i);
…
}
“External” iteration also pushes control logic into your code!

Parallelising the processing is a huge task

Java 8 updated the Collections API to support “internal” iteration

Powerful functional concepts were added via the Stream API
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Iteration in Java 8
Streaming collections is very simple:

list.stream().forEach(data -> …);
Internal iteration separates the “what” from the “how” in your code

Parallel processing can occur implicitly if the list supports it

Functional pipelines allow for easy processing

list.stream()
.map(MyData::getAge)
.filter(i -> i < 15)
.count();
intermediate operations

terminal operation
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Properties of Java 8 Streams
Java 8 Streams have a number of useful properties:
They are lazy

Streams only process data on-demand

This is triggered by a “terminal operation”
They can “short circuit” 

Some operations don’t need to see the whole stream

findFirst() and findAny() can return if an element is found
Importantly the Stream is “pulling” the data from the data structure
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Streams of data
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Streams - the overloaded concept
Before Java 8, a “stream” of data was a java.io.InputStream

Whilst you probably didn’t think of it that way, you still iterated

int read;
while((read = is.read()) != -1) {
byte data = (byte) read;
…
}
The big difference with an InputStream is that it may block

A thread may get “stuck” waiting for user input, or a slow network

Java NIO has non-blocking input, but is much harder to use
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Streams - the overloaded concept (2)
An InputStream behaves like an ordered Collection of bytes

Using a Java 8 Stream over these bytes could make sense

is.forEach(data -> …)
But the InputStream may block the thread indefinitely 

If the input is asynchronous then resources are wasted by waiting

A slow function may not process data as fast as it arrives

Rapid bursts of data may overload the consumer

All of this is independent of the data, be it bytes or Objects

Java 8 Streams aren’t able to cope with asynchronous data
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Push-based asynchronous streams
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Push-based Streams
Push-based-streams are fundamentally different from pull-based streams

The processing function is called when data arrives, not when the
previous entry has been processed

Asynchronous operation allows for high throughput and parallelisation

Terminal operations must be asynchronous and non-blocking

The Promise is the primitive of Asynchronous Programming

Rather than returning values a push-based stream returns a Promise

A Promise represents a delayed result that will be “resolved” later

OSGi Promises are a good option here
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Mapping Java 8 Streams to a push model
The Java 8 Stream has a rich and powerful API

Making it push-based is easier than you might think!

Change the return type of the terminal operations
Pull Push
long count() Promise<Long> count()
boolean anyMatch() Promise<Boolean> anyMatch()
boolean allMatch() Promise<Boolean> allMatch()
Optional<T> min() Promise<Optional<T>> min()
Optional<T> max() Promise<Optional<T>> max()
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Problems with this approach
This model actually works very well, but there are some problems

How do we know when an asynchronous stream has finished?

A pull-based model can simply indicate that there is no more data

Pull-based iteration offers a natural “brake” by processing elements in turn

Push-based systems can be overwhelmed by “Event Storms”

Even a single client thread can be problematic if it is too eager!

How do we cope with this?
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Using Events to communicate
Pushing the raw data into the consumer is simple, but insufficient

Consumers need a pushed event to indicate the end of a stream

Events should also be able to propagate failures

An Event is therefore a simple wrapper for data or metadata

public static enum EventType { DATA, ERROR, CLOSE };
public final class PushEvent<T> {
public EventType getType() { … }
public T getData() { … }
public Exception getFailure{ … }
}
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Learning lessons from Network Engineers
Push-based streams share a lot of concepts with computer networks

Asynchronous delivery

Producer and Consumer may run at different rates

TCP solves the “event storm” problem with back-pressure

The producer gets faster, but backs off if the consumer’s ACK rate drops

Our push-streams need to feed back to the data producer

The simplest way to do this is simply to say “don’t call me for a while”
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
The AsyncConsumer
A simple functional interface for consuming data:

public interface PushEventConsumer {
long accept(PushEvent<T> event);
}
End of Stream events can be detected and back-pressure returned

If positive then the producer should wait at least that long

If zero then continue as soon as possible

If negative then close the stream
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Buffers, Windows and Circuit Breakers
An event consumer may receive events on many threads

The event consumer may also be slow to process data

Buffering allows a thread switch, freeing up the producer’s thread

It also allows the consumer to scale up or down the number of workers

Incoming data is queued until it can be processed

The buffer can return back-pressure based on how full it is

Buffering is a built-in feature of the push-based stream

Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Buffering events
1723113119
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Buffering events (2)
What happens when the buffer gets full?

We could use an infinite buffer, but memory isn’t infinite…

Blocking is a possibility, but not very asynchronous!

A good option is simply to close the stream

This is called a “circuit breaker” - it trips if the consumer falls too far behind

This model protects against event storms
1723113119375?
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Windowing events
An event consumer may wish to receive batches of events to process

The consumer can then forward an aggregate event

Batches can be defined using an absolute number, or a time window

The underlying behaviour is similar to buffering
1723113119
17231131195 37Number
Time
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Producing data events
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Producing events
So far we’ve focussed on consuming and processing events

This is not very useful unless we can produce events!

Event producers are connected to consumers using the open() method

public interface PushEventSource<T> {
Closeable open(PushEventConsumer<? super T> event);
}
The returned Closeable can be used to “end” the stream

This is useful when the data stream is infinite!
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Helpful behaviours
Event Producers have to cope with multiple registrations

They also have to handle back-pressure from the consumer

Sometimes the producer has no choice about waiting!

Writing a producer should not be hard, so we provide help

The SimplePushEventSource provides buffered publishing

The Buffer/Circuit breaker allows the producer to “ignore” back pressure

A connect Promise allows event delivery to be lazily started
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Playing with streams
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Playing with push streams
We need an asynchronous source of events

The UK rail network has an open data API!

Events are batched (for performance) and delivered using STOMP

Events are JSON objects and so can easily be processed!

Let’s have a play!
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
•For more about OSGi...

• Specifications at http://www.osgi.org

• Enterprise OSGi in Action

• http://www.manning.com/cummins

•For more about the Push Streams

• http://github.com/osgi/design

•See the IoT Competition at 1745 today

Questions?
Thanks!
http://www.paremus.com
info@paremus.com
http://www.manning.com/cummins
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Addendum
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
Demo Gremlins
This morning I was testing my demo

I couldn’t connect to the Network Rail Feed

They had Deactivated my account!

No demo = Unhappy Audience :( 

But OSGi is amazing technology from the future!

I built a new module using MQTT to consume events from the OSGi Train

1 hour later - Working Demo. No other code had to change!

Network Rail reactivated my account 10 minutes later…
Copyright © 2005 - 2016 Paremus Ltd.
May not be reproduced by any means without express permission. All rights reserved.
OSGi Community Event Nov 2016
www.paremus.com @Paremus info@paremus.com

Contenu connexe

Plus de mfrancis

Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...mfrancis
 
OSGi CDI Integration Specification - Ray Augé (Liferay)
OSGi CDI Integration Specification - Ray Augé (Liferay)OSGi CDI Integration Specification - Ray Augé (Liferay)
OSGi CDI Integration Specification - Ray Augé (Liferay)mfrancis
 
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...mfrancis
 
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...mfrancis
 
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...mfrancis
 
Popular patterns revisited on OSGi - Christian Schneider (Adobe)
Popular patterns revisited on OSGi - Christian Schneider (Adobe)Popular patterns revisited on OSGi - Christian Schneider (Adobe)
Popular patterns revisited on OSGi - Christian Schneider (Adobe)mfrancis
 
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)mfrancis
 
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)mfrancis
 
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...mfrancis
 
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)mfrancis
 
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...mfrancis
 
How to connect your OSGi application - Dirk Fauth (Bosch)
How to connect your OSGi application - Dirk Fauth (Bosch)How to connect your OSGi application - Dirk Fauth (Bosch)
How to connect your OSGi application - Dirk Fauth (Bosch)mfrancis
 
Visualization of OSGi based Software Architectures in Virtual Reality - Lisa ...
Visualization of OSGi based Software Architectures in Virtual Reality - Lisa ...Visualization of OSGi based Software Architectures in Virtual Reality - Lisa ...
Visualization of OSGi based Software Architectures in Virtual Reality - Lisa ...mfrancis
 
Turtles all the Way Up – From OSGi bundles to Fog Computing - Tim Ward (Paremus)
Turtles all the Way Up – From OSGi bundles to Fog Computing - Tim Ward (Paremus)Turtles all the Way Up – From OSGi bundles to Fog Computing - Tim Ward (Paremus)
Turtles all the Way Up – From OSGi bundles to Fog Computing - Tim Ward (Paremus)mfrancis
 
OSGi in Action - How we use OSGi to build Open Liberty - Alasdair Nottingham ...
OSGi in Action - How we use OSGi to build Open Liberty - Alasdair Nottingham ...OSGi in Action - How we use OSGi to build Open Liberty - Alasdair Nottingham ...
OSGi in Action - How we use OSGi to build Open Liberty - Alasdair Nottingham ...mfrancis
 
Software AG Application Modularity - OSGi and JPMS (Jigsaw)
Software AG Application Modularity - OSGi and JPMS (Jigsaw)Software AG Application Modularity - OSGi and JPMS (Jigsaw)
Software AG Application Modularity - OSGi and JPMS (Jigsaw)mfrancis
 
Journey from Monolith to a Modularized Application - Approach and Key Learnin...
Journey from Monolith to a Modularized Application - Approach and Key Learnin...Journey from Monolith to a Modularized Application - Approach and Key Learnin...
Journey from Monolith to a Modularized Application - Approach and Key Learnin...mfrancis
 
Eclipse microprofile config and OSGi config admin - E Jiang
Eclipse microprofile config and OSGi config admin - E JiangEclipse microprofile config and OSGi config admin - E Jiang
Eclipse microprofile config and OSGi config admin - E Jiangmfrancis
 
Smart IoTt on OSGi with Apache Openwhisk - C Ziegeler & D Bosschaert
Smart IoTt on OSGi with Apache Openwhisk - C Ziegeler & D BosschaertSmart IoTt on OSGi with Apache Openwhisk - C Ziegeler & D Bosschaert
Smart IoTt on OSGi with Apache Openwhisk - C Ziegeler & D Bosschaertmfrancis
 
When whiteboards play together. JAX-RS and servlets the OSGi way - M Hoffmann...
When whiteboards play together. JAX-RS and servlets the OSGi way - M Hoffmann...When whiteboards play together. JAX-RS and servlets the OSGi way - M Hoffmann...
When whiteboards play together. JAX-RS and servlets the OSGi way - M Hoffmann...mfrancis
 

Plus de mfrancis (20)

Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
 
OSGi CDI Integration Specification - Ray Augé (Liferay)
OSGi CDI Integration Specification - Ray Augé (Liferay)OSGi CDI Integration Specification - Ray Augé (Liferay)
OSGi CDI Integration Specification - Ray Augé (Liferay)
 
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
 
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
 
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
 
Popular patterns revisited on OSGi - Christian Schneider (Adobe)
Popular patterns revisited on OSGi - Christian Schneider (Adobe)Popular patterns revisited on OSGi - Christian Schneider (Adobe)
Popular patterns revisited on OSGi - Christian Schneider (Adobe)
 
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
 
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
 
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
 
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
 
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
 
How to connect your OSGi application - Dirk Fauth (Bosch)
How to connect your OSGi application - Dirk Fauth (Bosch)How to connect your OSGi application - Dirk Fauth (Bosch)
How to connect your OSGi application - Dirk Fauth (Bosch)
 
Visualization of OSGi based Software Architectures in Virtual Reality - Lisa ...
Visualization of OSGi based Software Architectures in Virtual Reality - Lisa ...Visualization of OSGi based Software Architectures in Virtual Reality - Lisa ...
Visualization of OSGi based Software Architectures in Virtual Reality - Lisa ...
 
Turtles all the Way Up – From OSGi bundles to Fog Computing - Tim Ward (Paremus)
Turtles all the Way Up – From OSGi bundles to Fog Computing - Tim Ward (Paremus)Turtles all the Way Up – From OSGi bundles to Fog Computing - Tim Ward (Paremus)
Turtles all the Way Up – From OSGi bundles to Fog Computing - Tim Ward (Paremus)
 
OSGi in Action - How we use OSGi to build Open Liberty - Alasdair Nottingham ...
OSGi in Action - How we use OSGi to build Open Liberty - Alasdair Nottingham ...OSGi in Action - How we use OSGi to build Open Liberty - Alasdair Nottingham ...
OSGi in Action - How we use OSGi to build Open Liberty - Alasdair Nottingham ...
 
Software AG Application Modularity - OSGi and JPMS (Jigsaw)
Software AG Application Modularity - OSGi and JPMS (Jigsaw)Software AG Application Modularity - OSGi and JPMS (Jigsaw)
Software AG Application Modularity - OSGi and JPMS (Jigsaw)
 
Journey from Monolith to a Modularized Application - Approach and Key Learnin...
Journey from Monolith to a Modularized Application - Approach and Key Learnin...Journey from Monolith to a Modularized Application - Approach and Key Learnin...
Journey from Monolith to a Modularized Application - Approach and Key Learnin...
 
Eclipse microprofile config and OSGi config admin - E Jiang
Eclipse microprofile config and OSGi config admin - E JiangEclipse microprofile config and OSGi config admin - E Jiang
Eclipse microprofile config and OSGi config admin - E Jiang
 
Smart IoTt on OSGi with Apache Openwhisk - C Ziegeler & D Bosschaert
Smart IoTt on OSGi with Apache Openwhisk - C Ziegeler & D BosschaertSmart IoTt on OSGi with Apache Openwhisk - C Ziegeler & D Bosschaert
Smart IoTt on OSGi with Apache Openwhisk - C Ziegeler & D Bosschaert
 
When whiteboards play together. JAX-RS and servlets the OSGi way - M Hoffmann...
When whiteboards play together. JAX-RS and servlets the OSGi way - M Hoffmann...When whiteboards play together. JAX-RS and servlets the OSGi way - M Hoffmann...
When whiteboards play together. JAX-RS and servlets the OSGi way - M Hoffmann...
 

Dernier

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 

Dernier (20)

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 

Scalable Event Processing – Pushing the limits with Push Streams! - Tim Ward

  • 1. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 OSGi Community Event 2016 co-located at EclipseCon Europe 2016 Scalable Event Processing Pushing the limits with Push Streams! Tim Ward http://www.paremus.com info@paremus.com
  • 2. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 •Chief Technology Officer at Paremus •8 years developing OSGi specifications •Chair of the OSGi IoT Expert Group •Interested in Asynchronous Distributed Systems •Author of Manning’s Enterprise OSGi in Action •http://www.manning.com/cummins Who is Tim Ward? @TimothyWard
  • 3. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Working with Data
  • 4. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Iteration in Java We’ve probably all written this code: for(int i =0; i < list.size(); i ++) { MyData data = list.get(i); … } and this code: Iterator<MyData> it = list.iterator(); while(it.hasNext()) { MyData data = it.next(); … }and this code: for(MyData data : list) { … } Data is everywhere, and Java’s collections make processing data easy
  • 5. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Problems with iteration Whilst Java iteration is easy, it’s still easy to make mistakes: This is bad for Linked Lists! for(int i =0; i < list.size(); i ++) { MyData data = list.get(i); … } “External” iteration also pushes control logic into your code! Parallelising the processing is a huge task Java 8 updated the Collections API to support “internal” iteration Powerful functional concepts were added via the Stream API
  • 6. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Iteration in Java 8 Streaming collections is very simple: list.stream().forEach(data -> …); Internal iteration separates the “what” from the “how” in your code Parallel processing can occur implicitly if the list supports it Functional pipelines allow for easy processing list.stream() .map(MyData::getAge) .filter(i -> i < 15) .count(); intermediate operations terminal operation
  • 7. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Properties of Java 8 Streams Java 8 Streams have a number of useful properties: They are lazy Streams only process data on-demand This is triggered by a “terminal operation” They can “short circuit” Some operations don’t need to see the whole stream findFirst() and findAny() can return if an element is found Importantly the Stream is “pulling” the data from the data structure
  • 8. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Streams of data
  • 9. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Streams - the overloaded concept Before Java 8, a “stream” of data was a java.io.InputStream Whilst you probably didn’t think of it that way, you still iterated int read; while((read = is.read()) != -1) { byte data = (byte) read; … } The big difference with an InputStream is that it may block A thread may get “stuck” waiting for user input, or a slow network Java NIO has non-blocking input, but is much harder to use
  • 10. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Streams - the overloaded concept (2) An InputStream behaves like an ordered Collection of bytes Using a Java 8 Stream over these bytes could make sense is.forEach(data -> …) But the InputStream may block the thread indefinitely If the input is asynchronous then resources are wasted by waiting A slow function may not process data as fast as it arrives Rapid bursts of data may overload the consumer All of this is independent of the data, be it bytes or Objects Java 8 Streams aren’t able to cope with asynchronous data
  • 11. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Push-based asynchronous streams
  • 12. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Push-based Streams Push-based-streams are fundamentally different from pull-based streams The processing function is called when data arrives, not when the previous entry has been processed Asynchronous operation allows for high throughput and parallelisation Terminal operations must be asynchronous and non-blocking The Promise is the primitive of Asynchronous Programming Rather than returning values a push-based stream returns a Promise A Promise represents a delayed result that will be “resolved” later OSGi Promises are a good option here
  • 13. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Mapping Java 8 Streams to a push model The Java 8 Stream has a rich and powerful API Making it push-based is easier than you might think! Change the return type of the terminal operations Pull Push long count() Promise<Long> count() boolean anyMatch() Promise<Boolean> anyMatch() boolean allMatch() Promise<Boolean> allMatch() Optional<T> min() Promise<Optional<T>> min() Optional<T> max() Promise<Optional<T>> max()
  • 14. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Problems with this approach This model actually works very well, but there are some problems How do we know when an asynchronous stream has finished? A pull-based model can simply indicate that there is no more data Pull-based iteration offers a natural “brake” by processing elements in turn Push-based systems can be overwhelmed by “Event Storms” Even a single client thread can be problematic if it is too eager! How do we cope with this?
  • 15. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Using Events to communicate Pushing the raw data into the consumer is simple, but insufficient Consumers need a pushed event to indicate the end of a stream Events should also be able to propagate failures An Event is therefore a simple wrapper for data or metadata public static enum EventType { DATA, ERROR, CLOSE }; public final class PushEvent<T> { public EventType getType() { … } public T getData() { … } public Exception getFailure{ … } }
  • 16. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Learning lessons from Network Engineers Push-based streams share a lot of concepts with computer networks Asynchronous delivery Producer and Consumer may run at different rates TCP solves the “event storm” problem with back-pressure The producer gets faster, but backs off if the consumer’s ACK rate drops Our push-streams need to feed back to the data producer The simplest way to do this is simply to say “don’t call me for a while”
  • 17. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 The AsyncConsumer A simple functional interface for consuming data: public interface PushEventConsumer { long accept(PushEvent<T> event); } End of Stream events can be detected and back-pressure returned If positive then the producer should wait at least that long If zero then continue as soon as possible If negative then close the stream
  • 18. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Buffers, Windows and Circuit Breakers
  • 19. An event consumer may receive events on many threads The event consumer may also be slow to process data Buffering allows a thread switch, freeing up the producer’s thread It also allows the consumer to scale up or down the number of workers Incoming data is queued until it can be processed The buffer can return back-pressure based on how full it is Buffering is a built-in feature of the push-based stream Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Buffering events 1723113119
  • 20. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Buffering events (2) What happens when the buffer gets full? We could use an infinite buffer, but memory isn’t infinite… Blocking is a possibility, but not very asynchronous! A good option is simply to close the stream This is called a “circuit breaker” - it trips if the consumer falls too far behind This model protects against event storms 1723113119375?
  • 21. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Windowing events An event consumer may wish to receive batches of events to process The consumer can then forward an aggregate event Batches can be defined using an absolute number, or a time window The underlying behaviour is similar to buffering 1723113119 17231131195 37Number Time
  • 22. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Producing data events
  • 23. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Producing events So far we’ve focussed on consuming and processing events This is not very useful unless we can produce events! Event producers are connected to consumers using the open() method public interface PushEventSource<T> { Closeable open(PushEventConsumer<? super T> event); } The returned Closeable can be used to “end” the stream This is useful when the data stream is infinite!
  • 24. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Helpful behaviours Event Producers have to cope with multiple registrations They also have to handle back-pressure from the consumer Sometimes the producer has no choice about waiting! Writing a producer should not be hard, so we provide help The SimplePushEventSource provides buffered publishing The Buffer/Circuit breaker allows the producer to “ignore” back pressure A connect Promise allows event delivery to be lazily started
  • 25. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Playing with streams
  • 26. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Playing with push streams We need an asynchronous source of events The UK rail network has an open data API! Events are batched (for performance) and delivered using STOMP Events are JSON objects and so can easily be processed! Let’s have a play!
  • 27. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016
  • 28. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 •For more about OSGi... • Specifications at http://www.osgi.org • Enterprise OSGi in Action • http://www.manning.com/cummins •For more about the Push Streams • http://github.com/osgi/design •See the IoT Competition at 1745 today Questions? Thanks! http://www.paremus.com info@paremus.com http://www.manning.com/cummins
  • 29. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Addendum
  • 30. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 Demo Gremlins This morning I was testing my demo I couldn’t connect to the Network Rail Feed They had Deactivated my account! No demo = Unhappy Audience :( But OSGi is amazing technology from the future! I built a new module using MQTT to consume events from the OSGi Train 1 hour later - Working Demo. No other code had to change! Network Rail reactivated my account 10 minutes later…
  • 31. Copyright © 2005 - 2016 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. OSGi Community Event Nov 2016 www.paremus.com @Paremus info@paremus.com