78
Mathieu ANCELIN Alexandre DELEGUE

I don't always write reactive application but when I do, it run on raspberry pi

Embed Size (px)

DESCRIPTION

This talk show how we made a reactive application on thta run on raspberry pi.

Citation preview

Page 1: I don't always write reactive application but when I do, it run on raspberry pi

Mathieu ANCELIN Alexandre DELEGUE

Page 2: I don't always write reactive application but when I do, it run on raspberry pi

Mathieu ANCELIN

• Développeur @SERLI

• Scala, Java, web & OSS

• ReactiveCouchbase, Weld-OSGi, Weld, etc ...

• Poitou-Charentes JUG

• Membre de l’expert group CDI 1.1 (JSR-346)

• Membre de l’expert group OSGi Enterprise

• @TrevorReznik

Page 3: I don't always write reactive application but when I do, it run on raspberry pi

Alexandre DELEGUE

• Développeur @ SERLI

• Java

• Scala

• Web

• spring, play, …

• @chanksleroux

Page 4: I don't always write reactive application but when I do, it run on raspberry pi

SERLI

• Société de conseil et d’ingénierie du SI

• 75 personnes

• 80% de business Java

• Contribution à des projets OSS

• 10% de la force de travail sur l’OSS

• Membre de l’EG JSR-346

• Membre de l’OSGi Alliance

• www.serli.com @SerliFr

Page 5: I don't always write reactive application but when I do, it run on raspberry pi

Les technologies présentées sont inspirées de technologies réelles!

Les applications qui en découlent sont fictives!Toute ressemblance avec des applications existantes n’est

que fortuite!

Page 6: I don't always write reactive application but when I do, it run on raspberry pi

ALEX

Page 7: I don't always write reactive application but when I do, it run on raspberry pi
Page 8: I don't always write reactive application but when I do, it run on raspberry pi

www.amazing.com

Page 9: I don't always write reactive application but when I do, it run on raspberry pi

Mobile infrastructure

Page 10: I don't always write reactive application but when I do, it run on raspberry pi

Mobile infrastructure

Raspberry pi x 7

Routeur wifi

Switch

Page 11: I don't always write reactive application but when I do, it run on raspberry pi

Demo

Page 12: I don't always write reactive application but when I do, it run on raspberry pi

Résister à la charge

Page 13: I don't always write reactive application but when I do, it run on raspberry pi

Résister aux pannes

Page 14: I don't always write reactive application but when I do, it run on raspberry pi

Absorber une hausse de trafic

Page 15: I don't always write reactive application but when I do, it run on raspberry pi

Approche classique

Page 16: I don't always write reactive application but when I do, it run on raspberry pi

Monolithique

bouquetin

faisan

???

hornbill

Page 17: I don't always write reactive application but when I do, it run on raspberry pi

Latence

Page 18: I don't always write reactive application but when I do, it run on raspberry pi

Bloquant

Page 19: I don't always write reactive application but when I do, it run on raspberry pi

Charge

Page 20: I don't always write reactive application but when I do, it run on raspberry pi

Scalabilité

Page 21: I don't always write reactive application but when I do, it run on raspberry pi

Reactive Manifesto

Page 22: I don't always write reactive application but when I do, it run on raspberry pi

Reactive Manifesto

Page 23: I don't always write reactive application but when I do, it run on raspberry pi

Reactive manifesto

• react to event : the event-driven nature enables the following qualities

• react to load : focus on scalability by avoiding contention on shared resources

• react to failure : build resilient systems with the ability to recover at all levels

• react to user : honor response time guarantees regardless of load

Page 24: I don't always write reactive application but when I do, it run on raspberry pi

Scalable / React to load

Page 25: I don't always write reactive application but when I do, it run on raspberry pi
Page 26: I don't always write reactive application but when I do, it run on raspberry pi

Overview

Frontend

Cart

Identity

Backend

Page 27: I don't always write reactive application but when I do, it run on raspberry pi

Datas

Page 28: I don't always write reactive application but when I do, it run on raspberry pi

Mini / Micro Services

• Une application par domaine fonctionnel

• store-frontend : présentation du contenu

• store-identity : authentification / gestion de compte

• store-cart : panier

• store-backend : administration du site

Page 29: I don't always write reactive application but when I do, it run on raspberry pi

Stateless

• Chaque application est stateless

