state of akka 2017 - the best is yet to come

192
Konrad `ktoso` Malawski @ Scala Days CPH 2017 State of Akka @ 2017 The best is yet to come

Upload: konrad-malawski

Post on 23-Jan-2018

3.002 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: State of Akka 2017 - The best is yet to come

Konrad `ktoso` Malawski @ Scala Days CPH 2017

State of Akka @ 2017

The best is yet to come

Page 2: State of Akka 2017 - The best is yet to come

Konrad `ktoso` Malawski @ Scala Days CPH 2017

Disclaimer:

Parts of this talk is about under-development “experimental” APIs

which may change slightly.

This is not a strict roadmap,it is a general outline where we’re headed.

Page 3: State of Akka 2017 - The best is yet to come

Konrad `ktoso` Malawski

Akka Team,Reactive Streams TCK,

Scala SLIP Committee member

Page 4: State of Akka 2017 - The best is yet to come

Konrad `@ktosopl` Malawski

work: akka.io lightbend.com personal blog: http://kto.so

communities: geecon.org Java.pl / KrakowScala.pl sckrk.com GDGKrakow.pl lambdakrk.pl

Page 5: State of Akka 2017 - The best is yet to come
Page 6: State of Akka 2017 - The best is yet to come

The underlying motto of all our development

“Can we do better than that?”

Page 7: State of Akka 2017 - The best is yet to come

The underlying motto of all our development

“Can we do better than that?”

and sometimes…

“Been there, done that.”

Page 8: State of Akka 2017 - The best is yet to come

A JourneyFrom Past, through Current, to the Future…!

Page 9: State of Akka 2017 - The best is yet to come

https://www.lightbend.com/akka-five-year-anniversary

Paststarting 2009

Page 10: State of Akka 2017 - The best is yet to come
Page 11: State of Akka 2017 - The best is yet to come

https://www.lightbend.com/akka-five-year-anniversary

Page 12: State of Akka 2017 - The best is yet to come

”The actor model in computer science is a m a t h e m a t i c a l m o d e l o f c o n c u r r e n t computation that treats actors as the universal primitives of concurrent computation. ”

Wikipedia

The Actor Model

Page 13: State of Akka 2017 - The best is yet to come

and acts on them by: • Sending messages • Changing its state / behaviour • Creating more actors

receives messages

An Actor

Page 14: State of Akka 2017 - The best is yet to come

A concurrency and distribution construct. an addressable, location-transparent, entity.

An Actor

Actors talk directly to each other. An ActorSystem is truly peer-to-peer, not client-server.

Page 15: State of Akka 2017 - The best is yet to come

An Actor

(current 2.x API, not the ancient one :-))

Page 16: State of Akka 2017 - The best is yet to come

An Actor

Java API “feels native”, Java8 Lambdas, no Scala “leaking”

Page 17: State of Akka 2017 - The best is yet to come

A simple Actor interaction

Could be different threadsor different nodes in cluster.

API remains the same - and always async.

Page 18: State of Akka 2017 - The best is yet to come

Why does it matter?

Could be different threadsor different nodes in cluster.

API remains the same - and always async.

http://www.anandtech.com/show/11464/intel-announces-skylakex-bringing-18core-hcc-silicon-to-consumers-for-1999

Page 19: State of Akka 2017 - The best is yet to come

Actors are never “exposed”, ActorRefs are.

Page 20: State of Akka 2017 - The best is yet to come

Get “introduced”, interact directly.

Page 21: State of Akka 2017 - The best is yet to come

Binary > Textual Protocols“The Internet is running in debug mode.”

— Rüdiger Möller

http://java-is-the-new-c.blogspot.de/2014/10/why-protocols-are-messy-concept.html

Page 22: State of Akka 2017 - The best is yet to come

MediaContent {

media = Media {

uri = “http://conference.com/key.mpg"

title = "Keynote"

width = 640

height = 480

format = "video/mpg4"

duration = 18000000

size = 58982400

bitrate = 262144

persons = ["Bill Gates", "Steve Jobs"]

player = JAVA

copyright = null

}

}

images = [

Image {

uri = “http://conference.com/key_large.jpg"

title = "Keynote"

width = 1024

height = 768

size = LARGE

}

Image {

uri = “http://conference.com/key_small.jpg"

title = "Keynote"

width = 320

height = 240

size = SMALL

}

]

Not only JSON: Example data

Page 23: State of Akka 2017 - The best is yet to come

create ser deser total size

protostuff 68 433 634 1067ns 239bytes

protobuf 121 1173 719 1891 239

kryo-serializer 53 1480 1331 2810 286

thrift 95 1455 731 2186 349

. . .

json/jackson/manual 52 1039 1228 2267 468

json/jackson/databind 54 1164 1866 3030 485

json/gson/databind 56 4667 4403 9070 486

xml/xstream+c-aalto 54 3310 6732 10042 525

xml/JAXB 54 4354 141333 145686 719

java-built-in 53 5046 23279 28325 889

Why Binary?

Slide only to illustrate order-of-magniture differences. Don’t over-focus on numbers.

All details here: https://github.com/eishay/jvm-serializers/wiki

Page 24: State of Akka 2017 - The best is yet to come

