[AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté
-
Upload
microsoft-technet-france -
Category
Technology
-
view
1.688 -
download
0
description
Transcript of [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté
![Page 1: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/1.jpg)
#azurecampCache Distribué
Thomas ContéTechnical EvangelistMicrosoft
24 juin 2014
![Page 2: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/2.jpg)
Pourquoi un cache distribué?
Tour d’horizonZoom sur Redis
Agenda
![Page 3: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/3.jpg)
Pour améliorer les temps de réponse
Pour alléger la charge sur la base de données
Pour alléger la charge sur les frontaux (stockage d’objets coûteux à calculer)
Pour centraliser le stockage des sessions utilisateurs et rendre les frontaux stateless
Pourquoi un cache distribué?
![Page 4: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/4.jpg)
Toutes les options sont détaillées dans cette page:
http://azure.microsoft.com/en-us/pricing/details/cache/
Azure Redis Cache (preview, annoncé à TechEd)
Managed Cache Service
In-Role Cache
Shared Caching Service (deprecated)
Offres partenaires via le Azure Store
Tour d’horizon des options dans Azure
![Page 5: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/5.jpg)
Ancienne offre de cache distribué
Uniquement accessible via l’ancien portail Silverlight
Sera décommissionné le 3 septembre 2014
Si vous l’utilisez: migration vers le Azure Redis Cache ou le Managed Cache Service (dans cet ordre)
Managed Cache Service pour une migration sans modification du code
Shared Caching Service
![Page 6: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/6.jpg)
![Page 7: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/7.jpg)
S’appuie sur AppFabric Cache (nom de code Velocity)
Cache à héberger soi-même via le Azure SDK
Tourne dans des Worker Roles, au tarif habituel
Librairie cliente .NET dans NuGet
Supporte Regions et Tags
Peut être utilisé pour le ASP.NET Session State
Peut être utilisé pour le ASP.NET Page Output Caching
In-Role Cache
![Page 8: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/8.jpg)
Memcache Server Gateway
Activée en ajoutant simplement un endpoint:
<InputEndpoint name="memcache_default" protocol="tcp" port="11211" />
Permet d’accéder au cache depuis des environnements non-.NET (PHP…)
Memcache Client Shim
Package NuGet fonctionnant uniquement en .NET
Utilité limitée (en .NET, préférer le protocole natif)
In-Role Cache: compatibilité memcache
![Page 9: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/9.jpg)
S’appuie sur AppFabric Cache (nom de code Velocity)
Entièrement géré as-a-service
Actuellement en GA
Autorise des tailles de cache jusqu’à 150 Go
Haute disponibilité dans l’édition Premium
Managed Cache Service
![Page 10: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/10.jpg)
Pas d’option pour créer un cache depuis le portail
Utiliser les cmdlets Azure PowerShell:
Add-AzureAccount
New-AzureManagedCache -Name TestCache -Location "North Europe" -Sku Basic -Memory 128MB
Le cache est alors visible depuis le portail
Managed Cache Service: création
![Page 11: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/11.jpg)
Ajout du package NuGet « Windows Azure Cache »
Modification du web.config: ajout de l’URL et de la clé
Attention aux mises à jour du package// Cache client configured by settings in application config file.DataCache defaultCache = new DataCache("default", "default");// Put and retrieve a test object from the default cache.defaultCache.Put("testkey", "testobject");string strObject = (string)defaultCache.Get("testkey");
Managed Cache Service: utilisation
![Page 12: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/12.jpg)
Managed Cache Service: prix
![Page 13: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/13.jpg)
Annoncé à TechEd, actuellement en preview
Création depuis le nouveau-nouveau portail
Redis 2.8 hébergé sur Windows (transparent)
Peut être utilisé pour le ASP.NET Session State (package RedisSessionStateProvider dans NuGet)
Deux options:
• Basic – un seul nœud, plusieurs tailles disponibles
• Standard – deux nœuds Master/Slave, plusieurs tailles
Azure Redis Cache
![Page 14: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/14.jpg)
![Page 15: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/15.jpg)
Accessible uniquement aux US (US East, US West)
Offre Redis et memcached as-a-service
Offre partenaire: redislabs.com
![Page 16: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/16.jpg)
#azurecampZoom sur Redis
![Page 17: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/17.jpg)
Redis is an open source, BSD licensed, advanced key-value store. It is often
referred to as a data structure server since keys can contain strings,
hashes, lists, sets and sorted sets.
![Page 18: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/18.jpg)
Strings Type de base
Hashes Correspondances champvaleur
Lists Liste de chaînes
Sets Ensemble de chaînes uniques
Sorted Sets Ensemble de chaînes triées par score
Structures de données
![Page 19: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/19.jpg)
Utilisation de chaînes comme compteurs: INCR, DECR, DECRBY
Ajouter des éléments à une chaîne: APPEND
Incrémenter une valeur dans un hash: HINCRBY
Ajouter des valeurs à une liste: LPUSH, RPUSH
Etc.
Opération Atomiques
![Page 20: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/20.jpg)
Transactions: MULTI, EXEC/DISCARD
Publish / Subscribe
Lua Scripting: EVAL
Temps d’expiration: EXPIRE, TTL
SDKs pour la plupart des langages
Mais aussi…
![Page 21: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/21.jpg)
Notre implémentation de Redis supporte les connexions SSL et requiert une authentification par mot de passe
Pour pouvoir utiliser SSL, la librairie doit le supporter – voir le billet sur le site de Redislabs:
http://redislabs.com/blog/secure-redis-ssl-added-to-redsmin-and-clients
Comment s’y connecter?
![Page 22: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/22.jpg)
<?phprequire 'vendor/predis/predis/autoload.php';$client = new Predis\Client([ 'scheme' => 'tcp', 'host' => 'tomtest.redis.cache.windows.net', 'port' => '6379', 'password' => ‘(secret_key)']);$client->set('foo', 'bar');$value = $client->get('foo');?>Hello <?= $value ?>
Exemple en PHP
![Page 23: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/23.jpg)
ConnectionMultiplexer connection = ConnectionMultiplexer.Connect("tomtest.redis.cache.windows.net,ssl=true,password=toto");IDatabase cache = connection.GetDatabase();
// Simple put of integral data types into the cachecache.StringSet("key1", "value");cache.StringSet("key2", 25);
// Simple get of data types from the cachestring key1 = cache.StringGet("key1");int key2 = (int)cache.StringGet("key2");
En .NET, utiliser StackExchange.Redis
![Page 24: [AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté](https://reader033.fdocuments.net/reader033/viewer/2022051816/54661fd3af795974338b5130/html5/thumbnails/24.jpg)
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.