• aucune donnée n’est stockée dans l’application (pas de cache, pas de fichier …)

• Chaque application peut être clonée

Session

Page 30: I don't always write reactive application but when I do, it run on raspberry pi

Frontend

}- 100 % html - Indexation par les

moteurs de recherche - stateless - une url == un contenu

Page 31: I don't always write reactive application but when I do, it run on raspberry pi

Limiter la charge

Page 32: I don't always write reactive application but when I do, it run on raspberry pi

Cache

Frontend

Cache Browser CDN nginx/http varnish

Page 33: I don't always write reactive application but when I do, it run on raspberry pi

Optimisations

Cache +

recherche full text

Base de données ?

Page 34: I don't always write reactive application but when I do, it run on raspberry pi

Modèle de données

{ id: "04abe480-2521-11e4-acde-f7b0d99b8321", label: "Product number 1", description: "A description …", image: "image.jpeg", price: 1.5, fragments: [{ type: "search", html: " <div >...</div>" },{ type: "cart", html: " <tr >...</tr>" } ]}

}}

Données indexées pour la

recherche

HTML pré-généré

Page 35: I don't always write reactive application but when I do, it run on raspberry pi

Recherche

GET /products?q=some%20text Frontend Search some text

- Concat fragments - Include into main

template

Page 36: I don't always write reactive application but when I do, it run on raspberry pi

Créer / mettre à jour

BackendFrontendUpdateProduct ProductUpdated EventSource

ProductUpdated

Page 37: I don't always write reactive application but when I do, it run on raspberry pi

Resilient / react to failure

Page 38: I don't always write reactive application but when I do, it run on raspberry pi
Page 39: I don't always write reactive application but when I do, it run on raspberry pi
Page 40: I don't always write reactive application but when I do, it run on raspberry pi

Infrastructure

Identity

Frontend

Identity Backend

Cart

Cart

Frontend

Identity

Backend

Page 41: I don't always write reactive application but when I do, it run on raspberry pi

Infrastructure

Identity

Frontend

Identity Backend

Cart

Cart

Frontend

Identity

Backend

Page 42: I don't always write reactive application but when I do, it run on raspberry pi

Infrastructure

Identity

Frontend

Identity Backend

Cart

Cart

Frontend

Identity

Backend

Page 43: I don't always write reactive application but when I do, it run on raspberry pi

Infrastructure

Identity

Frontend

Identity Backend

Cart

Cart

Frontend

Identity

Backend

Page 44: I don't always write reactive application but when I do, it run on raspberry pi

Demo !

Let It Crash !!!

Page 45: I don't always write reactive application but when I do, it run on raspberry pi

Event-driven / react to event

Page 46: I don't always write reactive application but when I do, it run on raspberry pi
Page 47: I don't always write reactive application but when I do, it run on raspberry pi

Akka

• Akka

• Modèle acteur

• Un acteur = Une entité statefull

• Communication entre acteurs par messages (même à distance)

• Un acteur peut créer/détruire des enfants

• Un acteur peut surveiller d’autres acteurs

• Plus de problèmes de concurrence, asynchrone par nature

• Résistant aux pannes

• Java or Scala

Page 48: I don't always write reactive application but when I do, it run on raspberry pi

Akka

Actor

Actor

Actor

Actor

messages ActorFils

Fils

Fils

Fils

ActorFils

ActorFils

Server 1

Server 2

messages

Page 49: I don't always write reactive application but when I do, it run on raspberry pi

Akka messages

import akka.actor.{Props, ActorSystem, ActorLogging, Actor}case class Greeting(who: String) class GreetingActor extends Actor with ActorLogging { def receive = { case Greeting(who) ⇒ log.info("Hello " + who) }} val system = ActorSystem("MySystem") val greeter = system.actorOf(Props[GreetingActor], name = "greeter") greeter ! Greeting("Charlie Parker")

Page 50: I don't always write reactive application but when I do, it run on raspberry pi

Play 2

• Framework web

• java or scala

• Support pour les websocket et le server sent event

• Asynchrone

• pré-requis pour une application orientée événements

Page 51: I don't always write reactive application but when I do, it run on raspberry pi

Play async