create ser deser total size

protostuff 68 433 634 1067ns 239bytes

protobuf 121 1173 719 1891 239

kryo-serializer 53 1480 1331 2810 286

thrift 95 1455 731 2186 349

. . .

json/jackson/manual 52 1039 1228 2267 468

json/jackson/databind 54 1164 1866 3030 485

json/gson/databind 56 4667 4403 9070 486

xml/xstream+c-aalto 54 3310 6732 10042 525

xml/JAXB 54 4354 141333 145686 719

java-built-in 53 5046 23279 28325 889

Why Binary?

Slide only to illustrate order-of-magniture differences. Don’t over-focus on numbers.

All details here: https://github.com/eishay/jvm-serializers/wiki

Page 25: State of Akka 2017 - The best is yet to come

create ser deser total size

protostuff 68 433 634 1067ns 239bytes

protobuf 121 1173 719 1891 239

kryo-serializer 53 1480 1331 2810 286

thrift 95 1455 731 2186 349

. . .

json/jackson/manual 52 1039 1228 2267 468

json/jackson/databind 54 1164 1866 3030 485

json/gson/databind 56 4667 4403 9070 486

xml/xstream+c-aalto 54 3310 6732 10042 525

xml/JAXB 54 4354 141333 145686 719

java-built-in 53 5046 23279 28325 889

Why Binary?

Slide only to illustrate order-of-magniture differences. Don’t over-focus on numbers.

All details here: https://github.com/eishay/jvm-serializers/wiki

Page 26: State of Akka 2017 - The best is yet to come

Avoid Java Serialization

----sr--model.Order----h#-----J--idL--customert--Lmodel/Customer;L--descriptiont--Ljava/lang/String;L--orderLinest--Ljava/util/List;L--totalCostt--Ljava/math/BigDecimal;xp--------ppsr--java.util.ArrayListx-----a----I--sizexp----w-----sr--model.OrderLine--&-1-S----I--lineNumberL--costq-~--L--descriptionq-~--L--ordert--Lmodel/Order;xp----sr--java.math.BigDecimalT--W--(O---I--scaleL--intValt--Ljava/math/BigInteger;xr--java.lang.Number-----------xp----sr--java.math.BigInteger-----;-----I--bitCountI--bitLengthI--firstNonzeroByteNumI--lowestSetBitI--signum[--magnitudet--[Bxq-~----------------------ur--[B------T----xp----xxpq-~--xq-~--

Java Serialization

final case class Order(id: Long, description: String, totalCost: BigDecimal, orderLines: ArrayList[OrderLines], customer: Customer)

<order id="0" totalCost="0"><orderLines lineNumber="1" cost="0"><order>0</order></orderLines></order>XML…!

{"order":{"id":0,"totalCost":0,"orderLines":[{"lineNumber":1,"cost":0,"order":0}]}}JSON…!

------java-util-ArrayLis-----model-OrderLin----java-math-BigDecima---------model-Orde-----Kryo…!

Excellent post by James Sutherland @ http://java-persistence-performance.blogspot.com/2013/08/optimizing-java-serialization-java-vs.html

Page 27: State of Akka 2017 - The best is yet to come

Avoid Java Serialization

Akka uses ProtocolBuffers for (most*) it’s messages by default.

To completely disable Java Serialization do:

akka.actor.allow-java-serialization = false (which switches Akka to protobuf completely)

User messages you define your own serializers.

most* – due to wire compatibility some messages, wheresome messages did use JavSer in the past

Page 28: State of Akka 2017 - The best is yet to come

Avoid Java Serialization

Good serializers include (but are not limited to): Kryo, Google Protocol Buffers, SBE,Thrift, JSON if you really want

// dependencies"com.github.romix.akka" %% "akka-kryo-serialization" % "0.4.0"

// application.confextensions = [“com.romix.akka.serialization.kryo.KryoSerializationExtension$"]serializers { java = "akka.serialization.JavaSerializer" kryo = "com.romix.akka.serialization.kryo.KryoSerializer" }

akka.actor.serialization-bindings { “com.mycompany.Example”: kryo . . .}

[info] ForkJoinActorBenchmark.pingPong java avgt 10 25.464 ± 1.175 us/op [info] ForkJoinActorBenchmark.pingPong kryo avgt 10 4.348 ± 4.346 us/op [info] ForkJoinActorBenchmark.pingPong off avgt 10 0.967 ± 0.657 us/op

Page 29: State of Akka 2017 - The best is yet to come

Sidenote: Akka + Binary Compatibility?

Page 30: State of Akka 2017 - The best is yet to come

Our binary compatibility story

http://doc.akka.io/docs/akka/current/scala/common/binary-compatibility-rules.html

Page 31: State of Akka 2017 - The best is yet to come

Our binary compatibility story

http://doc.akka.io/docs/akka/current/scala/common/binary-compatibility-rules.html

2.3.1x [2015-09] -> 2.4.x [2015-08] -> 2.5.x [2017-04] -> ... 2.7.x [???] -> 2.8.x [???] -> 3.x [far out still, no need to break APIs]

Page 32: State of Akka 2017 - The best is yet to come

Our binary compatibility story

http://doc.akka.io/docs/akka/current/scala/common/binary-compatibility-rules.html

