reactive server

34
S Reactive Server Scott Ryan December 2016

Upload: davita-kidney-care

Post on 20-Mar-2017

68 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Reactive server

S

Reactive ServerScott Ryan

December 2016

Page 2: Reactive server

Who Am I

Open Source Consultant Server Technologies

Java, Groovy, Spring Big Data

Mongo, Hadoop, Spark, Storm Client

Angular 1 & 2, Javascript, CSS, HTML, DS3

Page 3: Reactive server

Agenda

The challenge Standard Solutions Future of Java Spring Solutions Implementation Considerations

Page 4: Reactive server

Characteristics of Reactive

Waiting for a response loses the ability operate in a parallel manner Respond in a timely manner Responsive in the face of failure Responsive under varying workload Leverage asynchronous message passing

Page 5: Reactive server

Slow from both Ends

Service Layer(Limited Threads)

Clients Resources

Page 6: Reactive server

Why do I need this?

Scalability Non blocking runtimes few

threads (Netty, Node JS(1))

Non blocking applications

Support slow clients in a non blocking way

Resource Availability and Stability

Function chaining (Callback Hell)

Getting Asynchronous right

Simplicity

Composeable Micro-services

Page 7: Reactive server

Asynchronous Programming Options

Java Futures Retrieving value is blocking Nested futures builds

callback hell

Java 8 Streams Pull based One time use Fixed length Don’t support latency

Completable Futures Completion stage

Finishes and Ends One result

Page 8: Reactive server

What is Reactive

Ability to push data from a hot source as it is available Observer pattern extended and done right Observable allows subscribers to register interest Producer can indicate completion Produced can indicate error Back pressure can be applied

Page 9: Reactive server

Data Publisher

Page 10: Reactive server

Data Subscriber

Page 11: Reactive server

Data Subscription

Page 12: Reactive server

20,000 Foot View

Subscriber

Subscription

Publisher

subscribe(Subscriber)

onSubscribe(Subscription)

Page 13: Reactive server

Java 9 Interfaces

Java.util.concurrent Flow.Publisher Flow.Subscriber Flow.Processor Flow.Subscription

Page 14: Reactive server

Flow.Publisher

void subscribe(Flow.Subscriber<? super T> subscriber)

Page 15: Reactive server

Flow.Subscriber

void onComplete() void onError(Throwable throwable) void onNext(T item) void onSubscribe(Flow.Subscription subscription)

Page 16: Reactive server

Flow.Processor

Combination of Subscriber and Publisher

Page 17: Reactive server

Flow.Subscription

void cancel() void request(long n) Nothing happens until request is called Request applies back pressure

Page 18: Reactive server

Bringing it Together

Subscriber

SubscriptionBack Pressure

Publisher

subscribe(Subscriber)

onSubsrcribe(Subscription)

onComplete()onError(Throwable)

onNext(Item)

cancel()request(n)

Page 19: Reactive server

S

Simple DemoJava 9 Interfaces

Page 20: Reactive server

Spring 5/Spring Boot 2

Support for implementation of the Flow interfaces Extensive added support to make them scalable and flexible Mono and Flux are Publishers Subscribers and Subscriptions available Implemented in web reactive (Netty, Undertow, Tomcat) Potentially in Spring Data, Spring Security, etc. Oracle reactive drivers

Page 21: Reactive server

Mono

Implements Publisher Interface Parallels CompletionStage Supports variable latency Produces 0 or 1 result Extensive support for scalability and processing

Page 22: Reactive server

Flux

Implements Publisher Interface Parallels the Stream implementation Produces multiple results Infinite length possible Supports variable latency Extended for scalability and processing

Page 23: Reactive server

Potential Ideas

Competing services first one wins Combine results from multiple services

Filter Remove Duplicates

Interleave results from multiple services

Page 24: Reactive server

MVC Magic

Spring MVC Rest Controllers Compatible with existing Controllers Spring Functional Interface Async input and output

Page 25: Reactive server

Functional Web Framework

Lightweight Functional definition Perfect for micro service standup

Page 26: Reactive server

S

Spring MVC DemoReactive 1

Page 27: Reactive server

High NumberService

PersonService

PersonController

Person Database

Low NumberService(Slow)

Page 28: Reactive server

S

Spring Functional Demo

Reactive 2

Page 29: Reactive server

Mongo

Netty

Page 30: Reactive server

Debugging and Logging

Always a challenge to debug asynchronous operations

Logging may be deceiving Test frameworks on the way

Page 31: Reactive server

Client Support

Observables on the client side HTTP 2 and Servlet 3.1 provide a pathway Containers like netty and undertow provide value Angular 2 , React etc. support client side

Observables

Page 32: Reactive server

Conclusion

Choose wisely grasshopper Do not assume it will produce value or performance

More is not necessarily better Prepare the team It is not your fathers Async world Design with Options Watch system load and usage

Page 33: Reactive server

Questions