rest no more - files.gotocon.com · content why? getting started architecture actors remote actors...

67
REST NO MORE USING ACTORS FOR THE INTERNET OF (LEGO) TRAINS & RASPBERRY PIS Johan Janssen, Info Support @johanjanssen42

Upload: others

Post on 03-Sep-2019

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

REST NO MORE USING ACTORS FOR THE INTERNET OF (LEGO)

TRAINS & RASPBERRY PISJohan Janssen, Info Support @johanjanssen42

Page 2: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

Disclaimer: No Lego was harmed beyondrepair during the project.

Page 3: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

CONTENT

▪ Why?▪ Getting started▪ Architecture▪ Actors▪ Remote actors

▪ Shared protocol▪ HTTP vs Actors▪ Conclusion▪ Challenges▪ Questions

Page 4: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

WHY?

Page 5: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

Why?

Page 6: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges
Page 7: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

GETTING STARTED

Page 8: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

MINIMAL INGREDIENTS FOR 1 TRAIN ABOUT € 50

▪Raspberry Pi A+ / Raspberry Pi Zero▪Wifi dongle▪EDUP Ultra-Mini Nano USB 2.0 802.11n▪USB battery pack▪Anker® 2. Gen Astro Mini 3200mAh▪Infrared transmitter▪Keyes 38KHz IR Infrared Transmitter Module for Arduino

Page 9: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges
Page 10: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

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 11: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

ARCHITECTURE

Page 12: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

Architecture

Page 13: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

LTCC(Angular)

LTCC(Java)

DeviceControl(Java)

Infrared(C and LIRC)

RFID(C)

SwitchControl(Java)

Servo(Python)

RPi-Cam-Web-Interface(C)

Page 14: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

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: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

LTCC (Laptop / Pi)

Lego Train

SwitchControl (Pi) Camera (Pi)

DeviceControl (Pi)

Page 16: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

Original controls

Page 17: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

Infrared

Page 18: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

Sound

Page 19: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges
Page 20: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

Camera

Page 21: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges
Page 22: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

Switches

Page 23: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges
Page 24: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges
Page 25: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges
Page 26: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

LTCC APPLICATION

Page 27: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

ACTORS

Page 28: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

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 29: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

REMOTE ACTORS

Page 30: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges
Page 31: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

AKKA REMOTE ACTOR CALL

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

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

Page 32: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

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: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

SHARED PROTOCOL

Page 34: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

Actor on JVM 1

Actor on JVM 2

Messages

Page 35: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

Actor on laptop

Musicservice Actor on

Raspberry PiPlay message

CONCRETE EXAMPLE

Page 36: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

Serverapplication

MessageProtocol

Raspberry Pi application

Page 37: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

EXAMPLE MESSAGE

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

Page 38: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

MESSAGE USED BY APPLICATION

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

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

Page 39: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

HTTP VS REMOTE ACTOR

Page 40: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

ADVANTAGES REMOTE ACTORS

▪No converting to JSON/SOAP▪More natural programming

▪Concurrent on default▪Built-in load balancer▪Built-in circuit breaker

Page 41: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

ADVANTAGES HTTP

▪Indepedent of technology ▪Loosely coupled

Page 42: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

FAT JAR (SBT ASSEMBLY) IN MB

0

5.5

11

16.5

22

Local actor Remote actor Akka HTTP Spring boot

Page 43: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

GATLING

Page 44: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

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 45: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

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 46: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

Mean response time (ms)

0

12.5

25

37.5

50

50 500 1000

Akka HTTP Remote actor

Page 47: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

Max response time (ms)

0

225

450

675

900

50 500 1000

Akka HTTP Remote actor

Page 48: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

GRADUATION STUDENT

▪REST could handle around 600 users▪Remote actors probably around 3300 users

Page 49: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

REST is dead, long live remote actors!

- Johan Janssen

Page 50: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges
Page 51: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

Mean response time (ms)

0

2.5

5

7.5

10

50 500 1000

Remote actor Spring boot

Page 52: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

Max response time (ms)

0

55

110

165

220

50 500 1000

Remote actor Spring boot

Page 53: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

Challenges

Page 54: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges
Page 55: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges
Page 56: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges
Page 57: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges
Page 58: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges
Page 59: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges
Page 60: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges
Page 61: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges
Page 62: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges
Page 63: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges
Page 64: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

DO IT YOURSELF

▪ https://github.com/johanjanssen/▪ LCC▪ LCCInstallScript

Page 65: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

CONCLUSION

Page 66: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

The best part!!

Page 67: REST NO MORE - files.gotocon.com · CONTENT Why? Getting started Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Challenges

QUESTIONS?Johan Janssen, Info Support @[email protected]