Binary compatibility != Wire compatibility

/* but we’ll get to that! (hint: Artery) */

Page 33: State of Akka 2017 - The best is yet to come
Page 34: State of Akka 2017 - The best is yet to come

History of Futures

In Days before Futures got standardised in Scala (~2012). Their design was heavily influenced by: Akka, Finagle & Scalaz & more…

Archival version @ 2012 http://doc.akka.io/docs/akka/2.0/scala/futures.html

SIP-14 - Futures and Promises By: Philipp Haller, Aleksandar Prokopec, Heather Miller, Viktor Klang, Roland Kuhn, and Vojin Jovanovic

http://docs.scala-lang.org/sips/completed/futures-promises.html

Page 35: State of Akka 2017 - The best is yet to come
Page 36: State of Akka 2017 - The best is yet to come

“Best practices are solutions to yesterdays problems.”

https://twitter.com/FrankBuytendijk/status/795555578592555008

Circuit breaking as substitute of flow-control

Page 37: State of Akka 2017 - The best is yet to come

See also, Nitesh Kant, Netflix @ Reactive Summit https://www.youtube.com/watch?v=5FE6xnH5Lak

Page 38: State of Akka 2017 - The best is yet to come

See also, Nitesh Kant, Netflix @ Reactive Summit https://www.youtube.com/watch?v=5FE6xnH5Lak

Page 39: State of Akka 2017 - The best is yet to come

HTTP/1.1 503 Service Unavailable

HTTP/1.1 503 Service Unavailable

Throttling as represented by 503 responses. Client will back-off… but how?What if most of the fleet is throttling?

Page 40: State of Akka 2017 - The best is yet to come

http://doc.akka.io/docs/akka/2.4/common/circuitbreaker.html

HTTP/1.1 503 Service Unavailable

HTTP/1.1 503 Service Unavailable

Page 41: State of Akka 2017 - The best is yet to come

http://doc.akka.io/docs/akka/2.4/common/circuitbreaker.html

Page 42: State of Akka 2017 - The best is yet to come

See also, Nitesh Kant, Netflix @ Reactive Summit https://www.youtube.com/watch?v=5FE6xnH5Lak

“slamming the breaks”

Page 43: State of Akka 2017 - The best is yet to come

See also, Nitesh Kant, Netflix @ Reactive Summit https://www.youtube.com/watch?v=5FE6xnH5Lak

“slamming the breaks”

Page 44: State of Akka 2017 - The best is yet to come

See also, Nitesh Kant, Netflix @ Reactive Summit https://www.youtube.com/watch?v=5FE6xnH5Lak

“slamming the breaks”

Page 45: State of Akka 2017 - The best is yet to come

See also, Nitesh Kant, Netflix @ Reactive Summit https://www.youtube.com/watch?v=5FE6xnH5Lak

“slamming the breaks”

Page 46: State of Akka 2017 - The best is yet to come

See also, Nitesh Kant, Netflix @ Reactive Summit https://www.youtube.com/watch?v=5FE6xnH5Lak

“slamming the breaks”

Page 47: State of Akka 2017 - The best is yet to come

See also, Nitesh Kant, Netflix @ Reactive Summit https://www.youtube.com/watch?v=5FE6xnH5Lak

We’ll re-visit this specific case in a bit :-)

“slamming the breaks”

Page 48: State of Akka 2017 - The best is yet to come

Are absolutely useful!

Still… “Can do better than that?”

Circuit Breakers

Page 49: State of Akka 2017 - The best is yet to come
Page 50: State of Akka 2017 - The best is yet to come

This will lead to the creation of Akka Streams and Reactive Streams!

We can do better.

Page 51: State of Akka 2017 - The best is yet to come
Page 52: State of Akka 2017 - The best is yet to come

The heart of Distributed Systems, built using Akka.

Akka Cluster

Page 53: State of Akka 2017 - The best is yet to come

Akka cluster provides membership and fault-tolerance for distributed Actors.

- Membership is implemented as epidemic gossip. - No single point of failure, “Leader” can move to

any of the nodes (deterministically) - Battle hardened since many years - Known to scale to 2400 nodes.

Akka Cluster

https://cloudplatform.googleblog.com/2014/01/large-akka-cluster-on-google-compute.html

Page 54: State of Akka 2017 - The best is yet to come

Cluster Sharding

Page 55: State of Akka 2017 - The best is yet to come

Cluster Sharding

Page 56: State of Akka 2017 - The best is yet to come

Failure detection using simple heartbeats often not good enough for production. You can:

- Use Akka Split Brain Resolver (commercial), multiple split brain scenario resolution strategies - “Keep majority”, “Keep oldest”, “Static Quorum”

- Perform manual downing (a safe bet, good if OPS or automated via Nagios etc)

- Roll your own, all required APIs are public

Failure detection is pluggable

https://cloudplatform.googleblog.com/2014/01/large-akka-cluster-on-google-compute.html

Page 57: State of Akka 2017 - The best is yet to come
Page 58: State of Akka 2017 - The best is yet to come

bit.ly/why-reactive

How to think about these techniques?

Page 59: State of Akka 2017 - The best is yet to come

