euregjug: using actors for the internet of (lego) trains
TRANSCRIPT
![Page 1: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/1.jpg)
USING ACTORS FOR THE INTERNET OF (LEGO) TRAINS
Johan Janssen, Info Support @johanjanssen42
![Page 2: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/2.jpg)
Disclaimer: No Lego was harmed beyondrepair during the project.
![Page 3: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/3.jpg)
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](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/4.jpg)
WHY?
![Page 5: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/5.jpg)
Why?
![Page 6: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/6.jpg)
![Page 7: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/7.jpg)
GETTING STARTED
![Page 8: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/8.jpg)
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](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/9.jpg)
![Page 10: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/10.jpg)
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](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/11.jpg)
ARCHITECTURE
![Page 12: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/12.jpg)
Architecture
![Page 13: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/13.jpg)
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](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/14.jpg)
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](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/15.jpg)
LTCC (Laptop / Pi)
Lego Train
SwitchControl (Pi) Camera (Pi)
DeviceControl (Pi)
![Page 16: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/16.jpg)
Original controls
![Page 17: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/17.jpg)
Infrared
![Page 18: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/18.jpg)
Sound
![Page 19: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/19.jpg)
![Page 20: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/20.jpg)
Camera
![Page 21: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/21.jpg)
![Page 22: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/22.jpg)
Switches
![Page 23: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/23.jpg)
![Page 24: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/24.jpg)
![Page 25: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/25.jpg)
![Page 26: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/26.jpg)
LTCC APPLICATION
![Page 27: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/27.jpg)
ACTORS
![Page 28: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/28.jpg)
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](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/29.jpg)
REMOTE ACTORS
![Page 30: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/30.jpg)
![Page 31: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/31.jpg)
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](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/32.jpg)
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](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/33.jpg)
SHARED PROTOCOL
![Page 34: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/34.jpg)
Actor on JVM 1
Actor on JVM 2
Messages
![Page 35: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/35.jpg)
Actor on laptop
Musicservice Actor
on Raspberry
PiPlay
message
CONCRETE EXAMPLE
![Page 36: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/36.jpg)
Serverapplication
MessageProtocol
Raspberry Pi application
![Page 37: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/37.jpg)
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](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/38.jpg)
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](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/39.jpg)
HTTP VS REMOTE ACTOR
![Page 40: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/40.jpg)
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](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/41.jpg)
ADVANTAGES HTTP
Indepedent of technology Loosely coupled
![Page 42: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/42.jpg)
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](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/43.jpg)
GATLING
![Page 44: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/44.jpg)
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](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/45.jpg)
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](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/46.jpg)
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](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/47.jpg)
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](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/48.jpg)
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](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/49.jpg)
GRADUATION STUDENT
REST could handle around 600 usersRemote actors probably around 3300 users
![Page 50: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/50.jpg)
REST is dead, long live remote actors!
- Johan Janssen
![Page 51: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/51.jpg)
![Page 52: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/52.jpg)
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](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/53.jpg)
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](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/54.jpg)
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](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/55.jpg)
Challenges
![Page 56: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/56.jpg)
![Page 57: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/57.jpg)
![Page 58: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/58.jpg)
![Page 59: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/59.jpg)
![Page 60: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/60.jpg)
![Page 61: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/61.jpg)
![Page 62: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/62.jpg)
![Page 63: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/63.jpg)
![Page 64: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/64.jpg)
![Page 65: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/65.jpg)
![Page 66: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/66.jpg)
DO IT YOURSELF https://github.com/johanjanssen/
LCC LCCInstallScript
![Page 67: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/67.jpg)
CONCLUSION
![Page 68: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/68.jpg)
The best part!!
![Page 69: EuregJUG: Using actors for the internet of (lego) trains](https://reader036.vdocuments.net/reader036/viewer/2022062522/589cd0391a28ab43388b51a1/html5/thumbnails/69.jpg)
QUESTIONS?Johan Janssen, Info Support @johanjanssen42