polyglot persistance con postgresql, couchdb, mongodb, redis e orientdb
DESCRIPTION
Pirma parte del seminario su NoSQL al DiTeDi di Udine del 15/12/2012. Affrontato il caso di studio di un'architettura enterprise, basata su datastore relazionali (PostgreSQL) e non (CouchDB, MongoDB, Redis e OrientDB).TRANSCRIPT
![Page 1: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/1.jpg)
Polyglot Persistance Esempio di architettura basata
su PostgreSQL, CouchDB, MongoDB, Redis e OrientDB
DiTeDi, Udine - Italia 15-12-2012
![Page 2: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/2.jpg)
@maraspin
![Page 3: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/3.jpg)
@stefanovalle
![Page 4: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/4.jpg)
http://www.mvassociati.it/
![Page 5: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/5.jpg)
IL CONTESTO
![Page 6: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/6.jpg)
L’OBIETTIVO
![Page 7: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/7.jpg)
![Page 8: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/8.jpg)
DATI IN TEMPO REALE
![Page 9: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/9.jpg)
REPERIMENTO FEEDBACK IMMEDIATO
![Page 10: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/10.jpg)
MENO HARDWARE NEGLI HOTEL
![Page 11: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/11.jpg)
Partiamo da stack LAMP/LAPP
11
![Page 12: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/12.jpg)
PostgreSQL Backend
12
![Page 13: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/13.jpg)
Chi usa PostgreSQL?
13
![Page 14: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/14.jpg)
Gestione "meta" dati di: • Hotel • Applicazioni • Configurazioni • Personalizzazioni • Utenti • ACL • RELAZIONI tra essi
14
![Page 15: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/15.jpg)
Modello relazionale
15
Film
TitoloNome CategoriaRating CategoriaAnnoVisioniGradimentiVoto
![Page 16: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/16.jpg)
Diamo un’occhio ai dati…
16
E se voglio cambiare rating per i drammatici?
![Page 17: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/17.jpg)
Normalizzazione
17
![Page 18: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/18.jpg)
Schema aggiornato
18
![Page 19: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/19.jpg)
Come sono memorizzati i dati
19
![Page 20: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/20.jpg)
E se vogliamo un report?
20
SELECT film_normal.* , categoria.* FROM film_normal JOIN categoria on categoria.id = film_normal.categoria_id
![Page 21: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/21.jpg)
JOIN: Operazione impegnativa
21
X
Morale: considerare sempre i benefici della normalizzazione. Ci torniamo tra poco!
![Page 22: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/22.jpg)
Indici
22
EXPLAIN ANALIZE SELECT …
O(N) -> O(log N)
![Page 23: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/23.jpg)
PostgreSQL vs MySQL
23
Idea: SELECT titolo, max(visioni) FROM film;
Qual’è il film più visto?
![Page 24: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/24.jpg)
MySQL
24
SELECT titolo, max(visioni) FROM film;
![Page 25: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/25.jpg)
PostgreSQL
25
SELECT titolo, max(visioni) FROM film;
SELECT titolo, max(visioni) FROM film;
SQL error: ERROR: column "film.titolo" must appear in the GROUP BY clause or be used in an aggregate function at character 8 In statement: SELECT titolo, max(visioni) FROM film;
![Page 26: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/26.jpg)
PostgreSQL
26
SELECT titolo, max(visioni) FROM film;
SELECT titolo, max(visioni) FROM film;
SQL error: ERROR: column "film.titolo" must appear in the GROUP BY clause or be used in an aggregate function at character 8 In statement: SELECT titolo, max(visioni) FROM film;
![Page 27: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/27.jpg)
27
Disclaimer: Ciò non significa che non utilizziamo anche MySQL in determinati contesti
Ocio però!
![Page 28: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/28.jpg)
Perchè cio?
28
Risultato Casuale
SELECT titolo, max(visioni) FROM film;
![Page 29: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/29.jpg)
Tabelle Sparse
29
![Page 30: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/30.jpg)
Possibile Soluzione
30
CREATE VIEW film AS SELECT titolo, anno, visioni FROM film_provider1 UNION SELECT titolo, anno, visioni FROM film_provider2;
![Page 31: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/31.jpg)
POI SU UPDATE…
![Page 32: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/32.jpg)
Alternativa
32
![Page 33: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/33.jpg)
Supporto per Ereditarietà
33
CREATE TABLE film ( id integer NOT NULL, titolo character varying(50), anno integer, visioni integer ); CREATE TABLE film_provider1 ( gradimenti integer ) INHERITS (film); CREATE TABLE film_provider2 ( voto integer ) INHERITS (film);
![Page 34: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/34.jpg)
Comportamento dell’Ereditarietà
34
select * from film; select * from film_provider1;
![Page 35: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/35.jpg)
Write Ahead Log (Journal) • Apri il Log • Scrivici informazioni tipo “Questo dato va
qui (offset)” • Scrivi il file • Tenta il salvataggio su disco (fsync) • Modifica i dati • Segna sul Log che le operazioni sono
state compiute
35
http://www.depesz.com/2011/07/14/write-ahead-log-understanding-postgresql-conf-checkpoint_segments-checkpoint_timeout-checkpoint_warning/
![Page 36: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/36.jpg)
Durevolezza dei Dati
36
![Page 37: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/37.jpg)
MVCC
37
Supporto AutoVacuum
![Page 38: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/38.jpg)
Replicazione con LOG – 8.4
38
![Page 39: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/39.jpg)
Replicazione Streaming - 9.0
39
![Page 40: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/40.jpg)
Replicazione Sincrona - 9.1
40
![Page 41: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/41.jpg)
Failover
41
![Page 42: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/42.jpg)
Cosa portare a casa: • Solido e Affidabile (Ingres 1974) • Potenti strumenti di programmazione
(PL/PGSQL, PL/Python, PL/Java, ...) • Object-Relational Database (eredità) • Interessanti add-ons (IE fuzzystrmatch) • Replicazione Master/Slave Integrata • PostGIS • Community estesa, know how consolidato
42
![Page 43: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/43.jpg)
Da dove eravamo partiti?
43
![Page 44: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/44.jpg)
![Page 45: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/45.jpg)
E SE…
![Page 46: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/46.jpg)
DISTRIBUZIONE DATI E LOGICA
![Page 47: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/47.jpg)
47
![Page 48: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/48.jpg)
COERENZA DEI DATI
![Page 49: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/49.jpg)
DISPONIBILITÀ DEL SERVIZIO
![Page 50: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/50.jpg)
Non potete avere tutto, ragazzi!
Prof. Eric Brewer http://www.cs.berkeley.edu/~brewer/
![Page 51: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/51.jpg)
Se volete distribuire una base dati, qualora si venga a creare un partizionamento, dovete scegliere tra coerenza dei dati e disponibilità del servizio.
CAP Theorem, Nancy Lynch and Seth Gilbert, “Brewer's conjecture and the feasibility of consistent, available, partition-tolerant web services”, ACM SIGACT News, Volume 33 Issue 2 (2002), pg. 51-59.
![Page 52: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/52.jpg)
Vediamo che significa
52
![Page 53: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/53.jpg)
Vediamo che significa
53
Uno o più nodi non raggiungibili: partizonamento
![Page 54: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/54.jpg)
Vediamo che significa
54
Hotel Farm
Uno o più nodi non raggiungibili: partizonamento
![Page 55: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/55.jpg)
55
![Page 56: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/56.jpg)
RINUNCIA ALLA DISPONIBILITÀ?
![Page 57: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/57.jpg)
Non scordiamo neppure la latenza!
![Page 58: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/58.jpg)
CAP Theorem
58
Consistency
Availability Partition Tolerance
![Page 59: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/59.jpg)
Soluzioni disponibili
59
Consistency
Availability Partition Tolerance
Categoria CP: BigTable Hbase MongoDB Redis Memcached etc.
Categoria CA: RDBMS etc.
Categoria AP: DynamoDB CouchDB Cassandra SimpleDB Tokyo Cabinet Riak Voldemort etc.
![Page 60: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/60.jpg)
Soluzioni disponibili
60
Consistency
Availability Partition Tolerance
Categoria CP: BigTable Hbase MongoDB Redis Memcached etc.
Categoria CA: RDBMS etc.
Categoria AP: DynamoDB CouchDB Cassandra SimpleDB Tokyo Cabinet Riak Voldemort etc.
![Page 61: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/61.jpg)
Come abbiamo scelto? • Supporto multi-master • Facilità di sincronizzazione applicazione • Flessibilità del modello dati • Semplicità
61
![Page 62: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/62.jpg)
Soluzioni disponibili
62
Consistency
Availability Partition Tolerance
Categoria CP: BigTable Hbase MongoDB Redis Memcached Scalaris etc.
Categoria CA: RDBMS GreenPlum etc.
Categoria AP: DynamoDB CouchDB Cassandra SimpleDB Tokyo Cabinet Riak Voldemort etc.
![Page 63: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/63.jpg)
63
“designed with the web in mind”
![Page 64: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/64.jpg)
Cos’è CouchDB? • Datastore Documentale (JSON) • Interfaccia HTTP • Replicazione master-master (con filtri) • Può contenere applicazioni Web
HTML/CSS/JS (Couchapp) • Pensato per contesti distribuiti • Un progetto dalla storia “travagliata”
64
![Page 65: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/65.jpg)
Incontriamo Futon (demo live)
65
![Page 66: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/66.jpg)
Schemaless
66
![Page 67: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/67.jpg)
Schemaless
67
![Page 68: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/68.jpg)
Replicazione Semplice
68
Supporto per modalità PULL e PUSH
![Page 69: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/69.jpg)
Ma Semplice Davvero!
69
Aggiornati non solo i dati ma anche le viste (design docs)
![Page 70: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/70.jpg)
Scenario di conflitto
70
CouchDB – The definitive guide – O’Reilly
![Page 71: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/71.jpg)
Risoluzione del Conflitto
71
CouchDB – The definitive guide – O’Reilly
![Page 72: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/72.jpg)
Versioni • ID / _rev • Meglio generare da se gli ID (sequenziali) • Aggiornamenti atomici sui documenti • Aggiornamento ottimista, MVCC • Coerenza Eventuale
72
![Page 73: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/73.jpg)
POSSIAMO RISOLVERE I CONFLITTI
![Page 74: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/74.jpg)
O CERCARE DI EVITARLI
![Page 75: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/75.jpg)
Progettiamo per evitarli
75
{
"titolo": "Il Padrino",
"sommario": "..."
"visioni": 3873,
"gradimenti": 185,
}
Provider Camera 1
Camera 2
![Page 76: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/76.jpg)
Progettiamo per evitarli
76
{
"titolo": "Il Padrino",
"sommario": "...",
"visioni": 3873,
"gradimenti": 185,
}
Provider Camera 1
Camera 2
{
"titolo": "Il Padrino",
"sommario": "...",
"visioni": 3873,
"gradimenti": 185,
}
![Page 77: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/77.jpg)
Progettiamo per evitarli
77
{
"titolo": "Il Padrino",
"sommario": "..."
}
Provider Camera 1
Camera 2
{
"titolo": "Il Padrino",
"visioni": 3873,
"gradimenti": 185,
}
MVCC
![Page 78: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/78.jpg)
Progettiamo per evitarli
78
{
"titolo": "Il Padrino",
"sommario": "..."
}
Provider Camera 1
Camera 2
{
"titolo": "Il Padrino",
"visioni": 3873,
"gradimenti": 185,
}
{
"titolo": "Il Padrino",
"visioni": 3873,
"gradimenti": 185,
}
{
"titolo": "Il Padrino",
"sommario": "..."
}
![Page 79: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/79.jpg)
79
![Page 80: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/80.jpg)
80
![Page 81: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/81.jpg)
CouchApps
81
![Page 82: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/82.jpg)
LOGICA LATO CLIENT
![Page 83: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/83.jpg)
SVILUPPATORI
SERVER-SIDE
![Page 84: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/84.jpg)
84
![Page 85: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/85.jpg)
RELAZIONI
METADATI
![Page 86: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/86.jpg)
Classico Backend
86
![Page 87: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/87.jpg)
WebApps Generate Server Side
87
![Page 88: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/88.jpg)
88
![Page 89: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/89.jpg)
E QUINDI PRESENTATE AI CLIENT
![Page 90: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/90.jpg)
Alto consumo di disco
90
0
2000
4000
6000
8000
10000
12000
14000
16000
DB Size (MB)
NB Quanto sopra su update!
![Page 91: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/91.jpg)
Btree+, che Succede?
91
Questione di affidabilità, performance
![Page 92: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/92.jpg)
COMPATTIAMO QUANDO POSSIBILE…
![Page 93: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/93.jpg)
Indicatori di Performance • 350 evt/sec in inserimento • 3000 evt/sec se in batch mode • 100 evt/sec su update • 10 evt/sec durante compattazione
93
• NB: dati forniti unicamente per dare ordini di grandezza. Test eseguiti su server entry level IBM x3550 M3, 1x3.60 GHz Xeon, 4GB RAM, Dischi SAS in RAID 0
• CouchDB configurato con httpd max_connections = 2048, export ERL_MAX_PORTS=4096, export ERL_FLAGS="+A 4«, fsync
![Page 94: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/94.jpg)
94
![Page 95: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/95.jpg)
95
![Page 96: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/96.jpg)
DI COSA AVREMMO BISOGNO?
![Page 97: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/97.jpg)
SHARDING
![Page 98: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/98.jpg)
Sharding
98
![Page 99: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/99.jpg)
Da considerare: • Inerentemente più rischioso • Più onerosa la manutenzione e il backup
degli shard • Delicato decidere con quali criteri
• In SQL: “Join” tra shards costosi.
Replicazione delle tabelle “globali” – es. categorie film
99
![Page 100: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/100.jpg)
Una possibile soluzione
100
![Page 101: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/101.jpg)
Recap su CouchDB: • Ottima soluzione per contesti distribuiti • Non adatto per situazioni con frequenti
aggiornamenti e carichi (ingenti) costanti • API REST aiuta a scalare le letture • Bigcouch in aiuto sulle scritture • Architetture innovative con le Couchapp • Si possono usare strumenti Tipici Web:
HAproxy, Nginx
101
![Page 102: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/102.jpg)
Da Tenere a Mente: • Attenzione alla generazione degli ID,
specie se distribuiti • Lo spazio su disco cresce e la
compattazione «inchioda» lo strumento • I «driver» disponibili non sempre sono di
alta qualità...
102
![Page 103: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/103.jpg)
Da Tenere sotto controllo: • TouchDB
database CouchDB compatibile, adatto all’embedding in device mobili
• PouchDB libreria js: come avere CouchDB nel browser
103
![Page 104: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/104.jpg)
Ulteriori Esigenze
104
![Page 105: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/105.jpg)
“L’aggregatore”
105
RSS
Previsioni meteo
Vimeo
Eventi
...
Aggregatore
![Page 106: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/106.jpg)
Architettura dell’aggregatore
106
RSS
Previsioni meteo
Vimeo
Eventi
...
REST API Crawler
CDN
![Page 107: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/107.jpg)
Cosa scegliamo?
107
RSS
Previsioni meteo
Vimeo
Eventi
...
REST API Crawler
CDN
?
![Page 108: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/108.jpg)
Cosa ci serve? • Flessibilità del modello dati • Semplicità • Facilità di dialogo con PHP • Scalabilità sulle letture • Flessibilità di query
108
![Page 109: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/109.jpg)
Perché no CouchDB? • Flessibilità del modello dati • Semplicità • Facilità di dialogo con PHP • Scalabilità sulle letture • Flessibilità di query
109
![Page 110: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/110.jpg)
INTERAGIRE CON COUCHDB
![Page 111: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/111.jpg)
Quante visioni hanno avuto i film in totale?
![Page 112: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/112.jpg)
MAP REDUCE
![Page 113: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/113.jpg)
113
{
"_id": "39c7c57daddba704c2b04606de001373",
"info_type": "view",
"movie": "The Gladiator",
"views": 37
}
{
"_id": "39c7c57daddba704c2b04606de000a2f",
"info_type": "view",
"movie": "Spiderman",
"views": 10
}
{
"_id": "39c7c57daddba704c2b04606de000c92",
"info_type": "view",
"movie": "Shrek",
"views": 25
}
![Page 114: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/114.jpg)
114
{
"movie": "Spiderman",
"views": 10
}
{
"movie": "The Gladiator",
"views": 37
}
{
"movie": "Shrek",
"views": 25
}
![Page 115: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/115.jpg)
115
{
"movie": "Spiderman",
"views": 10
}
{
"movie": "The Gladiator",
"views": 37
}
{
"movie": "Shrek",
"views": 25
}
10 37 25
![Page 116: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/116.jpg)
116
{
"movie": "Spiderman",
"views": 10
}
{
"movie": "The Gladiator",
"views": 37
}
{
"movie": "Shrek",
"views": 25
}
10 37 25
47 25
![Page 117: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/117.jpg)
117
{
"movie": "Spiderman",
"views": 10
}
{
"movie": "The Gladiator",
"views": 37
}
{
"movie": "Shrek",
"views": 25
}
10 37 25
47 25
72
![Page 118: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/118.jpg)
118
{
"movie": "Spiderman",
"views": 10
}
{
"movie": "The Gladiator",
"views": 37
}
{
"movie": "Shrek",
"views": 25
}
10 37 25
47 25
72
MAP
![Page 119: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/119.jpg)
119
{
"movie": "Spiderman",
"views": 10
}
{
"movie": "The Gladiator",
"views": 37
}
{
"movie": "Shrek",
"views": 25
}
10 37 25
47 25
72
REDUCE
![Page 120: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/120.jpg)
In CouchDB
120
function(doc) {
if (doc.info_type == 'view') {
emit(doc.movie, doc.views);
}
}
Map:
{
"_id": "39c7c57...",
"info_type": "view",
"movie": "The Gladiator",
"views": 37
}
![Page 121: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/121.jpg)
Cosa fa il map?
121
Map: function(doc) {
if (doc.info_type == 'view') {
emit(doc.movie, doc.views);
}
}
{
"movie": "Spiderman",
"views": 10
}
{
"movie": "The Gladiator",
"views": 37
}
{
"movie": "Shrek",
"views": 25
}
10 37 25
![Page 122: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/122.jpg)
Cosa fa il reduce?
122
Reduce: function (key, values, rereduce) {
return sum(values);
}
10 37 25
47 25
![Page 123: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/123.jpg)
Dov’è il problema?
123
function(doc) {
if (doc.info_type == 'config') {
for (param in doc.params) {
emit(param, doc.params[param]);
}
}
}
Map:
Reduce: .... Non possiamo avere parametri in input!
Viste precalcolate su ciascun documento
![Page 124: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/124.jpg)
124
“Hu(mongo)us”
![Page 125: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/125.jpg)
About MongoDB • Datastore Documentale (JSON) • Database / Collezioni • Protocollo Binario • Tanto Marketing • Veloce quasi come /dev/null :-P • Update in place -> locks! • Flessibilità nelle query • Autosharding
125
![Page 126: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/126.jpg)
Interagire con il DB è banale
126
![Page 127: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/127.jpg)
Attenzione!
127
![Page 128: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/128.jpg)
Query
128
// operatori di confronto
db.notizie.find({tipo: {$ne: ‘cnn’},
ora_reperimento: {$gt: 1352505039}
});
// eventi di oggi e (necessariamente) domani
db.evento.find( { data: { $all: [ ‘2012-11-10’,
‘2012-11-11’ ] } } );
// eventi di oggi e/o domani
db.evento.find( { data : { $in : [‘2012-11-10’
‘2012-11-11’ ] } } );
// eventi di una giornata sola
db.evento.find( { data : { $size: 1 } } );
// cerca dentro gli array
db.previsioni.find( { ‘settimana.temp_max’ : 20 } );
![Page 129: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/129.jpg)
Performance VS Durevolezza
129
Le impostazioni predefinite (32bit e <v2.0) sono “rischiose” (no journal)
![Page 130: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/130.jpg)
Performance VS Durevolezza
130
MongoDB a 32bit NON VA USATO in PRODUZIONE!
![Page 131: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/131.jpg)
Replica Set
131
http://docs.mongodb.org/manual/core/replication/
![Page 132: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/132.jpg)
Automated Failover
132
![Page 133: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/133.jpg)
Recap su MongoDB: • Semplice (arma a doppio taglio!) • Linguaggio d’interrogazione potente • Ottima documentazione • Flessibilità nella configurazione • Driver disponibili per molti linguaggi • Sviluppo molto attivo • Supporto
133
![Page 134: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/134.jpg)
Fare attenzione a: • Opzione safe, journaling • Si inchioda negli ordinamenti se non
definiti indici • Attenzione ai nomi! • Non farsi coinvolgere e cercare di
costruirci sopra DB relazionali
134
![Page 135: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/135.jpg)
135
![Page 136: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/136.jpg)
TUTTO A POSTO SIGNORE!
![Page 137: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/137.jpg)
Cosa abbiamo considerato? • Performance • Semplicità • Expiration automatico dei valori • Gestione del cold start • Non è un problema la perdita di dati
-> Ok persistenza volatile, no replicazione
137
![Page 138: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/138.jpg)
Perchè no Couch/Mongo? • Couch occupa troppo spazio, troppo lento • MongoDB poteva starci (soprattutto
perché TTL introdotte da poco – 12/09); • Ma ci sono soluzioni più semplici…
138
![Page 139: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/139.jpg)
139
“An open source, advanced key-value store”
![Page 140: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/140.jpg)
About Redis • Key/Value++ • Progetto Italiano (Salvatore Sanfilippo) • Protocollo Binario • Sponsorizzato da VMWare • Gestione expiry delle chiavi
140
![Page 141: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/141.jpg)
Esempi di query
141
// Memorizzare un valore
> SET status ok
// Collezioni
> SADD luci_accese camera bagno
// Valore con scadenza prefissata
> SET status ok
> EXPIRE status 10 // in secondi
![Page 142: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/142.jpg)
Sorted Sets
142
![Page 143: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/143.jpg)
Recap su Redis: • E’ molto veloce • Salva su RAM (snapshot su disco) • E’ un’ottima soluzione di caching,
evitando problema cold start • Necessario avere abbastanza RAM • Può essere usato per delegare alcuni
calcoli costosi
143
![Page 144: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/144.jpg)
144
![Page 145: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/145.jpg)
COME STANNO ANDANDO LE COSE?
![Page 146: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/146.jpg)
Cosa ci serve? • Gestire grandi moli di dati • Modello di dati che supporti correlazione
146
![Page 147: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/147.jpg)
Com’è fatta una nostra app?
147
![Page 148: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/148.jpg)
E una sessione d’uso?
148
![Page 149: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/149.jpg)
E una sessione d’uso?
149
![Page 150: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/150.jpg)
E una sessione d’uso?
150
![Page 151: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/151.jpg)
E una sessione d’uso?
151
![Page 152: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/152.jpg)
Cosa ci ricorda tutto ciò?
152
![Page 153: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/153.jpg)
G=(V,E)
![Page 154: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/154.jpg)
Un semplcie grafo
154
![Page 155: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/155.jpg)
Con strumenti visti prima… • Query di Couch poco flessibili • Redis assenza indici secondari • MongoDB e Postgres forse ok ma limiti
nel traversare nodi non immediatamente adiacenti
155
![Page 156: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/156.jpg)
Troviamo le visite a partire dalla
dashboard in un determinato periodo
![Page 157: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/157.jpg)
Con RDBMS
157
SELECT p1 . * , p2 . * , v . *
FROM pagina AS p1
JOIN visita AS v ON v.pagina_da = p1.id
JOIN pagina AS p2 ON v.pagina_a = p2.id
WHERE p1.id =1
AND v.data_visita >0
AND v.data_visita <4
![Page 158: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/158.jpg)
Il problema…
158
SELECT p1 . * , p2 . * , v . *
FROM pagina AS p1
JOIN visita AS v ON v.pagina_da = p1.id
JOIN pagina AS p2 ON v.pagina_a = p2.id
WHERE p1.id =1
AND v.data_visita >0
AND v.data_visita <4
O(log N) O(log M) O(log N)
![Page 159: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/159.jpg)
Invece con un grafo:
159
O(1)
O(1)
Adiacenza senza necessità di consultare un indice!
![Page 160: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/160.jpg)
160
“Multiple datamodels support”
![Page 161: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/161.jpg)
Modello Dati
161
![Page 162: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/162.jpg)
https://github.com/tinkerpop/blueprints/wiki/Property-Graph-Model
![Page 163: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/163.jpg)
Interagire con OrientDB • Protocollo binario / REST • JSON • Tinkerpop Stack: Gremlin, Pipes
• SQL(+)
163
![Page 164: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/164.jpg)
Select titolo, in.out.in.nome from #16:5
![Page 165: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/165.jpg)
Replica Master-Master
Sync/Async - Configurabile 165
![Page 166: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/166.jpg)
Recap su OrientDB:
• Ottima soluzione per gestire relazioni • Traversa 5 Milioni+ di record/sec • Progetto Italiano (Luca Garulli) • ACID • Supporta ereditarietà • Semplice da installare e avviare
166
![Page 167: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/167.jpg)
167
![Page 168: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/168.jpg)
Ringraziamento
168
Il know how utilizzato per la preparazione di questa presentazione è stato in buona parte acquisito durante lo sviluppo del sistema Hotel OnAir di concezione e proprietà di VDA Multimedia Spa, cui il case study di cui si è fatto accenno fa riferimento. Ringraziamo il team leader del progetto, Stefano Brenelli, e tutto il team di sviluppo, per l'interessante, edificante e proficua collaborazione. In particolare ringraziamo: Carlo Anselmi, Maurizio Battistella, Manuel Bitto, Nicola Busanello, Antonino Murador, Antonio Parrella, Nicola Pressi, Riccardo Zamuner, Michele Zanon, Tiziano Zonta. Ringraziamo anche i colleghi Diego Drigani e Dario Tion, nonchè tutto il PUG Friuli per i sempre utili confronti e consigli.
![Page 169: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/169.jpg)
DOMANDE?
![Page 170: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/170.jpg)
http://friuli.grusp.org/
![Page 171: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/171.jpg)
http://www.ditedi.it/
![Page 172: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/172.jpg)
Image Credits • http://www.flickr.com/photos/leandrociuffo/4128603357/ • http://www.flickr.com/photos/uggboy/8043043095/ • http://www.flickr.com/photos/kky/704056791/ • http://www.flickr.com/photos/shareandenjoy/7074965023/ • http://www.flickr.com/photos/ivyfield/4497654857/ • http://www.flickr.com/photos/craigmarren/6086280669/ • http://www.flickr.com/photos/getbutterfly/6317955134/ • http://www.flickr.com/photos/62698615@N08/5948655391/ • http://20bits.com/article/interview-questions-database-indexes • http://www.flickr.com/photos/iita-media-library/4808291918/ • http://www.flickr.com/photos/47108884@N07/6949078701/ • http://www.flickr.com/photos/rrrodrigo/4139483872/ • http://www.flickr.com/photos/latt/509790815/ • http://www.flickr.com/photos/spine/525988813/ • http://www.flickr.com/photos/latt/509790815/ • http://www.flickr.com/photos/antmoose/116845021/ • http://www.flickr.com/photos/charleylhasa/3374499088/ • http://www.flickr.com/photos/mcascherrypoint/6277623762/ • http://www.flickr.com/photos/superk8/2801590280/ • http://www.flickr.com/photos/cawley/1067814030/ • http://www.flickr.com/photos/mr_g_travels/863720665/ • http://www.flickr.com/photos/cortesdecima/6099516346/ • http://www.flickr.com/photos/portofsandiego/7777282856/ • http://www.flickr.com/photos/22750018@N05/4268345597/ • http://www.flickr.com/photos/petereed/132829587/ • http://www.flickr.com/photos/myfruit/7031263653/ • http://www.flickr.com/photos/maugiart/5014963068/ • http://www.flickr.com/photos/freefoto/3844247553/ • http://www.flickr.com/photos/incognito_rico/69242116/ • http://tinkerpop.com/ • http://www.slideshare.net/lvca/orientdb-distributed-architecture-11h • ttp://www.flickr.com/photos/dobs/4128798936/
172
![Page 173: Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB](https://reader034.vdocumenti.com/reader034/viewer/2022042601/54c79d4b4a7959551f8b45b9/html5/thumbnails/173.jpg)
Grazie per l’attenzione
Stefano Maraspin @maraspin [email protected]
Stefano Valle @stefanovalle [email protected]