Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

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

Last year this session’s speaker and his colleagues started a new Internet of Things project: Internet of (Lego) Trains. They wanted to figure out if they could use Java or Scala/Akka on IoT hardware. The Lego trains are equipped with a Raspberry Pi, camera, wireless dongle, infrared transmitter, speaker, RFID reader, and battery pack. Next to that are automated switch tracks and cameras, again with the help of Raspberry Pi’s. To control the trains and other parts, they built an actor-based application with Scala, Akka, Akka HTTP, and AngularJS. The session covers when and how to use Akka HTTP and remote actors to create a new generation of applications. It also presents the results of the performance tests they did to compare the two options. A live demo is of course included.

  • Login to see the comments

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

  1. 1. USING ACTORS FOR THE INTERNET OF (LEGO) TRAINS Johan Janssen, Info Support @johanjanssen42
  2. 2. Disclaimer: No Lego was harmed beyond repair during the project.
  3. 3. CONTENT  Why?  Getting started  Architecture  Actors  Remote actors  Shared protocol  HTTP vs Actors  Conclusion  Challenges  Questions
  4. 4. WHY?
  5. 5. Why?
  6. 6. GETTING STARTED
  7. 7. MINIMAL INGREDIENTS FOR 1TRAIN 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 InfraredTransmitter Module for Arduino
  8. 8. 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 Odroid C1 325 1024 4*1500 85 *56 Particle Photon 80-100 128KB 120 38 * 21
  9. 9. ARCHITECTURE
  10. 10. Architecture
  11. 11. LTCC (Angular) LTCC (Java) DeviceControl (Java) Infrared (C and LIRC) RFID (C) SwitchControl (Java) Servo (Python) RPi-Cam-Web- Interface (C)
  12. 12. 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)
  13. 13. LTCC (Laptop / Pi) LegoTrain SwitchControl (Pi) Camera (Pi) Device Control (Pi)
  14. 14. Original controls
  15. 15. Infrared
  16. 16. Sound
  17. 17. Camera
  18. 18. Switches
  19. 19. LTCC APPLICATION
  20. 20. ACTORS
  21. 21. 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"
  22. 22. REMOTE ACTORS
  23. 23. AKKA REMOTE ACTOR CALL val workerActorRef = system.actorOf(Props[Worker]) val workerActorRef = system.actorSelection("akka.tcp:// ExampleActorSystem@127.0.0.1:9005 /user/workerActor")
  24. 24. 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 } } }
  25. 25. SHARED PROTOCOL
  26. 26. Actor on JVM 1 Actor on JVM 2 Messages
  27. 27. Actor on laptop Musicservice Actor on Raspberry PiPlay message CONCRETE EXAMPLE
  28. 28. Server application MessageProtocol Raspberry Pi application
  29. 29. EXAMPLE MESSAGE object MusicServiceMessage { case class Play(filename: String) case class MusicList(filenames: List[Song]) }
  30. 30. MESSAGE USED BY APPLICATION val actorRef = context.actorSelection( "akka.tcp://[Actorsystem]@ [IP]:[port]/user/musicservice") actorRef ! [packagename].MusicServiceMessage.Play(filename)
  31. 31. HTTP VS REMOTE ACTOR
  32. 32. ADVANTAGES REMOTE ACTORS  No converting to JSON/SOAP  More natural programming  Concurrent on default  Built-in load balancer  Built-in circuit breaker
  33. 33. ADVANTAGES HTTP  Indepedent of technology  Loosely coupled
  34. 34. FAT JAR (SBT ASSEMBLY) IN MB 0 5 10 15 20 25 Local actor Remote actor Akka HTTP Spring boot
  35. 35. GATLING
  36. 36. 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 )) }
  37. 37. PERFORMANCETEST SETUP JVM 1 Akka HTTP HTTP: /ping pong JVM 2 Akka HTTP HTTP: /pong pong JVM 1 Akka HTTP HTTP: /ping pong JVM 2 Akka remote actor Akka over TCP: pong pong
  38. 38. 0 20 40 60 80 100 120 50 50 no pause 500 500 no pause 1000 1000 no pause Mean response time (ms) Akka HTTP Remote actor
  39. 39. 0 100 200 300 400 500 600 700 800 900 50 50 no pause 500 500 no pause 1000 1000 no pause Max response time (ms) Akka HTTP Remote actor
  40. 40. 0 50 100 150 200 250 300 350 50 50 no pause 500 500 no pause 1000 1000 no pause 99 percentile (ms) Akka HTTP Remote actor
  41. 41. GRADUATION STUDENT REST could handle around 600 users Remote actors probably around 3300 users
  42. 42. REST is dead, long live remote actors! - Johan Janssen
  43. 43. 0 5 10 15 20 25 30 50 50 no pause 500 500 no pause 1000 1000 no pause Mean response time (ms) Remote actor Spring boot
  44. 44. 0 100 200 300 400 500 600 700 800 900 50 50 no pause 500 500 no pause 1000 1000 no pause Max response time (ms) Remote actor Spring boot
  45. 45. 0 20 40 60 80 100 120 140 160 50 50 no pause 500 500 no pause 1000 1000 no pause 99 percentile (ms) Remote actor Spring boot
  46. 46. Challenges
  47. 47. DO ITYOURSELF  https://github.com/johanjanssen/  LCC  LCCInstallScript
  48. 48. CONCLUSION
  49. 49. The best part!!
  50. 50. QUESTIONS? Johan Janssen, Info Support @johanjanssen42

×