55
13.12.2011 Dipl.-Inf. (FH) Johannes Hoppe M.Sc. Johannes Hofmeister aus der Praxis

2011-12-13 NoSQL aus der Praxis

Embed Size (px)

DESCRIPTION

Vortrag für die .NET User Group Frankfurt

Citation preview

Page 1: 2011-12-13 NoSQL aus der Praxis

13.12.2011 Dipl.-Inf. (FH) Johannes Hoppe M.Sc. Johannes Hofmeister

aus der Praxis

Page 2: 2011-12-13 NoSQL aus der Praxis

Johannes Hoppe .NET Webentwickler

www.johanneshoppe.de

Page 3: 2011-12-13 NoSQL aus der Praxis

Johannes Hofmeister .NET Domänenexperte

www.twitter.com/pro_cessor

Page 4: 2011-12-13 NoSQL aus der Praxis

Not only SQL

01

Page 5: 2011-12-13 NoSQL aus der Praxis

2002 2004 2006 2008 2010 2012

Daten

Page 6: 2011-12-13 NoSQL aus der Praxis

Daten › Facebook hat 60k Server (2010)

› Google hat 450k Server (2006)

› Microsoft: hat 100k - 500k Server (seit Azure)

Facebook Server Footprint

Page 7: 2011-12-13 NoSQL aus der Praxis

Trend 1: increasing data sizes

Trend 2: more connectedness (“web 2.0”)

Trend 3: more individualization (fever structure)

Page 8: 2011-12-13 NoSQL aus der Praxis
Page 9: 2011-12-13 NoSQL aus der Praxis

verteilte und horizontale Skalierbarkeit

kein relationales Datenmodell (kein SQL)

schemafrei / schwache Schemarestriktionen

anderes Konsistenzmodell

Page 10: 2011-12-13 NoSQL aus der Praxis

Scale-up Vertikale Skalierung

Server auf mehr Leistungsfähigkeit trimmen

Page 11: 2011-12-13 NoSQL aus der Praxis

Scale-out horizontale Skalierung

Einfügen von Nodes (Rechnerknoten)

Page 12: 2011-12-13 NoSQL aus der Praxis

Schemafrei kein ALTER TABLE

kein Wartungsfenster *

Datenversionierung im Code!

* morgens ausschlafen

Page 13: 2011-12-13 NoSQL aus der Praxis

Anforderungen

an ein verteiltes System

Consistency Konsistenz

AvailabilityVerfügbarkeit

Partition

Tolerance Ausfalltoleranz

Page 14: 2011-12-13 NoSQL aus der Praxis

CAP Theorem › 2000: E. Brewer, N. Lynch

› You can satisfy

at most 2 out of the 3 requirements

Page 15: 2011-12-13 NoSQL aus der Praxis

Consistency › The system is in a consistent state after an operation

› All clients see the same data

› Strong consistency (ACID)

vs. eventual consistency (BASE)

ACID: Atomicity, Consistency, Isolation and Durability

BASE: Basically Available, Soft state, Eventually consistent

Page 16: 2011-12-13 NoSQL aus der Praxis

Availability › System is “always on”, no downtime

› Node failure tolerance

– all clients can find some available replica

› Software/hardware upgrade tolerance

Page 17: 2011-12-13 NoSQL aus der Praxis

Partition tolerance › System continues to function even when

split into disconnected subsets (network disruption)

› Not only for reads, but writes as well

Page 18: 2011-12-13 NoSQL aus der Praxis

“Drum prüfe,

wer sich ewig bindet.” Friedrich Schiller

Page 19: 2011-12-13 NoSQL aus der Praxis

Kategorisierung › Key-Value stores

› Document stores

› Wide Column stores

› Graphdatenbanken

› weitere

Page 20: 2011-12-13 NoSQL aus der Praxis

MongoDB

02

Page 21: 2011-12-13 NoSQL aus der Praxis

NoSQL

MongoDB Quick Reference Cards

http://www.10gen.com/reference

Page 22: 2011-12-13 NoSQL aus der Praxis

“Deployment” › Standardverzeichnis erstellen: c:\data\db

› Server-Start: mongod.exe

› Shell: mongo.exe

Page 23: 2011-12-13 NoSQL aus der Praxis
Page 24: 2011-12-13 NoSQL aus der Praxis

BSON Master/Slave

JavaScript C# Driver

Sharding GNU AGPL

Page 25: 2011-12-13 NoSQL aus der Praxis

JSON BSON

All JSON documents are stored in a binary

format called BSON. BSON supports a

richer set of types than JSON. http://bsonspec.org

Page 26: 2011-12-13 NoSQL aus der Praxis

CRUD – Create

(in the shell)

› db.people.save({name: 'Smith', age: 30});

See how the save command works:

› db.foo.save

Page 27: 2011-12-13 NoSQL aus der Praxis

CRUD – Create …with a bit JavaScript

for(i=0; i<1000; i++) {

['quiz', 'essay', 'exam'].forEach(function(name) {

var score = Math.floor(Math.random() * 50) + 50;

db.scores.save({student: i, name: name, score: score});

});

}

