USING ACTORS FOR THE INTERNET
OF (LEGO) TRAINS [CON1709]
Johan Janssen, Info Support @johanjanssen42
Disclaimer:
No Lego was harmed beyond
repair during the project.
CONTENT
 Why?
 Getting started
 Architecture
 Actors
 Remote actors
 Shared protocol
 HTTP vs Actors
 Conclusion
 Challenges
 Questions
WHY?
Why?
GETTING STARTED
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
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
ARCHITECTURE
Architecture
LTCC
(Angular)
LTCC
(Java)
DeviceControl
(Java)
Infrared
(C and LIRC)
RFID
(C)
SwitchControl
(Java)
Servo
(Python)
RPi-Cam-Web-
Interface
(C)
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)
LTCC (Laptop / Pi)
LegoTrain
SwitchControl (Pi) Camera (Pi)
Device
Control
(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://
ExampleActorSystem@127.0.0.1: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
Actor on
JVM 1
Actor on
JVM 2
Messages
Actor on
laptop
Musicservice
Actor on
Raspberry PiPlay
message
CONCRETE EXAMPLE
Server
application
MessageProtocol
Raspberry Pi
application
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
0
5
10
15
20
25
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
))
}
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
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
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
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
GRADUATION STUDENT
REST could handle around 600 users
Remote actors probably around 3300 users
REST is dead,
long live remote actors!
- Johan Janssen
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
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
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
Challenges
CONCLUSION
The best part!!
QUESTIONS?
Johan Janssen, Info Support
@johanjanssen42

JavaOne: Using actors for the iInternet of (Lego) Trains [con1709]

Editor's Notes

  • #10 You can also make it a bit bigger with camera, RFID, speaker
  • #11 You could use a Zero or Particle Photon if you only need an IR transmitter. But for video it’s a bit more difficult to use those. Bigger is better for development speed. Smaller is better to put it in a train.
  • #46 This is the test setup for the performance test JVM1 is the frontend, receives http request from client JVM1 sends a request to JVM2 for some further info, after reply from JVM2 it responds to the client. Top is over HTTP Bottom is using Akka remote actors over TCP.
  • #56 Documentation Raspberry USB connector/burned Hardware resources To small children Time
  • #57 Limited resources although quite a lot with the Raspberry Pi. This HD only has 72 MB
  • #58 Broken Raspberry Pi USB connector on A+
  • #59 Lego quite picky with batteries, empty batteries. No easy/cheap way to charge Lego battery box.
  • #60 RFID only works when nearby and when moving slowly
  • #61 WIFI issues
  • #62 No plug and play
  • #63 Lots of options: Raspbian/Arch. Docker, documentation, support, hardware
  • #64 Documentation, wiring etc.
  • #65 To small children
  • #66 Not enough time
  • #67 Sum up Play with lego;s like kids Show and tells for grownups Testdrive akka, experience Come to Jfokus in beaty stockholm … That’s not even the best part. The best part is … Ervaring opgedaan met hardware/IoT Java en Scala/Akka werken blijkbaar prima - Marketing stands op conferenties Scala/Akka ervaring REST vs Remote Actors Ons hier gebracht