Back then known as “Spray”, we joined up and started working on a streaming-first HTTP server.

Akka HTTP

Page 60: State of Akka 2017 - The best is yet to come

- Fully Typed HTTP model - So good, other projects use it instead of rolling their own!

(http4s uses Spray’s model.)

- Streaming-focused HTTP server - Built from the ground up on Akka Streams

- Full Java API (unlike Spray)

- Streaming with WebSockets!

Key features of Akka HTTP

Page 61: State of Akka 2017 - The best is yet to come

Streaming in Akka HTTP

http://doc.akka.io/docs/akka/2.4/scala/stream/stream-customize.html#graphstage-scala “Framed entity streaming”

http://doc.akka.io/docs/akka/2.4/java/http/routing-dsl/source-streaming-support.html

HttpServer as a: Flow[HttpRequest, HttpResponse]

Page 62: State of Akka 2017 - The best is yet to come

Streaming in Akka HTTP

HttpServer as a: Flow[HttpRequest, HttpResponse]

HTTP Entity as a: Source[ByteString, _]

http://doc.akka.io/docs/akka/2.4/scala/stream/stream-customize.html#graphstage-scala “Framed entity streaming”

http://doc.akka.io/docs/akka/2.4/java/http/routing-dsl/source-streaming-support.html

Page 63: State of Akka 2017 - The best is yet to come

Streaming in Akka HTTP

HttpServer as a: Flow[HttpRequest, HttpResponse]

HTTP Entity as a: Source[ByteString, _]

Websocket connection as a: Flow[ws.Message, ws.Message]

http://doc.akka.io/docs/akka/2.4/scala/stream/stream-customize.html#graphstage-scala “Framed entity streaming”

http://doc.akka.io/docs/akka/2.4/java/http/routing-dsl/source-streaming-support.html

Page 64: State of Akka 2017 - The best is yet to come

High level Routing API:

Key features of Akka HTTP

Page 65: State of Akka 2017 - The best is yet to come

Low-level API (e.g. what Play uses):

Key features of Akka HTTP

Page 66: State of Akka 2017 - The best is yet to come
Page 67: State of Akka 2017 - The best is yet to come

Akka Persistence EventSourcing your Actors

Page 68: State of Akka 2017 - The best is yet to come

Event sourcing your Actors

Receive commands. Store events. Optional: Create queries / views

Page 69: State of Akka 2017 - The best is yet to come

Event sourcing your Actors

Page 70: State of Akka 2017 - The best is yet to come

Event sourcing your Actors

Page 71: State of Akka 2017 - The best is yet to come

Event sourcing your Actors

Page 72: State of Akka 2017 - The best is yet to come

Present & near Future2016~2017+

Page 73: State of Akka 2017 - The best is yet to come
Page 74: State of Akka 2017 - The best is yet to come

Distributed Data Conflict-Free Data-Types

Page 75: State of Akka 2017 - The best is yet to come

CAP theorem reminder

Akka Persistence Akka DData

Page 76: State of Akka 2017 - The best is yet to come

CAP theorem reminder

Akka DDataAkka Persistence

Page 77: State of Akka 2017 - The best is yet to come

Using Distributed Data

The focus is on “spreading the data”, not on the “single entity” like it is in Persistence.

Page 78: State of Akka 2017 - The best is yet to come

Distributed Data visualised

You supply a write consistency level which has the following meaning:

•WriteLocal the value will immediately only be written to the local replica, and later disseminated with gossip

•WriteTo(n) the value will immediately be written to at least n replicas, including the local replica

•WriteMajority the value will immediately be written to a majority of replicas, i.e. at least N/2 + 1 replicas, where N is the number of nodes in the cluster (or cluster role group)

•WriteAll the value will immediately be written to all nodes in the cluster (or all nodes in the cluster role group)

Page 79: State of Akka 2017 - The best is yet to come

CRDTs spread using Gossip

Page 80: State of Akka 2017 - The best is yet to come

CRDTs spread using Gossip

Page 81: State of Akka 2017 - The best is yet to come

CRDTs spread using Gossip

Page 82: State of Akka 2017 - The best is yet to come

CRDTs spread using Gossip

Page 83: State of Akka 2017 - The best is yet to come

Summary of CRDTs

• Counters: GCounter, PNCounter • Sets: GSet, ORSet • Maps: ORMap, ORMultiMap, LWWMap, PNCounterMap • Registers: LWWRegister, Flag

Page 84: State of Akka 2017 - The best is yet to come
Page 85: State of Akka 2017 - The best is yet to come

“Stream”

Page 86: State of Akka 2017 - The best is yet to come

Suddenly everyone jumped on the word “Stream”.

Akka Streams / Reactive Streams started end-of-2013.

“Streams”

* when put in “” the word does not appear in project name, but is present in examples / style of APIs / wording.

Page 87: State of Akka 2017 - The best is yet to come

Suddenly everyone jumped on the word “Stream”.

Akka Streams / Reactive Streams started end-of-2013.

The word “Stream” is used in many contexts/meanings

Akka Streams Reactive Streams RxJava “streams”* Spark Streaming Apache Storm “streams”* Java Steams (JDK8) Reactor “streams”* Kafka Streams ztellman / Manifold (Clojure)

