the things we don't see – stories of software, scala and akka

119
Konrad `@ktosopl` Malawski @ Scalapeno 2016 q The things we don’t see Exploring the unseen worlds of the Scala, Akka and Software in general

Upload: konrad-malawski

Post on 13-Apr-2017

2.747 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: The things we don't see – stories of Software, Scala and Akka

Konrad `@ktosopl` Malawski @ Scalapeno 2016

q

The things we don’t see Exploring the unseen worlds of the Scala,

Akka and Software in general

Page 2: The things we don't see – stories of Software, Scala and Akka

Konrad `@ktosopl` Malawski @ Scalapeno 2016

The things we don’t see Exploring the unseen worlds of the Scala,

Akka and Software in general

Page 3: The things we don't see – stories of Software, Scala and Akka

Konrad `@ktosopl` Malawski

akka.iotypesafe.comgeecon.org

Java.pl / KrakowScala.plsckrk.com / meetup.com/Paper-Cup @ London

GDGKrakow.pl lambdakrk.pl

Page 4: The things we don't see – stories of Software, Scala and Akka
Page 5: The things we don't see – stories of Software, Scala and Akka

“The things we don’t see”

What it means (at least for me, and in this talk)

… in Software in general

… in Scala (programming languages)

… in Akka (concurrency, distributed systems)

Page 6: The things we don't see – stories of Software, Scala and Akka

The things we don’t see…in Software

Page 7: The things we don't see – stories of Software, Scala and Akka

A world of tradeoffs

Reality

Page 8: The things we don't see – stories of Software, Scala and Akka

A world of tradeoffs

Reality

Page 9: The things we don't see – stories of Software, Scala and Akka

A world of tradeoffs

Reality

Page 10: The things we don't see – stories of Software, Scala and Akka

A world of tradeoffs

Reality

Page 11: The things we don't see – stories of Software, Scala and Akka

A world of tradeoffs

Reality

At the core of it…This talk is about trade-offs.

Page 12: The things we don't see – stories of Software, Scala and Akka

Measure

Page 13: The things we don't see – stories of Software, Scala and Akka

Measure

What we can’t measure, we can’t improve.And often: simply don’t improve at all.

Page 14: The things we don't see – stories of Software, Scala and Akka

Measure

What we can’t measure, we can’t improve.And often: simply don’t improve at all.

“ArrayDeque surely will be faster here!” Wha..! Turns out it isn’t, let’s see why…

Page 15: The things we don't see – stories of Software, Scala and Akka

Measure, to gain understanding of your system

OMG! I changed all the settings to “more”! And it’s not improving…!

Page 16: The things we don't see – stories of Software, Scala and Akka

Measure, to gain understanding of your system

OMG! I changed all the settings to “more”! And it’s not improving…!

Hmm… weird. Where do you see the bottleneck?

Page 17: The things we don't see – stories of Software, Scala and Akka

Measure, to gain understanding of your system

OMG! I changed all the settings to “more”! And it’s not improving…!

Hmm… weird. Where do you see the bottleneck?

Page 18: The things we don't see – stories of Software, Scala and Akka

Measure, and don’t be that guy

OMG! That lib is 1000x better in serving a file!!! I’ll use kernel bypass networking for my blog!

Have & understand actual performance requirements,don’t invent them based on high frequency trading* talks :-)

* I’m assuming here that’s not your business, if it is – carry on.

Page 19: The things we don't see – stories of Software, Scala and Akka

Systems, what do they do?!

Page 20: The things we don't see – stories of Software, Scala and Akka

Systems, what do they do?!

Page 21: The things we don't see – stories of Software, Scala and Akka

Systems, what do they do?!

Page 22: The things we don't see – stories of Software, Scala and Akka

Systems, what do they do?!

Page 23: The things we don't see – stories of Software, Scala and Akka

Systems, what do they do?!

Page 24: The things we don't see – stories of Software, Scala and Akka

Systems, what do they do?!

Page 25: The things we don't see – stories of Software, Scala and Akka

The things we don’t see… in Scala

Page 26: The things we don't see – stories of Software, Scala and Akka

A thing about nulls

Page 27: The things we don't see – stories of Software, Scala and Akka

A thing about nulls

"I call it my billion-dollar mistake." Sir C. A. R. Hoare, on his invention of the null reference

Page 28: The things we don't see – stories of Software, Scala and Akka

A thing about nulls

something.calculateSum(2, 2)

