cdays15 - az08 - documentdb: il nosql secondo azure

21
AZ08 – DocumentDB: il NoSql secondo Azure Davide Benvegnù [email protected] - @davidebenvegnu http://blog.dbtek.it/ GetLatestVers ion

Upload: davide-benvegnu

Post on 26-Jul-2015

32 views

Category:

Documents


0 download

TRANSCRIPT

AZ08 – DocumentDB: il NoSql secondo AzureDavide Benvegnù[email protected] - @davidebenvegnuhttp://blog.dbtek.it/

GetLatestVersion

#CDays14 – Milano 25, 26 e 27 Febbraio 2014

Chi Sono?

DAVIDE BENVEGNU’• International Development Manager @ Aruba.it• DBTek.it => Managing Director & CTO @ DBTek Ltd

• Microsoft MVP in Visual Studio ALM• Speaker ad eventi nazionali (CDays, SMAU, Festival ICT…)• Membro DotNetToscana e GetLatestVersion• MSDN – MVA – CodePlex – NuGet – Slideshare…

@davidebenvegnu – blog.dbtek.it

GetLatestVersion

#CDays14 – Milano 25, 26 e 27 Febbraio 2014

Agenda

• Panoramica su DocumentDB• Funzionalità• Struttura ed organizzazione• Stored Procedure, Trigger e Funzioni• Sviluppare in .Net su DocumentDB• Demo

#CDays14 – Milano 25, 26 e 27 Febbraio 2014

DocumentDB

• È un database NoSql documentale• Un altro database NoSQL? Non bastavano quelli esistenti?• NO! Non esiste un servizio come questo

• Fully managed (Saas)• Schema free… con data model JSON• Indici automatici• Supporta l’esecuzione di JavaScript server-side (Stored Procedure,

Trigger e Function)

#CDays14 – Milano 25, 26 e 27 Febbraio 2014

Killer feature

Ma soprattutto:

SELECT * FROM MyCollection

#CDays14 – Milano 25, 26 e 27 Febbraio 2014

Features

• Interrogabile via SDK che con REST API• SDK disponibile per .Net, Node.js, JavaScript, Java e Python

• Multiutente• È possibile creare utenti con SDK o REST API• Ogni user può avere permission diverse

• Livello di consistenza personalizzabile (4 tipi)• Supporta le query parametriche (con @)• Supporta scenari multitenant• Supporta lo sharding e l’elastic scale

#CDays14 – Milano 25, 26 e 27 Febbraio 2014

Struttura

#CDays14 – Milano 25, 26 e 27 Febbraio 2014

Struttura

• Ogni risorsa ha un ID => manuale o automatico

• Ogni risorsa ha un Link univoco

• Per gli attachment sono disponibili al max 2 Gb per account

#CDays14 – Milano 25, 26 e 27 Febbraio 2014

Organizzazione

#CDays14 – Milano 25, 26 e 27 Febbraio 2014

Organizzazione: Da notare

Preview• Max 3 collections• Max 50 (era 5) CU• 1 CU:

• 10 GB SSD• 2000 RU/sec

GA (dal 08/04/2015)• Max 100 collections• Max 100 CU (soft limit)• 1 CU:

• 10 GB SSD• S1: 250 RU/sec• S2: 1000 RU/sec• S3: 2500 RU/sec

CU = Capacity UnitRU = Request Unit

#CDays14 – Milano 25, 26 e 27 Febbraio 2014

Consistenza (Coerenza)

A livello Account (tutti i DB, tutte le collection)

• Assoluta: garanzia totale sulla coerenza, bassa performance• Scritture ok quando commit permanente sulla maggioranza delle repliche• Letture confermate sulla maggioranza delle repliche (no letture parziali)

• Associata: alta latenza in lettura• Definizione di intervalli max di operazioni e secondi

• Sessione: default, media latenza in lettura• Scritture di sessione garantite• Letture di sessione garantite, altre no

• Eventuale: minor garanzia sul dato, max prestazioni• Scritture e letture potenzialmente su repliche diverse

#CDays14 – Milano 25, 26 e 27 Febbraio 2014

REST API

Il servizio espone delle API RESTful con autenticazione HMAC• Anche l’SDK usa queste API• API Base Url

https://{account_name}.documents.azure.com

• Document Path:/dbs/{database_link}/colls/{collection_link}/docs/{document_link}

• Esempio:https://dbtekddb.documents.azure.com/dbs/QDo9AA==/colls/QDo9AM-JWAE=/docs/ ju1TAP hIFAAJAAAAAAAAAA==

#CDays14 – Milano 25, 26 e 27 Febbraio 2014

Stored Procedure, Trigger e Funzioni

• Definiti a Collection level• Scritti in JavaScript, eseguiti server-side• Possono operare su tutti i Document della Collection

• Stored procedure• Trigger

• Eseguiti “Pre” oppure “Post”• Operazioni di Create, Replace e Delete

• Funzioni (UDF)• Funzioni scalari• Invocabili solo dentro le query

#CDays14 – Milano 25, 26 e 27 Febbraio 2014

Un esempio: UDF

• Non esiste l’operatore «like». Quindi?

UserDefinedFunction func1 = new UserDefinedFunction() { Id = "IndexOfString", Body = @"function(t, s) { return t.search (s); }" };

SELECT * FROM c WHERE udf.IndexOfString (c.MyText, “abc123") > -1

#CDays14 – Milano 25, 26 e 27 Febbraio 2014

Sviluppare in .Net su DocumentDB

• Nuget: • Install-Package Microsoft.Azure.Documents.Client -Pre• Versione corrente: 0.9.2-preview• Usa «Newtonsoft.Json»• Supporta LINQ!!!!

• Per la connessione servono:• Endpoint url• Master Key (o Secondary Key o Read only keys…)

• Praticamente tutte le operazioni sono Async• Si basa tutto sul “SelfLink”

#CDays14 – Milano 25, 26 e 27 Febbraio 2014

Sviluppare in .Net su DocumentDB

• Uso con i Mobile Service: https://github.com/Azure/azure-documentdb-net/tree/master/azure-mobileservices-net• Domain manager e controller WebAPI che abilitano l’uso di DocumentDB

come backend

• Attualmente non esiste emulatore o istanza locale

#CDays14 – Milano 25, 26 e 27 Febbraio 2014

demoWebDocDB & DocumentDBBlog

#CDays14 – Milano 25, 26 e 27 Febbraio 2014

Performance Tips

• Usare un DocumentClient singleton

• Cache dei SelfLink di collection e documenti

• Tuning del «page size» (numero di risultati, default 100 o 1MB)

• Tuning del livello di consistenza: ‘< Consistency level’ = ‘< Read latency’

#CDays14 – Milano 25, 26 e 27 Febbraio 2014

Riferimenti

• Documentazione ufficiale di DocumentDB:http://documentdb.com

• WebDocDBhttps://webdocdb.codeplex.com

• Query playground:http://www.documentdb.com/sql/demo

• Channel9:http://channel9.msdn.com/Shows/Data-Exposed/Introduction-to-Azure-DocumentDB

#CDays14 – Milano 25, 26 e 27 Febbraio 2014

Q&A

Tutto il materiale di questa sessione suhttp://www.communitydays.it/

Lascia subito il feedback su questa sessione,potrai essere estratto per i nostri premi!

Seguici suTwitter @CommunityDaysITFacebook http://facebook.com/cdaysit#CDays15