case class ListProductsQuery()class ProductView extends Actor { override def receive: Receive = { case ListProductsQuery() => models.Product.list() pipeTo sender() }} !class ProductsController extends Controller { private def listProducts(): Future[List[models.Product]] = { (Actors.productView() ? ListProductsQuery()).mapTo[List[models.Product]] } def index() = Action.async { listProducts().map(products => Ok(views.html.index(products))) }}

Page 52: I don't always write reactive application but when I do, it run on raspberry pi

Messages

Frontend

Cart

Identity

Backend

CheckAuth

UpdateProduct

OrderCartAddProductToCart

ProductAddedToCart

ProductUpdated

WebSocket

Messages Akka

Server sent event

Page 53: I don't always write reactive application but when I do, it run on raspberry pi

Cluster

• Utilisation de Akka-cluster

• Librairie permettant de former un cluster de systèmes d’acteurs

• simple service d’adhésion

• tolérant aux pannes

• décentralisé (P2P, gossip)

• pas de SPOF

• pas de SPOB

• détection des pannes

Page 54: I don't always write reactive application but when I do, it run on raspberry pi

Cluster services• Librairie de découverte de services distribués

• Exposition descripteurs de services (URL, protocole, version, nom)

• Repose sur les memberships du cluster Akka

• Clients de services

• HTTP, Akka, Thrift, Memcached …

• Petits plus

• Monitoring

• Load balancing (pas très intelligent)

• Retry with exponential back off

Page 55: I don't always write reactive application but when I do, it run on raspberry pi

Cluster services

Client spécifique

Client Générique Monitoring

Load balancer +

retry

Service instance 1

Service instance 1

Service instance 1

Page 56: I don't always write reactive application but when I do, it run on raspberry pi

Cluster services

Client spécifique

Client Générique Monitoring

Load balancer +

retry

Service instance 1

Service instance 1

Service instance 1

Page 57: I don't always write reactive application but when I do, it run on raspberry pi

Cluster services

Client spécifique

Client Générique Monitoring

Load balancer +

retry

Service instance 1

Service instance 1

Service instance 1

Page 58: I don't always write reactive application but when I do, it run on raspberry pi

CQRS & EventSourcing

• Command Query Responsibility Segregation

• Command : Enregistrement

• Query : Lecture

• 2 modèles distincts

• Séparation des services

• Event sourcing

• Stockage des événements

Page 59: I don't always write reactive application but when I do, it run on raspberry pi

Persistence

JournalEvent source processor

eventcommand event event

View 1

View 2

View 3

Page 60: I don't always write reactive application but when I do, it run on raspberry pi

Exemple

AddProductToCart

Journal

ProductAddedToCart ProductAddedToCart ProductAddedToCartWebSocket

ActorProducts

ViewsProducts Processor

Page 61: I don't always write reactive application but when I do, it run on raspberry pi

Responsive

Page 62: I don't always write reactive application but when I do, it run on raspberry pi
Page 63: I don't always write reactive application but when I do, it run on raspberry pi

Frontend réactif

Page 64: I don't always write reactive application but when I do, it run on raspberry pi

Demo !

Realtime web!

Page 65: I don't always write reactive application but when I do, it run on raspberry pi

Et les perfs dans tout ca ?

Page 66: I don't always write reactive application but when I do, it run on raspberry pi

Les chiffres

367 998 456 756

Page 67: I don't always write reactive application but when I do, it run on raspberry pi

Les chiffres

367 998 456 756 €

Page 68: I don't always write reactive application but when I do, it run on raspberry pi

200 clients

Page 69: I don't always write reactive application but when I do, it run on raspberry pi

400 clients

Page 70: I don't always write reactive application but when I do, it run on raspberry pi

Metrics everywhere !!!

Page 71: I don't always write reactive application but when I do, it run on raspberry pi

Les problèmes rencontrés

Page 72: I don't always write reactive application but when I do, it run on raspberry pi

Nginx / mongo …

Page 73: I don't always write reactive application but when I do, it run on raspberry pi

Cassandra

Page 74: I don't always write reactive application but when I do, it run on raspberry pi

Bench web socket

Page 75: I don't always write reactive application but when I do, it run on raspberry pi

Configuration akka-cluster

Page 76: I don't always write reactive application but when I do, it run on raspberry pi

Conclusion

Page 77: I don't always write reactive application but when I do, it run on raspberry pi

scala

Page 78: I don't always write reactive application but when I do, it run on raspberry pi

This is the end ...