* when put in “” the word does not appear in project name, but is present in examples / style of APIs / wording.

Apache GearPump “streams” Apache [I] Streams (!) Apache [I] Beam “streams” Apache [I] Quarks “streams” Apache [I] Airflow “streams” (dead?) Apache [I] Samza Scala Stream Scalaz Streams, now known as FS2 Swave.io Java InputStream / OutputStream / … :-)

2017年: 安定版。リアクティブストリーム付きの JDK9。

Page 88: State of Akka 2017 - The best is yet to come

“Stream” What does it mean?!

• Possibly infinite datasets (“streams”)

• “Streams are NOT collections.”

• Processed element-by-element• Element could mean “byte” • More usefully though it means a specific type “T”

• Asynchronous processing• Asynchronous boundaries (between threads)

• Network boundaries (between machines)

2017年: 安定版。リアクティブストリーム付きの JDK9。

Page 89: State of Akka 2017 - The best is yet to come

Where does Akka Stream fit?

Akka Streams specifically fits,if you answer yes to any of these:

• Should it take on public traffic?• Processing in hot path for requests?• Integrate various technologies?• Protect services from over-load?• Introspection, debugging, excellent Akka integration?• (vs. other reactive-stream impls.)

Page 90: State of Akka 2017 - The best is yet to come

How do I pick which “streaming” I need?

Kafka serves best as a transport for pub-sub across services.

• Note that Kafka Streams (db ops are on the node) is rather, different than the Reactive Kafka client

• Great for cross-service communication instead of HTTP Request / Reply

Kafka はサービス間の pub-sub 通信に向いているHTTP の代わりにサービス間の通信に使う

Page 91: State of Akka 2017 - The best is yet to come

How do I pick which “streaming” I need?

Spark has vast libraries for ML or join etc ops.

• It’s the “hadoop replacement”.• Spark Streaming is windowed-batches• Latency anywhere up from 0.5~1second

• Great for cross-service communication instead of HTTP Req/Reply

Spark は機械学習系が充実している

Page 92: State of Akka 2017 - The best is yet to come

Oh yeah, there’s JDK8 “Stream” too!

Terrible naming decision IMHO, since Java’s .stream()

• Geared for collections • Best for finite and known-up-front data• Lazy, sync/async (async rarely used)• Very (!) hard to extend

It’s the opposite what we talk about in Streaming systems!

It’s more: “bulk collection operations”Also known as… Scala collections API (i.e. Iterator

JDK8 の Stream はイテレータ的なもの

Page 93: State of Akka 2017 - The best is yet to come

What about JDK9 “Flow”?

JDK9 introduces java.util.concurrent.Flow

• Is a 1:1 copy of the Reactive Streams interfaces• On purpose, for people to be able to impl. it

• Does not provide useful implementations• Is only the inter-op interfaces• Libraries like Akka Streams implement RS,

and expose useful APIs for you to use.

JDK9 の Flow はリアクティブ・ストリーム

Page 94: State of Akka 2017 - The best is yet to come

A fundamental building block. Not end-user API by itself.

reactive-streams.org

Reactive Streams

Page 95: State of Akka 2017 - The best is yet to come

Reactive StreamsMore of an SPI (Service Provider Interface),

than API.

reactive-streams.org

Page 96: State of Akka 2017 - The best is yet to come

The specification.Reactive Streams

Origins of

Page 97: State of Akka 2017 - The best is yet to come

Reactive Streams - story: 2013’s impls

2014–2015:

Reactive Streams Spec & TCKdevelopment, and implementations.

1.0 released on April 28th 2015,with 5+ accompanying implementations.

2015Included in JDK9 via JEP-266 “More Concurrency Updates”

download.java.net/java/jdk9/docs/api/java/util/concurrent/Flow.html

Page 98: State of Akka 2017 - The best is yet to come

But what does it do!?

Reactive Streams

Page 99: State of Akka 2017 - The best is yet to come

Fast Publisher[T] Slow Subscriber[T]

Push model

Page 100: State of Akka 2017 - The best is yet to come

Subscriber usually has some kind of buffer.

Push model

Page 101: State of Akka 2017 - The best is yet to come

What if the buffer overflows?

Push model

Page 102: State of Akka 2017 - The best is yet to come

Kernel does this!Routers do this!

(TCP)

Use bounded buffer, drop messages + require re-sending

Push model

Page 103: State of Akka 2017 - The best is yet to come

Reactive Streams explained

Reactive Streams explained in 1 slide

Page 104: State of Akka 2017 - The best is yet to come

Fast Publisher will send at-most 3 elements. This is pull-based-backpressure.

Reactive Streams: “dynamic push/pull”

Page 105: State of Akka 2017 - The best is yet to come

JEP-266 – soon…!public final class Flow { private Flow() {} // uninstantiable

@FunctionalInterface public static interface Publisher<T> { public void subscribe(Subscriber<? super T> subscriber); }

public static interface Subscriber<T> { public void onSubscribe(Subscription subscription); public void onNext(T item); public void onError(Throwable throwable); public void onComplete(); }

public static interface Subscription { public void request(long n); public void cancel(); }

public static interface Processor<T,R> extends Subscriber<T>, Publisher<R> { }}

Page 106: State of Akka 2017 - The best is yet to come

Reactive Streams: goals

1) Avoiding unbounded buffering across async boundaries

