24. Architecture
Redis
Air/Hotel/Cars/Ac
Redis
Web Resa/Users
Web Redis
HTTP Web Content
HTTPS
LB Web
ZapTravel
vendredi 22 mars 13
25. Architecture
Redis
Air/Hotel/Cars/Ac
Web
Redis
Web Resa/Users
Web Redis
HTTP
HTTPS
redis Web Content
LB Web
ZapTravel
vendredi 22 mars 13
26. Cas d’usage
Donne moi le label qui correspond à originId =380
ZapTravel
vendredi 22 mars 13
27. Cas d’usage
Donne moi le label qui correspond à originId =380
def getSlug(originId: Long): Option[String] = Redis.pool.withClient
{
client =>
Option(client.hget("Url:From:Rev", originId.toString))
}
ZapTravel
vendredi 22 mars 13
28. Cas d’usage
Donne moi le label qui correspond à originId =380
def getSlug(originId: Long): Option[String] = Redis.pool.withClient
{
client =>
Option(client.hget("Url:From:Rev", originId.toString))
}
ZapTravel
vendredi 22 mars 13
29. Cas d’usage
Donne moi le label qui correspond à originId =380
def getSlug(originId: Long): Option[String] = Redis.pool.withClient
{
client =>
Option(client.hget("Url:From:Rev", originId.toString))
}
Driver Sedis https://github.com/pk11/sedis ZapTravel
vendredi 22 mars 13
36. La Tour Eiffel
1. Charger du JSON à partir de Redis
2. Interpréter et retourner un objet
PointOfInterest
ZapTravel
vendredi 22 mars 13
37. HGET Pois:PoisHash 52511
{"name":"Eiffel
Tower","address":"","latitude":"48.8582493546","longitude":"2.2945117950","website":"www.tour-
eiffel.fr","rank":3,"photo":{"r":"eiffel-tower-paris-france","k":"6b56","e":"jpg","w":2406,"h":
1600,"a":"Mirari Erdoiza","l":"http://www.fotopedia.com/items/anboto-RiKxAA3gE6I"},"sentences":
{"gbs":[{"d":"The Eiffel Tower is one of the most famous monuments in the world (324 metres, 10,100
tonnes).","a":"Paris","l":"http://www.paris.com/paris_landmarks/monuments/
eiffel_tower_paris"},{"d":"This is without doubt one of the most recognizable structures in the
world.","a":"Frommers","l":"http://www.frommers.com/destinations/paris/A25288.html"},{"d":"If
the Statue of Liberty is emblematic of New York, Big Ben is London, and the Kremlin is Moscow, then the
Eiffel Tower is the symbol of Paris.","a":"Fodors","l":"http://www.fodors.com/world/europe/
france/paris/review-97417.html"},{"d":"When it was built for the 1889 Exposition Universelle (World
Fair), marking the centenary of the Revolution, the Tour Eiffel faced massive opposition from Paris'
artistic and literary elite.","a":"Lonely Planet","l":"http://www.lonelyplanet.com/france/paris
/sights/famous-landmark/eiffel-tower"}],"tips":[{"d":"It's pretty
high!.","a":"annawelford","l":"http://www.lonelyplanet.com/france/paris/sights/famous-
landmark/eiffel-tower","s":"Lonely Planet"},{"d":"Bigger than you think.","a":"anomolly","l":"http:/
/www.lonelyplanet.com/france/paris/sights/famous-landmark/eiffel-tower","s":"Lonely
Planet"},{"d":"Overcrowded.","a":"anshjain","l":"http://www.lonelyplanet.com/france/paris/
sights/famous-landmark/eiffel-tower","s":"Lonely Planet"},{"d":"The restaurant on the first floor is
an amazing experience!.","a":"ansofie","l":"http://www.lonelyplanet.com/france/paris/sights
/famous-landmark/eiffel-tower","s":"Lonely Planet"}]},"tags":["Landmark","Memorials/
Monuments","Sights","Famous landmark"]}
vendredi 22 mars 13
38. Play 2.0
• Définir une case class POI
• Définir un Format[POI]
• Ecrire la fonction pour lire et parser le
JSON
Note : Play 2.1 apporte un nouveau parser JSON plus simple
vendredi 22 mars 13
39. Play 2.0
case class POI(name: String,
address: String,
latitude: String,
longitude: String,
website: Option[String],
photo: Option[SightPhoto] = None,
sentences: Sentences,
tags: Option[List[String]])
POI = Point of Interest = notre Tour Eiffel
vendredi 22 mars 13
44. Aller sur Redis
def allOrigins: List[Origin] =
Redis.pool.withClient {
client =>
// ...
// ...
}
Modèle
vendredi 22 mars 13
45. Préparer une liste
def allUrlOrigins: Seq[(String, String)] =
{
Origin.allOrigins.map{
origin =>
(origin.slug, origin.label)
}.sortBy(_._2)
}
Contrôleur
vendredi 22 mars 13
46. Envoyer la liste au
template
Code dans la page HTML
<label for="location">Your travel origin is :</label>
@select( userForm("originCity"),
FolioCriteria.allUrlOrigins ,
'_label -> "Travel from origin",
'_showConstraints -> false
)
Vue
vendredi 22 mars 13
54. Play2 et Sécurité
• Simple
• Composable
• Facile à tester
vendredi 22 mars 13
55. Optimiser
l’indexation et le
référencement
vendredi 22 mars 13
56. Indexation et
référencement
• URLs propres et pondérées
• Mots clés
• Liens et Sitemap
• Microformat (Hotel, Avion, Lieux)
• Contenu non répété
vendredi 22 mars 13
59. URL
/from-boston/quality
GET /$origin<from-(.*)>/:classifier
controllers.Frontoffice.home(origin:String, classifier: String)
http://www.zaptravel.com/romance/weekend-deals/from-paris/to-athens/
12-Apr-2013-to-14-Apr-2013/elite-athens-greece
vendredi 22 mars 13
60. Play2
• La séparation entre la partie routage et
la partie contrôleur permet de créer des
URLs «propres»
vendredi 22 mars 13
61. Sitemap
• Déclarer la table des matières de son
site
• Optimise le référencement
• Permet de mettre en cache les pages
curl http://www.zaptravel.com/sitemap.xml
vendredi 22 mars 13
72. Eviter de recharger la
même page,
utilisez code 304 NotModified
Note: @rosstuck a fait une session sur HTTP à Confoo mercredi dernier
vendredi 22 mars 13
74. Exemple sur /from-paris/quality
Navigateur Play2
OK
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
ETag: 11299930771
Cache-Control: max-age=600, s-maxage=600, must-revalidate
Content-Length: 103586
...
...
ce n’est pas une erreur
vendredi 22 mars 13
75. Recharge /from-paris/quality
GET /from-paris/quality
If-None-Match: 112999307771
Navigateur Play2
304 Not Modified
Content-Length: 0
vendredi 22 mars 13
76. Optimisation 1
• Evitez de faire travailler votre serveur
pour rien
• Déterminez des ETags «métiers»
• Attention à la gestion du cache et des
serveurs mandataires.
vendredi 22 mars 13
77. Optimisation 2
Faire de la gestion de cache applicative
vendredi 22 mars 13
79. 2 types de cache
Cache technique type
Cache de Play2 ou Redis
Varnish
- Code applicatif
- Process à part
- utilise la mémoire
- Cache HTTP
de Play2 ou Redis
vendredi 22 mars 13
80. 2 types de cache
Cache technique type
Varnish
• Facile à installer
• Evite de solliciter
Play2
• Scalable
• Configurable
vendredi 22 mars 13
81. 2 types de cache
Cache applicatif Play2/
Redis
• Prend en compte le
métier
• Permet de garder les
pages «authentifiées»
• Pas aussi performant
que la solution
Varnish
vendredi 22 mars 13
82. Sur Zaptravel
• Page d’accueil
optimisé avec Cache
de Play2
• Page Folio, section
top Deal avec cache
Play2
• Page Deal, cache
avec Redis
vendredi 22 mars 13
83. Et pour terminer
Play2
Architecture Web
Apprentissage
Tests unitaires
Asynchrone (Enumeratee,
Iteratee)
vendredi 22 mars 13
84. Merci
https://joind.in/7951
@nmartignole
vendredi 22 mars 13