REST no more, use an actor
Transcription
REST no more, use an actor
REST no more, use an actor Johan Janssen, Info Support @johanjanssen42 [email protected] Martin Kanters, Info Support [email protected] Disclaimer: No Lego was harmed beyond repair during the project. CONTENT Why? Architecture Actors Remote actors Shared protocol HTTP vs Actors Conclusion Questions WHY? Why? MINIMAL INGREDIENTS FOR 1 TRAIN ABOUT € 50 Raspberry Pi A+ 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 ARCHITECTURE Architecture LTCC (Angular) RPi-Cam-WebInterface LTCC (Java) (C) DeviceControl SwitchControl (Java) (Java) Infrared RFID Servo (C and LIRC) (C) (Python) LTCC (Angular) LTCC (Scala/Akka) RPi-Cam-WebInterface (C) DeviceControl SwitchControl Leds with Photon (Scala/Akka) (Scala/Akka) (C) Infrared RFID Servo (C and LIRC) (C) (Python) SwitchControl (Pi) Device Control (Pi) LTCC (Laptop / Pi) Lego Train Camera (Pi) Original controls Infrared Sound Camera Switches LTCC APPLICATION ACTORS 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" REMOTE ACTORS AKKA REMOTE ACTOR CALL val workerActorRef = system.actorOf(Props[Worker]) val workerActorRef = system.actorSelection("akka.tcp:// [email protected]:9005 /user/workerActor") 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 } } } SHARED PROTOCOL Messages Actor on JVM 1 Actor on JVM 2 CONCRETE EXAMPLE Actor on laptop Play message Musicservice Actor on Raspberry Pi Server application Raspberry Pi application MessageProtocol EXAMPLE MESSAGE object MusicServiceMessage { case class Play(filename: String) case class MusicList(filenames: List[Song]) } MESSAGE USED BY APPLICATION val actorRef = context.actorSelection( "akka.tcp://[Actorsystem]@ [IP]:[port]/user/musicservice") actorRef ! [packagename].MusicServiceMessage.Play(filename) HTTP VS REMOTE ACTOR ADVANTAGES REMOTE ACTORS No converting to JSON/SOAP More natural programming Concurrent on default Built-in load balancer Built-in circuit breaker ADVANTAGES HTTP Indepedent of technology Loosely coupled FAT JAR (SBT ASSEMBLY) IN MB 25 20 15 10 5 0 Local actor Remote actor Akka HTTP Spring boot GATLING 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 )) } PERFORMANCE TEST SETUP HTTP: /pong HTTP: /ping pong JVM 1 Akka HTTP Akka over TCP: pong HTTP: /ping pong JVM 2 Akka HTTP pong JVM 1 Akka HTTP pong JVM 2 Akka remote actor Mean response time (ms) 120 100 80 60 40 20 0 50 50 no pause 500 Akka HTTP 500 no pause Remote actor 1000 1000 no pause Max response time (ms) 900 800 700 600 500 400 300 200 100 0 50 50 no pause 500 Akka HTTP 500 no pause Remote actor 1000 1000 no pause 99 percentile (ms) 350 300 250 200 150 100 50 0 50 50 no pause 500 Akka HTTP 500 no pause Remote actor 1000 1000 no pause REST is dead, long live remote actors! - Johan Janssen Mean response time (ms) 30 25 20 15 10 5 0 50 50 no pause 500 Remote actor 500 no pause Spring boot 1000 1000 no pause Max response time (ms) 900 800 700 600 500 400 300 200 100 0 50 50 no pause 500 Remote actor 500 no pause Spring boot 1000 1000 no pause 99 percentile (ms) 160 140 120 100 80 60 40 20 0 50 50 no pause 500 Remote actor 500 no pause Spring boot 1000 1000 no pause CONCLUSION The best part!! QUESTIONS? Thank you!! Johan Janssen, Info Support @johanjanssen42 [email protected] Martin Kanters, Info Support [email protected]
Similar documents
The presentation as PDF
The Internet of (Lego) Trains Johan Janssen, Info Support @johanjanssen42 [email protected]
More information