2) Inter-op interfaces between various libraries

Page 107: State of Akka 2017 - The best is yet to come

Reactive Streams: goals1) Avoiding unbounded buffering across async boundaries

2) Inter-op interfaces between various libraries

Argh, implementing a correct RS Publisher or Subscriber is so hard!

Page 108: State of Akka 2017 - The best is yet to come

1) Avoiding unbounded buffering across async boundaries

2) Inter-op interfaces between various libraries

Reactive Streams: goals

Argh, implementing a correct RS Publisher or Subscriber is so hard!

Page 109: State of Akka 2017 - The best is yet to come

Reactive Streams: goals

Argh, implementing a correct RS Publisher or Subscriber is so hard!

You should be using Akka Streams instead!

1) Avoiding unbounded buffering across async boundaries

2) Inter-op interfaces between various libraries

Page 110: State of Akka 2017 - The best is yet to come

Akka Streams in 20 seconds:

val firstString: Future[String] = Source.single(1) .map(_.toString()) .runWith(Sink.head)

Page 111: State of Akka 2017 - The best is yet to come

Source.single(1).map(i => i.toString).runWith(Sink.head())

// types: _Source[Int, NotUsed] Flow[Int, String, NotUsed] Sink[String, Future[String]]

Akka Streams in 20 seconds:

Page 112: State of Akka 2017 - The best is yet to come

// types: _Source[Int, NotUsed] Flow[Int, String, NotUsed] Sink[String, Future[String]]

Source.single(1).map(i => i.toString).runWith(Sink.head())

Akka Streams in 20 seconds:

Page 113: State of Akka 2017 - The best is yet to come
Page 114: State of Akka 2017 - The best is yet to come

natively in Akka HTTP/2

HTTP/2

Page 115: State of Akka 2017 - The best is yet to come

HTTP/2

1.9M May 15 08:02 bigimage.jpg 995K May 15 08:16 bigimage2.jpg

Page 116: State of Akka 2017 - The best is yet to come

HTTPS - the usual waterfall

Page 117: State of Akka 2017 - The best is yet to come

HTTPS - the usual waterfall

Page 118: State of Akka 2017 - The best is yet to come

HTTPS - the usual waterfall

Page 119: State of Akka 2017 - The best is yet to come

HTTP/2

Page 120: State of Akka 2017 - The best is yet to come

HTTP/2

Page 121: State of Akka 2017 - The best is yet to come

HTTP/2

HTTP(S)/1.1

HTTP/2

(before performance optimisations (sic))

Page 122: State of Akka 2017 - The best is yet to come

Play + Akka HTTP => HTTP/2

+ TLS configuration

https://github.com/playframework/play-scala-tls-example/pull/30

http/2HTTP+ =

Page 123: State of Akka 2017 - The best is yet to come

Akka HTTP as default backend for Play

Goal is not to “beat Netty*” but to keep perf while adding features.

Future:- Shared Typed HTTP Model- Shared Monitoring- Shared performance work

TL;DR; == Shared efforts

* We <3 Netty.

http://playframework.github.io/prune/ Ofc: Netty backend remains available.

Page 124: State of Akka 2017 - The best is yet to come
Page 125: State of Akka 2017 - The best is yet to come

Sub-journey to Akka Typed

Page 126: State of Akka 2017 - The best is yet to come

The journey to Akka Typed

Page 127: State of Akka 2017 - The best is yet to come

The journey to Akka Typed

Ancient API, deprecated“Typed Actor” API

Goal was to expose what Java developers knew.

Page 128: State of Akka 2017 - The best is yet to come

The journey to Akka Typed

Old “TypedActor” experimental in 2.3, removed

Upsides:- Easily bridge to “non-Akka” / “non-Reactive” apps- type-safe- “easy” (not necessarily a good thing)

Downsides:- Reflection, 10x slow-down compared to UntypedActor- “RPC”-ish, not true to the core messaging- Not true to Akka’s core principle: Messaging

Page 129: State of Akka 2017 - The best is yet to come

The journey to Akka Typed

Page 130: State of Akka 2017 - The best is yet to come

The journey to Akka Typed

“Typed Channels” experimental in 2.3, removed

Page 131: State of Akka 2017 - The best is yet to come

The journey to Akka Typed

“Typed Channels” experimental in 2.3, removed

Upsides:- completely type-safe- very expressive

Downsides:- Too complex, many new operators- Had to rely on scala macros - “sender” difficult to solve

Page 132: State of Akka 2017 - The best is yet to come

The journey to Akka Typed

Page 133: State of Akka 2017 - The best is yet to come

The journey to Akka Typed

http://axel22.github.io/resources/docs/reactors.pdf

Page 134: State of Akka 2017 - The best is yet to come

The journey to Akka Typed

Page 135: State of Akka 2017 - The best is yet to come

Akka Typed

try it now, 2.5.2from repo.akka.io/snapshots

2 styles, 100% awesome.Full Java & Scala API, as usual.

Actor.mutable – similar to current Actors, Behavior is a classActor.immutable – more functional style, recommended

