euregjug: using actors for the internet of (lego) trains

69
USING ACTORS FOR THE INTERNET OF (LEGO) TRAINS Johan Janssen, Info Support @johanjanssen42

Upload: johan-janssen

Post on 10-Feb-2017

63 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: EuregJUG: Using actors for the internet of (lego) trains

USING ACTORS FOR THE INTERNET OF (LEGO) TRAINS

Johan Janssen, Info Support @johanjanssen42

Page 2: EuregJUG: Using actors for the internet of (lego) trains

Disclaimer: No Lego was harmed beyondrepair during the project.

Page 3: EuregJUG: Using actors for the internet of (lego) trains

CONTENT

Why? Getting started Architecture Actors Remote actors

Shared protocol HTTP vs Actors Conclusion Challenges Questions

Page 4: EuregJUG: Using actors for the internet of (lego) trains

WHY?

Page 5: EuregJUG: Using actors for the internet of (lego) trains

Why?

Page 6: EuregJUG: Using actors for the internet of (lego) trains
Page 7: EuregJUG: Using actors for the internet of (lego) trains

GETTING STARTED

Page 8: EuregJUG: Using actors for the internet of (lego) trains

MINIMAL INGREDIENTS FOR 1 TRAIN ABOUT € 50Raspberry Pi A+ / Raspberry Pi ZeroWifi 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 9: EuregJUG: Using actors for the internet of (lego) trains
Page 10: EuregJUG: Using actors for the internet of (lego) trains

COMPARISONIdle (mA) Memory

(MB)CPU (Mhz) Size (mm)

RPi A+ 100 256 700 65 *56 RPi Zero 100 512 1000 65 * 30RPi B+ 200 512 700 85 *56RPi 2 B 230 1024 4*900 85 *56Odroid C1

325 1024 4*1500 85 *56

Particle Photon

80-100 128KB 120 38 * 21

Page 11: EuregJUG: Using actors for the internet of (lego) trains

ARCHITECTURE

Page 12: EuregJUG: Using actors for the internet of (lego) trains

Architecture

Page 13: EuregJUG: Using actors for the internet of (lego) trains

LTCC(Angular)

LTCC(Java)

DeviceControl(Java)

Infrared(C and LIRC)

RFID(C)

SwitchControl(Java)

Servo(Python)

RPi-Cam-Web-Interface(C)

Page 14: EuregJUG: Using actors for the internet of (lego) trains

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 15: EuregJUG: Using actors for the internet of (lego) trains

LTCC (Laptop / Pi)

Lego Train

SwitchControl (Pi) Camera (Pi)

DeviceControl (Pi)

Page 16: EuregJUG: Using actors for the internet of (lego) trains

Original controls

Page 17: EuregJUG: Using actors for the internet of (lego) trains

Infrared

Page 18: EuregJUG: Using actors for the internet of (lego) trains

Sound

Page 19: EuregJUG: Using actors for the internet of (lego) trains
Page 20: EuregJUG: Using actors for the internet of (lego) trains

Camera

Page 21: EuregJUG: Using actors for the internet of (lego) trains
Page 22: EuregJUG: Using actors for the internet of (lego) trains

Switches

Page 23: EuregJUG: Using actors for the internet of (lego) trains
Page 24: EuregJUG: Using actors for the internet of (lego) trains
Page 25: EuregJUG: Using actors for the internet of (lego) trains
Page 26: EuregJUG: Using actors for the internet of (lego) trains

LTCC APPLICATION

Page 27: EuregJUG: Using actors for the internet of (lego) trains

ACTORS

Page 28: EuregJUG: Using actors for the internet of (lego) trains

AKKA ACTORSclass Worker extends Actor { def receive = { case x => println(x) }}

val system = ActorSystem("ExampleActorSystem")

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

Page 29: EuregJUG: Using actors for the internet of (lego) trains

REMOTE ACTORS

Page 30: EuregJUG: Using actors for the internet of (lego) trains
Page 31: EuregJUG: Using actors for the internet of (lego) trains

AKKA REMOTE ACTOR CALL

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

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

Page 32: EuregJUG: Using actors for the internet of (lego) trains

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 33: EuregJUG: Using actors for the internet of (lego) trains

SHARED PROTOCOL

Page 34: EuregJUG: Using actors for the internet of (lego) trains

Actor on JVM 1

Actor on JVM 2

Messages

Page 35: EuregJUG: Using actors for the internet of (lego) trains

Actor on laptop

Musicservice Actor

on Raspberry

PiPlay

message

CONCRETE EXAMPLE

Page 36: EuregJUG: Using actors for the internet of (lego) trains

Serverapplication