What does this code do?

Page 29: The things we don't see – stories of Software, Scala and Akka

A thing about nulls

something.calculateSum(2, 2)

What does this code do?

a) return 4b) NullPointerException!c) System.exit(0) // though I have a love-hate relationship with this answer…

Page 30: The things we don't see – stories of Software, Scala and Akka

The curious case of OptionsScala Option – 2007 (Scala 2.5, sic! http://www.scala-lang.org/old/node/165)Guava Optional – 2011 (since v10.0)Java Optional – 2014 (since v1.8)

Page 31: The things we don't see – stories of Software, Scala and Akka

Scala Option – 2007 (Scala 2.5, sic! http://www.scala-lang.org/old/node/165)Guava Optional – 2011 (since v10.0)Java Optional – 2014 (since v1.8)

The curious case of Options

sealed abstract class Option[+A] extends Product with Serializable { self =>

def isEmpty: Boolean def isDefined: Boolean = !isEmpty def get: A @inline final def getOrElse[B >: A](default: => B): B = if (isEmpty) default else this.get

Page 32: The things we don't see – stories of Software, Scala and Akka

Scala Option – 2007 (Scala 2.5, sic! http://www.scala-lang.org/old/node/165)Guava Optional – 2011 (since v10.0)Java Optional – 2014 (since v1.8)

The curious case of Options

sealed abstract class Option[+A] extends Product with Serializable { self =>

def isEmpty: Boolean def isDefined: Boolean = !isEmpty def get: A @inline final def getOrElse[B >: A](default: => B): B = if (isEmpty) default else this.get

public final class Optional<T> { public boolean isPresent() { return value != null; } public T get() { if (value == null) throw new NoSuchElementException("No value present"); return value; } public T orElseGet(Supplier<? extends T> other) { return value != null ? value : other.get(); }

Page 33: The things we don't see – stories of Software, Scala and Akka

The curious case of Options

val o: Option[String] = ??? o.foreach(_.toUpperCase(Locale.ROOT)) // ok, sure o match { case Some(value) => value.toUpperCase(Locale.ROOT) case None => "_"}

We all have the same “mistake”: get seems innocent, but it’s not…

final Optional<String> optional = Optional.of("");

optional.map(it -> it.toUpperCase(Locale.ROOT)); if (optional.isPresent()) { optional.get().toUpperCase();}

Page 34: The things we don't see – stories of Software, Scala and Akka

Can we do better than that though?

“What the eyes don’t see,the programmer does not invoke.”

Page 35: The things we don't see – stories of Software, Scala and Akka

Blocking is the new “you broke the build!”

Page 36: The things we don't see – stories of Software, Scala and Akka

Blocking is the new “you broke the build!”// BAD! (due to the blocking in Future):implicit val defaultDispatcher = system.dispatcher

val routes: Route = post { complete { Future { // uses defaultDispatcher

Thread.sleep(5000) // will block on the default dispatcher, System.currentTimeMillis().toString // starving the routing infra } }}

Page 37: The things we don't see – stories of Software, Scala and Akka

Blocking is the new “you broke the build!”// BAD! (due to the blocking in Future):implicit val defaultDispatcher = system.dispatcher

val routes: Route = post { complete { Future { // uses defaultDispatcher

Thread.sleep(5000) // will block on the default dispatcher, System.currentTimeMillis().toString // starving the routing infra } }}

http://stackoverflow.com/questions/34641861/akka-http-blocking-in-a-future-blocks-the-server/34645097#34645097

Page 38: The things we don't see – stories of Software, Scala and Akka

The curious case of Futures

Page 39: The things we don't see – stories of Software, Scala and Akka

The curious case of Futurespublic class CompletableFuture<T> implements Future<T>, CompletionStage<T> {

public T get() throws InterruptedException, ExecutionException { // ... }

public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { // ... }

Page 40: The things we don't see – stories of Software, Scala and Akka

The curious case of Futures

Anyone remember the days beforescala.concurrent.Future?

Back to the Future, in which we discuss Akka and Twitter Futures in 2012 :-)https://groups.google.com/forum/?fromgroups=#!topic/akka-user/eXiBV5V7ZzE%5B1-25%5D

Page 41: The things we don't see – stories of Software, Scala and Akka

The curious case of Futurespublic class CompletableFuture<T> implements Future<T>, CompletionStage<T> {

public T get() throws InterruptedException, ExecutionException { // ... }

public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { // ... }

trait Future[+T] extends Awaitable[T] {

// THERE IS NO GET! // Closest thing to it is...

def value: Option[Try[T]] // However it’s not that widely known actually // Notice that it is non-blocking!

Page 42: The things we don't see – stories of Software, Scala and Akka

The curious case of Futurespublic class CompletableFuture<T> implements Future<T>, CompletionStage<T> {

public T get() throws InterruptedException, ExecutionException { // ... }

public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { // ... }

trait Future[+T] extends Awaitable[T] {

// THERE IS NO GET! // Closest thing to it is...

def value: Option[Try[T]] // However it’s not that widely known actually // Notice that it is non-blocking!

Page 43: The things we don't see – stories of Software, Scala and Akka

The curious case of Futurespublic class CompletableFuture<T> implements Future<T>, CompletionStage<T> {

public T get() throws InterruptedException, ExecutionException { // ... }

public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { // ... }

trait Future[+T] extends Awaitable[T] {

// THERE IS NO GET! // Closest thing to it is...

def value: Option[Try[T]] // However it’s not that widely known actually // Notice that it is non-blocking!

object Await {

@throws(classOf[TimeoutException]) @throws(classOf[InterruptedException]) def ready[T](awaitable: Awaitable[T], atMost: Duration): awaitable.type = blocking(awaitable.ready(atMost)(AwaitPermission))

@throws(classOf[Exception]) def result[T](awaitable: Awaitable[T], atMost: Duration): T = blocking(awaitable.result(atMost)(AwaitPermission)) }

Page 44: The things we don't see – stories of Software, Scala and Akka

The curious case of Futures

Java strongly valued fitting-in with existing types.This forced exposing the get() method.

Scala had a clean-slate, could keep out of sight methodswe don’t want devs to call as they’re dangerous.

“If you don’t see a way at first sight…maybe it was hidden on purpose?”

Page 45: The things we don't see – stories of Software, Scala and Akka

Hidden scaladoc features

Page 46: The things we don't see – stories of Software, Scala and Akka

Hidden scaladoc features

Akka HTTP 2.4.2we didn’t know about the

hidden feature as well actually :-)

Page 47: The things we don't see – stories of Software, Scala and Akka

Hidden scaladoc features

Akka HTTP 2.4.4

Started using the scaladoc@group feature.

Page 48: The things we don't see – stories of Software, Scala and Akka

Hidden scaladoc features

Akka HTTP 2.4.4

Started using the scaladoc@group feature.

Page 49: The things we don't see – stories of Software, Scala and Akka

Hidden scaladoc features

Akka HTTP 2.4.4

Started using the scaladoc@group feature.

/** * @groupname basic Basic directives * @groupprio basic 10 */ trait BasicDirectives {

/** * @group basic */ def mapInnerRoute(f: Route ⇒ Route): Directive0 = Directive { inner ⇒ f(inner(())) }

/** * @group basic */ def mapRequestContext(f: RequestContext ⇒ RequestContext): Directive0 = mapInnerRoute { inner ⇒ ctx ⇒ inner(f(ctx)) }

// unlocked by: scala -groups

Page 50: The things we don't see – stories of Software, Scala and Akka

Trait representation

Page 51: The things we don't see – stories of Software, Scala and Akka

Trait representation, in Scala 2.11

trait T { def foo = "bar!" }class A extends Tclass B extends T with SomethingElse

Page 52: The things we don't see – stories of Software, Scala and Akka

Trait representation, in Scala 2.11

Page 53: The things we don't see – stories of Software, Scala and Akka

Trait representation, in Scala 2.11

Page 54: The things we don't see – stories of Software, Scala and Akka

./target/scala-2.11/classes/scalapeno/Example$class.class

./target/scala-2.11/classes/scalapeno/Example.class

Trait representation, in Scala 2.11

$ javap -v ./target/scala-2.11/classes/scalapeno/Example.class Classfile target/scala-2.11/classes/scalapeno/Example.class Last modified 25-Apr-2016; size 475 bytes MD5 checksum fe12967b00411cde03bdc57f0ca6869b Compiled from "Example.scala"

public interface scalapeno.Example minor version: 0 major version: 50 flags: ACC_PUBLIC, ACC_INTERFACE, ACC_ABSTRACT {

public abstract java.lang.String newMethod(); descriptor: ()Ljava/lang/String; flags: ACC_PUBLIC, ACC_ABSTRACT }

Page 55: The things we don't see – stories of Software, Scala and Akka

./target/scala-2.11/classes/scalapeno/Example$class.class

./target/scala-2.11/classes/scalapeno/Example.class

Trait representation, in Scala 2.11

$ javap -v ./target/scala-2.11/classes/scalapeno/Example.class Classfile target/scala-2.11/classes/scalapeno/Example.class Last modified 25-Apr-2016; size 475 bytes MD5 checksum fe12967b00411cde03bdc57f0ca6869b Compiled from "Example.scala"

public interface scalapeno.Example minor version: 0 major version: 50 flags: ACC_PUBLIC, ACC_INTERFACE, ACC_ABSTRACT {

public abstract java.lang.String newMethod(); descriptor: ()Ljava/lang/String; flags: ACC_PUBLIC, ACC_ABSTRACT }

$ javap -v ./target/scala-2.11/classes/scalapeno/Example\$class.class Classfile target/scala-2.11/classes/scalapeno/Example$class.class Last modified 01-May-2016; size 450 bytes MD5 checksum ea679b7db9d6275dbe9dff53475000c2 Compiled from "Example.scala"

public abstract class scalapeno.Example$class minor version: 0 major version: 50 flags: ACC_PUBLIC, ACC_SUPER, ACC_ABSTRACT

public static java.lang.String newMethod(scalapeno.Example); descriptor: (Lscalapeno/Example;)Ljava/lang/String; flags: ACC_PUBLIC, ACC_STATIC Code: stack=1, locals=1, args_size=1 0: ldc #9 // String 2: areturn

Page 56: The things we don't see – stories of Software, Scala and Akka

New trait encoding using default methods https://github.com/scala/scala/pull/5003

Trait representation, in Scala 2.12

Page 57: The things we don't see – stories of Software, Scala and Akka

./target/scala-2.12.0-M4/classes/scalapeno/Example.class

Trait representation, in Scala 2.12

$ javap -v ./target/scala-2.12.0-M4/classes/scalapeno/Example.class Classfile scala-2.12.0-M4/classes/scalapeno/Example.class Last modified 25-Apr-2016; size 684 bytes MD5 checksum 07bad6e3b9c5d73b1276e5e7af937e29 Compiled from "Example.scala" public interface scalapeno.Example minor version: 0 major version: 52 flags: ACC_PUBLIC, ACC_INTERFACE, ACC_ABSTRACT { public java.lang.String newMethod(); descriptor: ()Ljava/lang/String; flags: ACC_PUBLIC Code: stack=1, locals=1, args_size=1 0: ldc #12 // String 2: areturn LocalVariableTable: Start Length Slot Name Signature 0 3 0 this Lscalapeno/Example; LineNumberTable: line 4: 0

Page 58: The things we don't see – stories of Software, Scala and Akka

The things we don’t see… in…

Page 59: The things we don't see – stories of Software, Scala and Akka

The things we don’t see… in עכו?

Page 60: The things we don't see – stories of Software, Scala and Akka

The things we don’t see in… The Queen of Laponia?!

Page 61: The things we don't see – stories of Software, Scala and Akka

The things we don’t see… in Akka, the open source project.

Page 62: The things we don't see – stories of Software, Scala and Akka

Messages! Not method calls.

Page 63: The things we don't see – stories of Software, Scala and Akka

Akka Actor in one sentence:

Messaging as a core abstraction, not slap-on afterthought.

Messages! Not method calls.

Akka in one sentence:

A toolkit for building highly distributed and concurrent apps.

Page 64: The things we don't see – stories of Software, Scala and Akka

Messages! Not method calls.

http://c2.com/cgi/wiki?AlanKayOnMessaging

Page 65: The things we don't see – stories of Software, Scala and Akka

Messages! Not method calls.

Waldo J, Wyant G, Wollrath A, Kendall S. A @ Sun Microsystems Laboratories. 1994.Note on Distributed Computing

Page 66: The things we don't see – stories of Software, Scala and Akka

Messages! Not method calls.Methods: // locally:

val value: Long = local.calculateSum(2, 2)// if it’s parallel then we need some middle man to handle concurrency issues hm…

// but remote will have big latency so... val value: Future[Long] = remote.calculateSum(2, 2)// Q1: what is actually put on the wire?// Q2: what about retrying to different host, // - now need magic to handle it...// Q3: can the downstream directly respond to upstream?// - ok, so we could build a special method that does this// Q4: what if the networking breaks...? Do I need to try/catch?

// ... but why, if it could be a simple message send :-)

Page 67: The things we don't see – stories of Software, Scala and Akka

Messages! Not method calls.Methods: // locally:

val value: Long = local.calculateSum(2, 2)// if it’s parallel then we need some middle man to handle concurrency issues hm…

// but remote will have big latency so... val value: Future[Long] = remote.calculateSum(2, 2)// Q1: what is actually put on the wire?// Q2: what about retrying to different host, // - now need magic to handle it...// Q3: can the downstream directly respond to upstream?// - ok, so we could build a special method that does this// Q4: what if the networking breaks...? Do I need to try/catch?

// ... but why, if it could be a simple message send :-)

Messages: // locally:local ! CalculateSum(2, 2)// I'll get a reply in a bit, or I can retry etc etc.// Actor is can be running in parallel, on multi-core etc, same API.// what can happen?// JVM can crash => effectively message loss

// remotelyremote ! CalculateSum(2, 2)// what can happen?// message loss// receiver of the msg can crash... => message loss

Page 68: The things we don't see – stories of Software, Scala and Akka

Messages! Not method calls.

class OneWayProxyActor extends Actor { val downstream: ActorRef = ??? def receive = { case StateQuery(q) => sender() ! run(q)

case req: IncomingRequest => downstream forward transformed(req) } def run(any: Any) = ???}

Page 69: The things we don't see – stories of Software, Scala and Akka

Messages! Not method calls.

What do we not see in these scenarios though?

Page 70: The things we don't see – stories of Software, Scala and Akka

Messages! Not method calls.

What do we not see in these scenarios though?

Local synchronous methods are trivial to trace: that’s what a StackTrace is. But the tradeoff is very high: scalability / resilience – all lost.

Page 71: The things we don't see – stories of Software, Scala and Akka

Messages! Not method calls.

What do we not see in these scenarios though?

Local synchronous methods are trivial to trace: that’s what a StackTrace is. But the tradeoff is very high: scalability / resilience – all lost.

Tracing async / distributed systems is not quite solved yet…

Dapper / Zipkin are not a new things, they’re the beginning of a journey – not the complete solution…

Page 72: The things we don't see – stories of Software, Scala and Akka

Messages! Not method calls.

I can totally do the same with REST HTTP calls!

Page 73: The things we don't see – stories of Software, Scala and Akka

Messages! Not method calls.

I can totally do the same with REST HTTP calls!

Sure you can (201, 204), but: In Akka that’s both default, and exactly 40bytes cheap.

Page 74: The things we don't see – stories of Software, Scala and Akka

Messages! Not exposing state.

Page 75: The things we don't see – stories of Software, Scala and Akka

Encapsulation, so nice…

Messages! Not exposing state.

class ComplexLogic { def add(i: Item): ComplexLogic def apply(): Effect}

Page 76: The things we don't see – stories of Software, Scala and Akka

But it’s “only for testing”!

Messages! Not exposing state.

getter

class ComplexLogic { def add(i: Item): ComplexLogic def apply(): Effect def state: State}

Page 77: The things we don't see – stories of Software, Scala and Akka

Messages! Not exposing state.

val logicActor: ActorRef = ???// no way to access state - for your own good.

logicActor ! Add(item)logicActor ! Add(item)logicActor ! ApplyexpectMsgType[StateAppliedSuccessfully]

Test: yes: behaviour and interactions, not: raw state.

Page 78: The things we don't see – stories of Software, Scala and Akka

“I want my words back.”Roland Kuhn (former Akka Team lead)

Page 79: The things we don't see – stories of Software, Scala and Akka

We want our words back…!

Two examples of name-collisions causing confusion:

“Scheduler”&

“Stream”

Naming is hard…

Page 80: The things we don't see – stories of Software, Scala and Akka

“Scheduler”

Page 81: The things we don't see – stories of Software, Scala and Akka

“Scheduler” - but is it the right one? class CountdownActor extends Actor { val untilEndOfWorld = 127.days // according to mayan prophecy // oh, great, a scheduler! val scheduler = context.system.scheduler scheduler.scheduleOnce(untilEndOfWorld, self, EndOfTheWorld) def receive = { case EndOfTheWorld => println("Aaaaa!!!") } }

http://doc.akka.io/docs/akka/2.4.4/scala/scheduler.html#scheduler-scala

Page 82: The things we don't see – stories of Software, Scala and Akka

“Scheduler” - but is it the right one? class CountdownActor extends Actor { val untilEndOfWorld = 127.days // according to mayan prophecy // oh, great, a scheduler! val scheduler = context.system.scheduler scheduler.scheduleOnce(untilEndOfWorld, self, EndOfTheWorld) def receive = { case EndOfTheWorld => println("Aaaaa!!!") } }

Page 83: The things we don't see – stories of Software, Scala and Akka

Into the Dungeon

Page 84: The things we don't see – stories of Software, Scala and Akka

Into the akka.actor.dungeon

Technically LARS is not in the dungeon,but couldn’t stop myself from making this reference…

Page 85: The things we don't see – stories of Software, Scala and Akka

“Scheduler” - but is it the right one?

Page 86: The things we don't see – stories of Software, Scala and Akka

“Scheduler” - but is it the right one?

Page 87: The things we don't see – stories of Software, Scala and Akka

It’s a plain “Hashed Wheel Timer” though!

Page 88: The things we don't see – stories of Software, Scala and Akka

It’s a plain “Hashed Wheel Timer” though!

Page 89: The things we don't see – stories of Software, Scala and Akka

It’s a plain “Hashed Wheel Timer” though!

Optimised for: • high performance • lockless insertion • O(1) insertion• huge amounts of tasks

// timeouts - on each request, ask timeouts

Original white paper: Hashed and Hierarchical Timing Wheels:https://pdfs.semanticscholar.org/0a14/2c84aeccc16b22c758cb57063fe227e83277.pdf

Page 90: The things we don't see – stories of Software, Scala and Akka

It’s a plain “Hashed Wheel Timer” though!

Optimised for: • high performance • lockless insertion • O(1) insertion• huge amounts of tasks

// timeouts - on each request, ask timeouts

Not for: • preciseness • persistence

Original white paper: Hashed and Hierarchical Timing Wheels:https://pdfs.semanticscholar.org/0a14/2c84aeccc16b22c758cb57063fe227e83277.pdf

Page 91: The things we don't see – stories of Software, Scala and Akka

Akka’s Scheduler fun facts!

• Akka impl. after Netty implementation• Akka impl. improved performance quite a bit• Netty pulled-in the optimisations

(just one of multiple (both way) healthy interactions) => Yay, healthy Open Source ecosystem!

Page 92: The things we don't see – stories of Software, Scala and Akka

Akka’s Scheduler fun facts!Error message you’ll likely never see:LightArrayRevolverScheduler for short: “LARS”

Page 93: The things we don't see – stories of Software, Scala and Akka

Akka’s Scheduler fun facts!Error message you’ll likely never see:LightArrayRevolverScheduler for short: “LARS”

“LARS cannot start new thread, ship’s going down!”

Page 94: The things we don't see – stories of Software, Scala and Akka

Persistent, reliable job scheduler

Ok, so what do we need for it?

Page 95: The things we don't see – stories of Software, Scala and Akka

Persistent, reliable job scheduler: Chronos

Ok, so what do we need?

• Persistence• Replication• Consensus on who executes

Page 96: The things we don't see – stories of Software, Scala and Akka

Persistent, reliable job scheduler: Chronos

Optimised for:

• ”Like CRON, but distributed”• Visibility, including management UI• Retries of failed tasks• Far-out tasks (usually measured in days etc)• Consensus on who executes• Also considered Lightweight• 2k lines of Scala• in it’s context… well, it is!

https://www.youtube.com/watch?v=FLqURrtS8IA

Page 97: The things we don't see – stories of Software, Scala and Akka

Persistent, reliable job scheduler: Chronos

Definitely NOT for:

• millions of tasks inserted per second• to be run in the next second

… that’s what the the Akka scheduler is for!

Page 98: The things we don't see – stories of Software, Scala and Akka

Persistent, reliable job scheduler: Chronos

Definitely NOT for:

• millions of tasks inserted per second• to be run in the next second

… that’s what the the Akka scheduler is for!

Notable mention: Quartz (well known long-term scheduler, with Akka integration and persistence)

Page 99: The things we don't see – stories of Software, Scala and Akka

“Stream”What does it mean?!

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

Page 100: The things we don't see – stories of Software, Scala and Akka

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 101: The things we don't see – stories of Software, Scala and Akka

Suddenly everyone jumped on the word “Stream”.

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

“Streams”

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 / … :-)

Page 102: The things we don't see – stories of Software, Scala and Akka

A core feature not obvious to the untrained eye…!

Akka Streams / HTTP

Quiz time! TCP is a ______ protocol?

Page 103: The things we don't see – stories of Software, Scala and Akka

A core feature not obvious to the untrained eye…!

Akka Streams / HTTP

Quiz time! TCP is a STREAMING protocol!

Page 104: The things we don't see – stories of Software, Scala and Akka

Streaming from Akka HTTPNo demand from TCP

= No demand upstream

= Source won’t generate tweets

Page 105: The things we don't see – stories of Software, Scala and Akka

Streaming from Akka HTTPNo demand from TCP

= No demand upstream

= Source won’t generate tweets

=>Bounded memory stream processing!

Page 106: The things we don't see – stories of Software, Scala and Akka

Binary Compatibility A.K.A. “The thing you think you want, but you actually want much more”

Brian Goetz, Java Language Architect, “Stewardship: The sobering parts” https://www.youtube.com/watch?v=2y5Pv4yN0b0

Page 107: The things we don't see – stories of Software, Scala and Akka

Compatibilities intertwinedScala versioning scheme is:Epoch.Major.Minor

Technically Java too is 1.6, 1.7, 1.8 by the way.

Akka releases closely track Scala versions.

Page 108: The things we don't see – stories of Software, Scala and Akka

Serialization Compatibility

=>

Akka Persistence, (experimental in 2.3.x)

Experimental version accidentally used Java Serialization for Scala’s Option.

Akka now released to both Scala: 2.10 and 2.11.Scala’s Option changed its serialised form slightly.

Akka Persistence is geared towards long-term storage of events – even if experimental, we did not want to block anyone from upgrading to 2.11…!

Page 109: The things we don't see – stories of Software, Scala and Akka

Serialization Compatibility =>

Akka Persistence, in this specific place, provides Serialization compatibility of raw Scalawhere Scala was allowed to break it.

Because we care about you :-)

// If we are allowed to break serialization compatibility of stored snapshots in 2.4 // we can remove this attempt to deserialize SnapshotHeader with JavaSerializer. // Then the class SnapshotHeader can be removed. See issue #16009 val oldHeader = if (readShort(in) == 0xedac) { // Java Serialization magic value with swapped bytes val b = if (SnapshotSerializer.doPatch) patch(headerBytes) else headerBytes serialization.deserialize(b, classOf[SnapshotHeader]).toOption } else None

Page 110: The things we don't see – stories of Software, Scala and Akka

Serialization Compatibility

Plenty of work goes completely un-seen, “if it works as it should, you don’t see it”.

The Scala ecosystem has matured, that many projects really care and tend those aspects.

Page 111: The things we don't see – stories of Software, Scala and Akka

“Why don’t we just magically…”

“In terms of magic in Akka…we prefer to have None of it.”

quoting myself in silly attempt to coin a phrase (-:

Page 112: The things we don't see – stories of Software, Scala and Akka

“Why don’t we just magically…”

Page 113: The things we don't see – stories of Software, Scala and Akka

nums.foldingLeft(0)(_ + _)

Page 114: The things we don't see – stories of Software, Scala and Akka

nums.foldingLeft(0)(_ + _)// Summing up:

Page 115: The things we don't see – stories of Software, Scala and Akka

A hidden force behind all our successes…

Before we sum up:

Page 116: The things we don't see – stories of Software, Scala and Akka

A hidden force behind all our successes…

You!The Scala community as a whole,

thank you!

Before we sum up:

Page 117: The things we don't see – stories of Software, Scala and Akka

Everything is a tradeoff. If you can’t see the tradeoff, look again.

Some things… you don’t need to see, some things you do.

Pick wisely.

Don’t believe in “oh yeah it’s magic”. Seek deeper understanding of things.

Keep learning: “Life is Study!”

Summing up

Page 118: The things we don't see – stories of Software, Scala and Akka

!תודה רבהThanks for listening!

ktoso @ typesafe.com twitter: ktosopl

github: ktosoteam blog: letitcrash.com

home: akka.io

Thus spake the Master Programmer:

“After three days without programming,life becomes meaningless.”

Page 119: The things we don't see – stories of Software, Scala and Akka

Q/A (Now’s the time to ask things!)

ktoso @ lightbend.com twitter: ktosopl

github: ktosoblog: kto.so

home: akka.io