rest no more - using actors for the internet of (lego) trains & raspberry pi's

70

Upload: johan-janssen

Post on 22-Jan-2018

56 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 2: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

REST NO MOREUSING ACTORS FOR THE INTERNET OF (LEGO)

TRAINS & RASPBERRY PI’SJohan Janssen, Info Support @johanjanssen42

Page 3: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

Disclaimer: No Lego was harmed beyondrepair during the project.

Page 4: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 5: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

CONTENT

Why?

Getting started

Architecture

Actors

Remote actors

Shared protocol

HTTP vs Actors

Conclusion

Challenges

Questions

Page 6: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

WHY?

Page 7: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

Why?

Page 8: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 9: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

GETTING STARTED

Page 10: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

MINIMAL INGREDIENTS FOR 1 TRAIN ABOUT € 50

Raspberry Pi A+ / Raspberry Pi Zero

Wifi dongleEDUP Ultra-Mini Nano USB 2.0 802.11n

USB battery packAnker® 2. Gen Astro Mini 3200mAh

Infrared transmitterKeyes 38KHz IR Infrared Transmitter Module for

Arduino

Page 11: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 12: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

COMPARISON

Idle (mA) Memory (MB) CPU (Mhz) Size (mm)

RPi A+ 100 256 700 65 *56

RPi Zero 100 512 1000 65 * 30

RPi B+ 200 512 700 85 *56

RPi 2 B 230 1024 4*900 85 *56

Particle Photon

80-100 128KB 120 38 * 21

Page 13: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

ARCHITECTURE

Page 14: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

Architecture

Page 15: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

LTCC

(Angular)

LTCC

(Java)

DeviceControl

(Java)

Infrared

(C and LIRC)

RFID

(C)

SwitchControl

(Java)

Servo

(Python)

RPi-Cam-Web-Interface

(C)

Page 16: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

LTCC

(Angular)

LTCC

(Scala/Akka)

DeviceControl

(Scala/Akka)

Infrared

(C and LIRC)

RFID

(C)

SwitchControl

(Scala/Akka)

Servo

(Python)

Leds with Photon

(C)

RPi-Cam-Web-Interface

(C)

Page 17: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

LTCC (Laptop / Pi)

Lego Train

SwitchControl (Pi) Camera (Pi)

DeviceControl

(Pi)

Page 18: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

Original controls

Page 19: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

Infrared

Page 20: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

Sound

Page 21: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 22: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

Camera

Page 23: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 24: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

Switches

Page 25: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 26: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 27: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 28: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

LTCC APPLICATION

Page 29: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

ACTORS

Page 30: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

AKKA ACTORS

class Worker extends Actor {def receive = {case x =>println(x)

}}

val system = ActorSystem("ExampleActorSystem")

val workerActorRef = system.actorOf(Props[Worker])workerActorRef ! "Hello conference"

Page 31: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

REMOTE ACTORS

Page 32: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 33: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

AKKA REMOTE ACTOR CALL

val workerActorRef = system.actorOf(Props[Worker])

val workerActorRef = system.actorSelection("akka.tcp://[email protected]:9005/user/workerActor")

Page 34: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

AKKA REMOTE ACTOR CONFIGURATION

akka {actor {provider = "akka.remote.RemoteActorRefProvider"

}remote {enabled-transports = ["akka.remote.netty.tcp"]netty.tcp {hostname = "127.0.0.1"port = 9002

}}

}

Page 35: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

SHARED PROTOCOL

Page 36: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

Actor on JVM 1

Actor on JVM 2

Messages

Page 37: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

Actor on laptop

MusicserviceActor on

Raspberry PiPlay message

CONCRETE EXAMPLE

Page 38: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

Serverapplication

MessageProtocol

Raspberry Pi application

Page 39: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

EXAMPLE MESSAGE

object MusicServiceMessage {case class Play(filename: String)case class MusicList(filenames: List[Song])

}

Page 40: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

MESSAGE USED BY APPLICATION

val actorRef = context.actorSelection("akka.tcp://[Actorsystem]@[IP]:[port]/user/musicservice")

actorRef ! [packagename].MusicServiceMessage.Play(filename)

Page 41: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

HTTP VS REMOTE ACTOR

Page 42: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

ADVANTAGES REMOTE ACTORS

No converting to JSON/SOAP

More natural programming

Concurrent on default

Built-in load balancer

Built-in circuit breaker

Page 43: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

ADVANTAGES HTTP

Indepedent of technology

Loosely coupled

Page 44: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

FAT JAR (SBT ASSEMBLY) IN MB

0

5

10

15

20

25

Local actor Remote actor Akka HTTP Spring boot

Page 45: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

GATLING

Page 46: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

class ExampleSimulation extends Simulation {

val scn = scenario("My scenario").repeat(100) {

exec(

http("Ping")

.get("http://localhost:8080/ping")

.check(status.is(200))

).pause(100 millisecond)

}

setUp(scn.inject(

rampUsers(1000) over (10 seconds) // Changing

))

}

Page 47: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

PERFORMANCE TEST SETUP

JVM 1Akka HTTP

HTTP: /ping

pong JVM 2Akka HTTP

HTTP: /pong

pong

JVM 1Akka HTTP

HTTP: /ping

pong JVM 2Akka remote actor

Akka over TCP: pong

pong

Page 48: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

0

10

20

30

40

50

60

50 500 1000

Mean response time (ms)

Akka HTTP Remote actor

Page 49: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

0

100

200

300

400

500

600

700

800

900

50 500 1000

Max response time (ms)

Akka HTTP Remote actor

Page 50: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

GRADUATION STUDENT

REST could handle around 600 users

Remote actors probably around 3300 users

Page 51: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

REST is dead, long live remote actors!

- Johan Janssen

Page 52: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 53: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

0

2

4

6

8

10

12

50 500 1000

Mean response time (ms)

Remote actor Spring boot

Page 54: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

0

50

100

150

200

250

50 500 1000

Max response time (ms)

Remote actor Spring boot

Page 55: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

Challenges

Page 56: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 57: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 58: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 59: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 60: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 61: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 62: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 63: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 64: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 65: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's
Page 66: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

DO IT YOURSELF

https://github.com/johanjanssen/ LCC

LCCInstallScript

Page 67: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

CONCLUSION

Page 68: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

The best part!!

Page 69: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's

QUESTIONS?

Johan Janssen, Info Support @[email protected]

Page 70: Rest no more - Using actors for the internet of (Lego) trains & Raspberry Pi's