Page 136: State of Akka 2017 - The best is yet to come

Akka Typed

Main user-facing changes:

ActorRef[T] typed ActorRefs.

Core concept is Behavior[T]which can be freely composed.

You always “become(Behavior)”, by returning Behavior.

sender() is gone,not possible to type it well.

sender was trouble anyway, so that’s good!

Page 137: State of Akka 2017 - The best is yet to come

Akka Typed

Untyped

=>

Actor.mutable

Page 138: State of Akka 2017 - The best is yet to come

Akka Typed

Untyped

Page 139: State of Akka 2017 - The best is yet to come

Akka Typed

Actor.immutable

Page 140: State of Akka 2017 - The best is yet to come

Akka TypedActor.immutable (Scala)

Page 141: State of Akka 2017 - The best is yet to come

Akka TypedActor.immutable (Scala)

Don’t worry, Java will eventually get pattern matching:http://mail.openjdk.java.net/pipermail/amber-spec-experts/2017-April/000033.html

Java adopting Scala features confirms Scala’s design.

…but, until then we provide you with helpers and DSLs:

Page 142: State of Akka 2017 - The best is yet to come

Akka TypedActor.immutable (Scala)

Actor.immutable (Java)

Page 143: State of Akka 2017 - The best is yet to come

Akka Typed

try it now, 2.5.99-TYPED-M1from repo.akka.io/snapshots

Learn more: from the docs: http://doc.akka.io/docs/akka/snapshot/scala/typed.html

and the blog: 1. Akka Typed: Hello World in the new API 2. Akka Typed: Coexistence 3. Akka Typed: Mutable vs. Immutable 4. Akka Typed: Protocols 5. Akka Typed: Supervision 6. Akka Typed: Lifecycle and Watch 7. Akka Typed: Timers

Page 144: State of Akka 2017 - The best is yet to come
Page 145: State of Akka 2017 - The best is yet to come

A community for Streams connectors

Alpakka – a community for Stream connectors

Alp

Page 146: State of Akka 2017 - The best is yet to come

Alpakka – a community for Stream connectors

http://developer.lightbend.com/docs/alpakka/current/

Page 147: State of Akka 2017 - The best is yet to come

Alpakka – a community for Stream connectors

http://developer.lightbend.com/docs/alpakka/current/

Page 148: State of Akka 2017 - The best is yet to come

Alpakka – a community for Stream connectors

http://developer.lightbend.com/docs/alpakka/current/

Page 149: State of Akka 2017 - The best is yet to come

Akka Streams in 20 seconds:

Page 150: State of Akka 2017 - The best is yet to come

Akka Streams in 20 seconds:

Page 151: State of Akka 2017 - The best is yet to come

Akka Streams core principles:

Page 152: State of Akka 2017 - The best is yet to come

Akka Streams core principles:

Page 153: State of Akka 2017 - The best is yet to come

Ecosystem that solves problems

> (is greater than) solving all the problems ourselves

Page 154: State of Akka 2017 - The best is yet to come
Page 155: State of Akka 2017 - The best is yet to come

Way more than just “we changed the transport.”

New Remoting: Artery

Page 156: State of Akka 2017 - The best is yet to come

Artery

Next generation remoting layer for Akka.

• Aeron (UDP) based instead of TCP,• Advanced automatic ActorRef Compression• Dedicated “lanes” for certain messages / destinations• Almost alloc-free in steady-state (except deserialization)

Page 157: State of Akka 2017 - The best is yet to come

Remoting feature matrix

Remoting “classic” Artery Remoting

Protocol TCP TLS+TCP

UDP (Aeron)

Large messages Troublesome Dedicated lanes

Heartbeat and System Messages Prioritised Dedicated lanes

Benchmarked* throughput 70k msg/s 700k+ msg/s

(up to 1m msg/s)

* benchmark setup: 5-to-5 actors, 100byte payload message (excluding envelope size), Amazon EC2 M4-X2Large instances

Page 158: State of Akka 2017 - The best is yet to come

How to use Artery?

single option,no new artifacts

Page 159: State of Akka 2017 - The best is yet to come

“Steady state” operation almost alloc-free

Serialize Deserialize

compression compression

package readpackage write

Akk

a St

ream

s(a

lloca

tion

free

)

Pooled envelopes

Pooled ByteBuffersDeserialize allocates

Pooled ByteBuffersno allocations

Caches for ActorRefs etcno allocations in steady state

Page 160: State of Akka 2017 - The best is yet to come

Artery: ActorRef Compression

Compression triggered for “heavy hitters”,so “most chatty” Actors to maximise benefit.

Triggers automatically & transparently.

Page 161: State of Akka 2017 - The best is yet to come

Artery: ActorRef / Manifest Compression

Page 162: State of Akka 2017 - The best is yet to come

Artery: ActorRef / Manifest Compression

In this case ActorRef compression reduced the size of a small envelope size by 74% - from 162 to 42 bytes (sic!).

Page 163: State of Akka 2017 - The best is yet to come
Page 164: State of Akka 2017 - The best is yet to come

Multi Data CenterCustomers increasingly have global-scale apps,

so we’re looking into advanced Multi-DataCenter scenarios.

