NoSQL: Azure Table Storage & MongoDB Alternativas y escenarios de uso NoSQL @erincon Click icon to add picture Click icon to add picture Click icon to add picture Eladio Rincón Director Relacional MCT, MVP SQL Server @augurarte Click icon to add picture Click icon to add picture Click icon to add picture Miguel López Director Cloud | [email protected]MCT, MCPD, MCTS, MCP 1
http://summit.solidq.com En un track de motor relacional una sesión NoSQL puede resultar extraña. En esta sesión mostraremos cómo funcionan estas tecnologías con dos aproximaciones diferentes: almacenamiento clave-valor en la nube (Azure) y almacenamiento orientado a documento (MongoDB). Evaluaremos y debatiremos sobre las dos tecnologías y su uso adecuado. Presentación realizada por Miguel López y Eladio Rincón.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
NoSQL: Azure Table Storage & MongoDBAlternativas y escenarios de uso NoSQL
@erincon
Click icon to add pictureClick icon to add pictureClick icon to add picture
Eladio Rincón
Director Relacional
MCT, MVP SQL Server
@augurarte
Click icon to add pictureClick icon to add pictureClick icon to add picture
1. Bases de datos relacionales y NoSQL2. Microsoft Azure Table Storage– Fundamentos MSATS– Diseño de NoSQL con MSATS– Programación del modelo
3. MongoDB– Fundamentos– Diseño de NoSQL con MongoDB– Programación del modelo
4. Escenarios5. Evaluación de costes
NoSQL: Azure Table Storage & MongoDB
BDD Relacionales y NoSQLAlmacenamiento de table de Azure (MSATS)MongoDBEscenariosCostes
5
BDD Relacionales y NoSQL
Las BDD Relacionales lideran el conjunto de sistemas de almacenamiento transaccional, escritura atómica, indexación de columnas, optimización de consultas y lenguaje de consulta declarative orientado a conjuntos.
Las BDD NoSQL se emplean de forma generalizada en sitios Web de tipo social masivamente accedidos y que necesitan escalar de forma intensiva, donde la característica principal son conjuntos de datos simples (frente a consultas complejas)
BDD Relacionales y NoSQLAlmacenamiento de table de Azure (MSATS)MongoDBEscenariosCostes
15
Almacenamiento de table Azure
Windows Azure Table ServiceWindows Azure tablesDesigning Windows Azure TablesImplementing Windows Azure TablesQuerying Windows Azure TablesAccessing table storageTable Storage Security– Set container permissions.– Use Shared Access Signatures (SAS)– Stored Access Policies
16
Cuentas de almacenamiento MSA
User creates a globally unique storage account nameChoose the primary location to host storage accountThree regions:– “North Central US”, “South Central US”– “North Europe”, “Europe West”– “South East Asia”, “East Asia”
Table Service:
http://myaccount.table.core.windows.net
17
DEMOAprovisionamiento de una cuenta de almacenamiento de Azure
Icon de tecnologíaIcon de tecnologíaIcon de tecnología
18
Características MSATS• Tabla de almacenamiento de Azure• Colección de entidades (parejas clave, valor)• La entidad tiene una clave principal y un conjunto
aleatorio no definido (schema-less) de propiedades. • PartitionKey (Particionamiento / distribución de carga / escalado)
• RowKey (conjuntos de filas relacionadas en una partición)
• TimeStamp (Sólo lectura, TS creación)
• Una propiedad es un par de nombre/valor (con tipo) similar a una columna
• MSATS no fuerza la creación o validación de esquema• El desarrollador necesitará implementar un esquema
Entities are the basic data item stored in a tableCollections of properties that are name value pairs. Each entity has 3 fixed properties called PartitionKey, RowKey and Timestamp. If we were to map this to concepts in a conventional database system, an entity is analogous to a row and property is analogous to a column.An entity can have up to 255 – 3 properties = 252 (3 system properties are reserved). 1 Entity = 1 MB of data (Maximum)
Use Microsoft.WindowsAzure.StorageClient. There are several ways of creating tables. Initialize tables once: for example using session or Application start events.Use CreateCloudTableClient to interact with WATSFor example, to create a table called ‘Products’:
using Microsoft.WindowsAzure;using Microsoft.WindowsAzure.StorageClient;
var clAccount;clAccount = CloudStorageAccount.FromConfigurationSettings(“ProductStorage") var tableClient = clAccount.CreateCloudTableClient();tableClient.CreateTableIfNotExists(“Products”)
37
Entidades: Operaciones CRUD
Configurar las entidades (modelo de clases)Configurar un DataContext
38
Configuración de las entidadesClass modeling
39
Operaciones CRUD
Context class is required in .NET to access the WAT using WCF Data Services and the correspondent entity (GE06LDataEntry).
Setting up data context
namespace GE06L_Data {
public class GE06LDataContext : TableServiceContext {public GE06LDataContext(string baseAddress, Microsoft.WindowsAzure.StorageCredentials credentials) : base(baseAddress, credentials) {}
public IQueryable<GE06LEntry> GE06LEntry {get { return this.CreateQuery<GE06LEntry>(“GE06LEntry");} } }}
40
Entities CRUD operationsList, Add, Update
// List (read) operation for GE06LEntry entitiespublic IEnumerable<GE06LEntry> GetGE06LEntries() {var results = from g in this.context.GE06LEntry where g.PartitionKey == DateTime.UtcNow.ToString("MMddyyyy") select g; return results; }
// Add operation for GE06LEntry entities
public void AddGE06LEntry(GE06LEntry newItem) {this.context.AddObject(“GE06LEntry", newItem);this.context.SaveChanges(); }
// Update operation for GE06LEntry entities
public void UpdateFileURL(string partitionKey, string rowKey, string fileUrl) { var results = from g in this.context.GE06LEntry where g.PartitionKey == partitionKey && g.RowKey == rowKey
from movie in context.CreateQuery<Movie>(tableName)
where
movie.PartitionKey == "Action" &&
movie.RowKey.CompareTo("Alien") >= 0 &&
movie.RowKey.CompareTo("Terminator") <= 0 &&
movie.IsFavorite
select movie
);
43
Consultar MSATSRange Queries - Partition Range Scan
var q = (
from movie in context.CreateQuery<Movie>(tableName)
where
movie.PartitionKey == "Action" &&
movie.RowKey.CompareTo("Alien") >= 0 &&
movie.RowKey.CompareTo("Terminator") <= 0 &&
movie.IsFavorite
select movie
);
44
Consultar MSATSFull Table Scan
var q = (from movie in context.CreateQuery<Movie>(tableName)
select movie );
var q = (from movie in context.CreateQuery<Movie>(tableName)
where movie.PartitionKey.CompareTo("Action") != 0
select movie );
var q = (
from movie in context.CreateQuery<Movie>(tableName)
where movie.IsFavorite select movie); var q =
(from movie in context.CreateQuery<Movie>(tableName)
where movie.RowKey.CompareTo("Sh") >= 0 &&
movie.RowKey.CompareTo("Si") < 0
select movie );
45
DEMOProgramación de MSATS
Icon de tecnologíaIcon de tecnologíaIcon de tecnología
NoSQL: Azure Table Storage & MongoDB
BDD Relacionales y NoSQLAlmacenamiento de table de Azure (MSATS)MongoDBEscenariosCostes
47
MongoDBMotivación
• ¿”Problemas” en RDBMs tradicionales?• Transaciones• JOINs
• Prescindimos de ellos• Transacciones a nivel de documento• No dejamos hacer JOINs
48
MongoDB
Unidad de Información es el Documento
49
MongoDB: Otro Paradigma
• Filosofía Schema On-Read• El Esquema es importante (aunque laxo)• En algún momento necesitas “modelar”• Antes o después
• Modelos Mapeados en Memoria• “Cerveza con alcohol vs cerveza sin
alcohol” by Garrigós• Importante arquitectura x64!
50
MongoDB: Conceptos Clave
• Aunque veamos JSON, almacenado en binario – BSON
• Consola de administración JavaScript y JSON• Varios GUI tipo SSMS• Drivers de Mongo para facilitar desarrollo
• Driver para C# y usar LINQ• Modelos de persistencia para mapeo• MongoRepository
• Sharding y Replicasets
51
DEMOMongoDB en Azure con correos electrónicos
Icon de tecnologíaIcon de tecnologíaIcon de tecnología
NoSQL: Azure Table Storage & MongoDB
BDD Relacionales y NoSQLAlmacenamiento de table de Azure (MSATS)MongoDBEscenariosCostes
53
Aplicaciones altamente escalables que necesitan consultas sencillas y rápidas• ONU, datos georeferenciados, info calculada• Energética, metadatos• BIG Data, datos temporales/sensores• Información social / redes sociales• Aplicaciones de localización de correos,
direcciones, etc.
Escenarios
NoSQL: Azure Table Storage & MongoDB
BDD Relacionales y NoSQLAlmacenamiento de table de Azure (MSATS)MongoDBEscenariosCostes
55
Costes
Microsoft Azure Table Storage
MongoDB on Azure
56
NoSQL: Azure Table Storage & MongoDB
Bases de datos relacionales y NoSQLMicrosoft Azure Table Storage– Fundamentos MSATS– Diseño de NoSQL con MSATS– Programación del modelo
MongoDB– Fundamentos – Diseño de NoSQL con MongoDB– Programación del modelo
EscenariosEvaluación de costes
Si quieres disfrutar de las mejores sesiones de nuestros mentores de España y Latino