MessageProtocol

Raspberry Pi application

Page 37: EuregJUG: Using actors for the internet of (lego) trains

EXAMPLE MESSAGE

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

Page 38: EuregJUG: Using actors for the internet of (lego) trains

MESSAGE USED BY APPLICATION

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

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

Page 39: EuregJUG: Using actors for the internet of (lego) trains

HTTP VS REMOTE ACTOR

Page 40: EuregJUG: Using actors for the internet of (lego) trains

ADVANTAGES REMOTE ACTORS

No converting to JSON/SOAPMore natural programming

Concurrent on defaultBuilt-in load balancerBuilt-in circuit breaker

Page 41: EuregJUG: Using actors for the internet of (lego) trains

ADVANTAGES HTTP

Indepedent of technology Loosely coupled

Page 42: EuregJUG: Using actors for the internet of (lego) trains

FAT JAR (SBT ASSEMBLY) IN MB

Local actor Remote actor Akka HTTP Spring boot0

5

10

15

20

25

Page 43: EuregJUG: Using actors for the internet of (lego) trains

GATLING

Page 44: EuregJUG: Using actors for the internet of (lego) trains

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) // Optional }

setUp(scn.inject( rampUsers(1000) over (10 seconds) // Changing ))}

Page 45: EuregJUG: Using actors for the internet of (lego) trains

PERFORMANCE TEST SETUP

JVM 1Akka HTTP

HTTP: /ping

pong JVM 2Akka HTTP

HTTP: /pong

pong

JVM 1Akka HTTP

HTTP: /ping

pongJVM 2

Akka remote actor

Akka over TCP: pong

pong

Page 46: EuregJUG: Using actors for the internet of (lego) trains

50 50 no pause 500 500 no pause 1000 1000 no pause0

20

40

60

80

100

120

Mean response time (ms)

Akka HTTP Remote actor

Page 47: EuregJUG: Using actors for the internet of (lego) trains

50 50 no pause 500 500 no pause 1000 1000 no pause0

100

200

300

400

500

600

700

800

900

Max response time (ms)

Akka HTTP Remote actor

Page 48: EuregJUG: Using actors for the internet of (lego) trains

50 50 no pause 500 500 no pause 1000 1000 no pause0

50

100

150

200

250

300

350

99 percentile (ms)

Akka HTTP Remote actor

Page 49: EuregJUG: Using actors for the internet of (lego) trains

GRADUATION STUDENT

REST could handle around 600 usersRemote actors probably around 3300 users

Page 50: EuregJUG: Using actors for the internet of (lego) trains

REST is dead, long live remote actors!

- Johan Janssen

Page 51: EuregJUG: Using actors for the internet of (lego) trains
Page 52: EuregJUG: Using actors for the internet of (lego) trains

50 50 no pause 500 500 no pause 1000 1000 no pause0

5

10

15

20

25

30

Mean response time (ms)

Remote actor Spring boot

Page 53: EuregJUG: Using actors for the internet of (lego) trains

50 50 no pause 500 500 no pause 1000 1000 no pause0

100

200

300

400

500

600

700

800

900

Max response time (ms)

Remote actor Spring boot

Page 54: EuregJUG: Using actors for the internet of (lego) trains

50 50 no pause 500 500 no pause 1000 1000 no pause0

20

40

60

80

100

120

140

160

99 percentile (ms)

Remote actor Spring boot

Page 55: EuregJUG: Using actors for the internet of (lego) trains

Challenges

Page 56: EuregJUG: Using actors for the internet of (lego) trains
Page 57: EuregJUG: Using actors for the internet of (lego) trains
Page 58: EuregJUG: Using actors for the internet of (lego) trains
Page 59: EuregJUG: Using actors for the internet of (lego) trains
Page 60: EuregJUG: Using actors for the internet of (lego) trains
Page 61: EuregJUG: Using actors for the internet of (lego) trains
Page 62: EuregJUG: Using actors for the internet of (lego) trains
Page 63: EuregJUG: Using actors for the internet of (lego) trains
Page 64: EuregJUG: Using actors for the internet of (lego) trains
Page 65: EuregJUG: Using actors for the internet of (lego) trains
Page 66: EuregJUG: Using actors for the internet of (lego) trains

DO IT YOURSELF https://github.com/johanjanssen/

LCC LCCInstallScript

Page 67: EuregJUG: Using actors for the internet of (lego) trains

CONCLUSION

Page 68: EuregJUG: Using actors for the internet of (lego) trains

The best part!!

Page 69: EuregJUG: Using actors for the internet of (lego) trains

QUESTIONS?Johan Janssen, Info Support @johanjanssen42