Page 165: State of Akka 2017 - The best is yet to come

Multi Data Center

These are just ideas.Talk to me, we’re gathering use cases.

- Active + Active ???

- Locality aware Cluster Sharding ???

- Entity “owner” Datacenter ???- Talk to us about your use cases :)

- …?

Page 166: State of Akka 2017 - The best is yet to come

Wait, there’s more! (things I couldn’t fit on the map)

Page 167: State of Akka 2017 - The best is yet to come

New docs engine New QuickStart, ScalaFiddle…

Page 168: State of Akka 2017 - The best is yet to come

Lightbend Paradox - docs engine

We know, we know: “Yet another docs engine”

Built-in scala-fiddle support

Akka.js => run Akka docs examples in browser

Page 169: State of Akka 2017 - The best is yet to come

Lightbend Paradox - docs engine

Much much easier to contribute now.

Zero dependencies just type “paradox”

Markdown instead of restructured text!

Built in capabilities to link github / scaladoc

Simple way to build multi-prog-lang docs @scala/@java

Page 170: State of Akka 2017 - The best is yet to come

Lightbend “kickstart” Replacing Activator

Page 171: State of Akka 2017 - The best is yet to come

developer.lightbend.com

Page 172: State of Akka 2017 - The best is yet to come

Tracing & Monitoring distributed systems

Page 173: State of Akka 2017 - The best is yet to come

Monitoring Akka

developer.lightbend.com/docs/monitoring/latest/home.html+

DataDog || StatsD || Graphite || …anything!

Page 174: State of Akka 2017 - The best is yet to come

Monitoring Akka

e.g.DataDog || StatsD || Graphite || …anything!

Page 175: State of Akka 2017 - The best is yet to come

Monitoring AkkaRemember where Artery Compression kicks in?

(“Top senders” / “Top receivers”)

Page 176: State of Akka 2017 - The best is yet to come

Tracing Akka with Jaeger or ZipkinUber Jaeger

Twitter Zipkin

Page 177: State of Akka 2017 - The best is yet to come

Tracing Akka with Jaeger or Zipkin

Lightbend Monitoringhttps://developer.lightbend.com/docs/cinnamon/latest/extensions/opentracing.html

Page 178: State of Akka 2017 - The best is yet to come

Tracing across nodes

Lightbend Monitoringhttps://developer.lightbend.com/docs/cinnamon/latest/extensions/opentracing.html

Already tracing across network transparently,Akka HTTP coming soon, as will Futures.

Page 179: State of Akka 2017 - The best is yet to come

Monitoring Akka

“What is failing in the system?”Lightbend OpsClarity

Page 180: State of Akka 2017 - The best is yet to come

External initiatives

Page 181: State of Akka 2017 - The best is yet to come

IntelliJ support for Akka!

Page 182: State of Akka 2017 - The best is yet to come

Ports to other platforms

Not supported by Lightbend, community projects.

http://getakka.net/ http://akka-js.org/

A sign that Akka is interesting and worth porting:

Page 183: State of Akka 2017 - The best is yet to come

Open Source projects using Akkaindex.scala-lang.org

Page 184: State of Akka 2017 - The best is yet to come

Summing up…

Page 185: State of Akka 2017 - The best is yet to come

Summing up

With all the foundational building blocks prepared…

“The best is yet to come.”

Page 186: State of Akka 2017 - The best is yet to come

Happy hAkking!

Page 187: State of Akka 2017 - The best is yet to come

Thanks everyone

Page 188: State of Akka 2017 - The best is yet to come

Thanks everyone

Committers from the Community!Jan Pustelnik

Krzysiek Ciesielski, Alexey Romanchuk,

Heiko Seeberger,Josep Prat,Jan Ypma,

André Rüdiger,Jonas Fonseca

…and hundreds of contributors

Thanks!

Page 189: State of Akka 2017 - The best is yet to come

We <3 contributions• Easy to contribute:

• https://github.com/akka/akka/issues?q=is%3Aissue+is%3Aopen+label%3Aeasy-to-contribute • https://github.com/akka/akka/issues?q=is%3Aissue+is%3Aopen+label%3A%22nice-to-have+%28low-prio%29%22

• Akka: akka.io && github.com/akka • Reactive Streams: reactive-streams.org • Reactive Socket: reactivesocket.io

• Mailing list:• https://groups.google.com/group/akka-user

• Public chat rooms:• http://gitter.im/akka/dev developing Akka• http://gitter.im/akka/akka using Akka

Page 190: State of Akka 2017 - The best is yet to come

Free e-book and printed report.bit.ly/why-reactive

Covers what reactive actually is.Implementing in existing architectures.

Thoughts from the team that’s buildingreactive apps since more than 6 years.

Obligatory “read my book!” slide :-)

Page 191: State of Akka 2017 - The best is yet to come

Metal Gear Solid illustrationsby Lap Pun Cheung

http://www.lpcheung.com/metal-gear-solid/

Hand drawn illustrations:by myself, CC-BY-NC

Artwork links

Page 192: State of Akka 2017 - The best is yet to come

Thanks! Questions?

ktoso @ lightbend.comtwitter: ktosopl

github: ktosoteam blog: blog.akka.io

home: akka.iomyself: kto.so