db.scores.count();

Page 28: 2011-12-13 NoSQL aus der Praxis

CRUD – Read Queries are specified using a document-style syntax!

› db.scores.find();

› db.scores.find({score: 50});

› db.scores.find({score: {"$gte": 70}});

› db.scores.find({score: {"$gte": 70}});

Page 29: 2011-12-13 NoSQL aus der Praxis

CRUD – Update

› db.people.update({name: 'Smith'}, {'$set': {interests: []}});

› db.people.update({name: 'Smith'},

{'$push': {interests: ['chess']}});

Page 30: 2011-12-13 NoSQL aus der Praxis

CRUD – Delete

› db.dropDatabase();

› db.foo.drop();

› db.foo.remove();

Page 31: 2011-12-13 NoSQL aus der Praxis

“Map Reduce is the Uzi of aggregation

tools. Everything described with count,

distinct and group can be done with

MapReduce, and more.” Kristina Chadorow, Michael Dirolf in MongoDB – The Definitive Guide

Page 32: 2011-12-13 NoSQL aus der Praxis

https://webnote.codeplex.com

Page 33: 2011-12-13 NoSQL aus der Praxis

RavenDB

03

Page 34: 2011-12-13 NoSQL aus der Praxis

NoSQL

Raven Db Documentation – All you need to know

http://beta.ravendb.net/docs

Page 35: 2011-12-13 NoSQL aus der Praxis

JSON Transactional

LINQ Lucene

100% .NET AGPL / dual

Page 36: 2011-12-13 NoSQL aus der Praxis

RavenDb › Written by Oren Eini aka Ayende Rahien

› Hibernating Rhinos

› Rhino Mocks & Rhino.ServiceBus

› Written in C#

Page 37: 2011-12-13 NoSQL aus der Praxis

Deployment › Get it via NuGet

› Change defaults in Raven.Server.exe.config

› It’s safe by default

› Just run the Raven.Server.exe in the /server/ folder

Page 39: 2011-12-13 NoSQL aus der Praxis

Safe by default › Useful defaults

› E.g. Limited page size – No Accidental SELECT *

› ACID

› Client / Server

› Cross shard

Page 40: 2011-12-13 NoSQL aus der Praxis

Units › Documents

› Collections

› Indexes

› Attachments

Page 41: 2011-12-13 NoSQL aus der Praxis

Designed to “just work” › Schema Free

› Hardly any mapping required

› dynamic (C# 4) yields great power

Page 42: 2011-12-13 NoSQL aus der Praxis

Designed to “just work” › Sleek Client API

› Fluent API

› Unit of Work Pattern

› Extensible – Plugin Support

Page 43: 2011-12-13 NoSQL aus der Praxis

Makes developers happy › Testable

› Interfaces all over

› In-Memory Database

› Extensible – Plugin Support

Page 44: 2011-12-13 NoSQL aus der Praxis

APIs › Native .NET Client API

› HTTP API (Pseudo REST)

Page 45: 2011-12-13 NoSQL aus der Praxis

Indexes › Written as Linq Queries

› Indexed with Lucene .NET

› Lucene Syntax for querying

Page 46: 2011-12-13 NoSQL aus der Praxis

“While being RESTful is a goal of the

HTTP API, it is secondary to the goal of

exposing easy to use and powerful

functionality” Ayende Rahien on the HTTP API - http://ravendb.net/documentation/docs-http-api-restful

Page 47: 2011-12-13 NoSQL aus der Praxis

HTTP API › Caching

› E-Tags

› Lucene Queries possible

C:\>curl -X GET http://localhost:8080/docs/Categories/1 -i HTTP/1.1 200 OK Content-Type: application/json; charset=utf-8 ETag: 00000000-0000-0200-0000-000000000004 { "Name" : "Normal Importance", "Color" : "green" }

Page 48: 2011-12-13 NoSQL aus der Praxis

Lucene Style Queries

Lucene Style var notes = session.Advanced .LuceneQuery<Note>() .Where(“Category:Important") .ToArray();

Classic Linq Style var notes = session .Query<Note>() .Where(n => n.Category == “Important") .ToArray();

Page 49: 2011-12-13 NoSQL aus der Praxis

Tabellen Dokumente

04

Page 50: 2011-12-13 NoSQL aus der Praxis

Key and Index Strategies

05

Page 51: 2011-12-13 NoSQL aus der Praxis
Page 52: 2011-12-13 NoSQL aus der Praxis

FRAGEN?

Page 53: 2011-12-13 NoSQL aus der Praxis

https://webnote.codeplex.com/

Page 54: 2011-12-13 NoSQL aus der Praxis

Vielen Dank! Johannes Hoppe

Johannes Hofmeister

Page 55: 2011-12-13 NoSQL aus der Praxis

Bildnachweise

Ausgewählter Ordner © Spectral-Design – Fotolia.com

Warnhinweis-Schild © Sascha Tiebel – Fotolia.com

Liste abhaken © Dirk Schumann – Fotolia.com

Stressed businessman © Selecstock – Fotolia.com