Design your application using Persistent Graphs and OrientDB

Preview:

DESCRIPTION

This

Citation preview

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 1www.orientechnologies.com

Luca Garulli – Founder and CEONuvolaBase Ltd

May 2012 29 - 30 in Cologne, Germany

Design your application using Persistent Graphs and OrientDB

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 2

Usually NoSQL products are selectedbecause are fast and super scalable,

but at what price?

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 3

Can you really renounce toTransactions, an expressive Query

language and all the featuresavailable for years by RDBMS?

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 4

Can we have a fast and scalable NoSQLproduct with flexible schema,

transactions, SQL, security and thesupport for complex types ?

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 5

The answer is OrientDB,the document-graph NoSQL dbms

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 6

The answer is OrientDB,the document-graph NoSQL dbms

I never will change my RDBMS with

anything!

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 7

Mission?Reduce to the minimum the compromises

on fitting the application domain to apersistent database supporting

multiple models

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 8

OrientDB = {flexibility of Document databases+ complexity of the Graph model

+ Object Oriented concepts+ fast Index

+ powerful SQL dialect}

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 9

+13 yearsof research

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 10

+3 yearsof design and development

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 11

Relationshipsare direct links

no Relational JOINS to connect multiple tables

Load trees and graphs in few ms!

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 12

Ø configdownload, unzip, run!

cut & paste the db

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 13

150,000records per second

(flat records, no index, on commodity hw)

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 14

Schema-lessschema is not mandatory, relaxed model,collect heterogeneous documents all together

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 15

Schema-fullschema with constraints on fields and validation rules

Customer.age > 17Customer.address not null

Customer.surname is mandatoryCustomer.email matches '\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b'

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 16

Schema-mixedschema with mandatory and optional fields + constraints

the best of schema-less and schema-full modes

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 17

ACID Transactionsdb.begin();try{ // your code ... db.commit();

} catch( Exception e ) { db.rollback();}

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 18

Complex typesnative support for collections, maps (key/value)

and embedded documentsno more additional tables to handle them

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 19

SQLselect * from employee where name like '%Jay%' and status=0

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 20

Why reinventyet another language when

the 100% of developers alreadyknow SQL?

OrientDB begins from SQLbut improves it with new

operators for graph manipulation

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 21

For the most of the querieseveryday a programmer needs

SQL is simpler,more readable and

compact thenScripting (Map/Reduce)

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 22

SELECT SUM(price) as prices, SUM(cost) as costs, prices-costs, margin/price FROM Balance

VSfunction (key, values) { var price = 0.0, cost = 0.0, margin = 0.0, marginPercent = 0.0; for (var i = 0; i < values.length; i++) { price += values[i].price; cost += values[i].cost; } margin = price - cost; marginPercent = margin / price; return { price: price, cost: cost, margin: margin, marginPercent: marginPercent };}

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 23

Asynchronous Queryinvoke callback when a record matches the condition

doesn't collect the result set

perfect for immediate resultsuseful to compute aggregates

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 24

Enhanced SQLSQL is not enough for collections, maps, trees and graphs

need to enhance SQL syntax

Easy syntax derived from JDO/JPA standards

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 25

SQL & relationshipsselect from Account where address.city.country.name = 'Italy'

select from Account where addresses contains (city.country.name = 'Italy')

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 26

SQL & trees/graphsselect out[label='friend'].in from V where name = 'Luca' and surname = 'Garulli'

select out[@class='knows'].in from V where name = 'Jay' and surname = 'Miner'

traverse friends from Profile where $depth < 7

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 27

SQL sub queriesselect from ( traverse friends from Profile where $depth < 7 ) where home.city.name = ‘Cologne’

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 28

SQL & stringsselect from Profile where name.toUpperCase() = 'LUCA'

select from City where country.name.substring(1,3).toUpperCase() = 'TAL'

select from Agenda where phones contains ( number.indexOf( '+39' ) > -1 )

select from Agenda where email matches '\bA-Z0-9._%+-?+@A-Z0-9.-?+\.A-Z?{2,4}\b'

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 29

SQL & schema-lessselect from Profile where any() like '%Jay%'

select from Stock where all() is not null

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 30

SQL & collectionsselect from Tree where children contains ( married = true )

select from Tree where children containsAll ( married = true )

select from User where roles containsKey 'shutdown'

select from Graph where edges.size() > 0

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 31

Java®runs everywhere is available JRE1.5+

robust engine

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 32

Language bindingsJava as native

JRuby, PHP, C, Scala, .NET,Ruby, Clojure, Node.js,Python and Javascript

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 33

Is your languagenot supported (yet)?

Write an adapter using theC, Java or HTTP binding

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 34

Binary protocolFast compressed JSON over tcp/ip

available for Javaand soon C, C++ and Ruby

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 35

HTTP RESTful

firewall friendly

use it from the web browseruse it from the ESB (SOA)

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 36

Native JSONODocument = new ODocument().fromJSON( " { '@rid' = '26:10', '@class' = 'Developer', 'name' : 'Luca', 'surname' : 'Garulli', 'out' : [ #10:33, #10:232 ] }“ );

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 37

Import/Exportuses JSON format

online operations (don't stop the database)

> export database demo

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 38

MVRB-Tree index

the best of B+Tree and RB-Treefast on browsing, low insertion cost

it's a new algorithm

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 39

Hookssimilar to triggers

catch events against records, database and transactions

implement custom cascade deletion algorithm

enforce constraints

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 40

Securityusers and roles, encrypted passwords

fine grain privileges(similar to what RDBMS offer)

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 41

CacheYou can avoid using 3°party caches

like Memcached

2 Level caches:Level1: Database level, 1 per thread

Level2: Storage level, 1 per JVM

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 42

OGraphVertex (V)

PersonAddress : Address

Inheritance

CustomertotSold : float

ProvidertotBuyed : float

OGraphEdge (E)

Works

since : Date

Residessince : Date

till : Date

Knows

Level : LEVELS

Vehiclebrand : BRANDS

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 43

OgraphVertex (V)

PersonAddress : Address

Polymorphic SQL Query

CustomertotSold : float

ProvidertotBuyed : float

Vehiclebrand : BRANDS select from Person

where city.name = 'Rome‘

Queries are polymorphicsand subclasses of Person can be

part of result set

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 44

Fetch plansChoose what to fetch on query and vertexes/edges loading

Vertexes/Edges not fetched will be lazy-loaded on request

Optimizes network latency

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 45

Load only the root vertex= *:1

Fetch plansVertex Luca | | lives city +---------> Vertex ------------> Vertex | 10th street Italy | knows +--------->* [Vertex Vertex Vertex ] [ Marko John Nicholas]

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 46

Fetch plansVertex Luca | | lives city +---------> Vertex ------------> Vertex | 10th street Italy | knows +--------->* [Vertex Vertex Vertex ] [ Marko John Nicholas]

Load root + address= *:1 lives:2

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 47

Fetch plansVertex Luca | | lives city +---------> Vertex ------------> Vertex | 10th street Italy | knows +--------->* [Vertex Vertex Vertex ] [ Marko John Nicholas]

Load root + all known= *:1 knows:1

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 48

Fetch plansVertex Luca | | lives city +---------> Vertex ------------> Vertex | 10th street Italy | knows +--------->* [Vertex Vertex Vertex ] [ Marko John Nicholas]

Load up 3rd level of depth= *:3

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 49

Graph Database model

Built as wrapper on top ofThe Document Database

Few simple concepts: Vertex, Edge,Property and Index

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 50

Why OrientDB is so special onhandling Graphs?

Can I model a graphon top of a RDBMS?

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 51

A GraphDB has an“index-free adjacency”

mechanism to crossthe graph without any

index lookup

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 52

OrientDB doesn’t use JOINbut the “link” to traverse

millions of elements per second

In Blueprints benchmark, with a hot cache,traverses 29,6M of records in less than 5 seconds

= 5,92M of nodes traversed per sec!

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 53

OGraphDatabaseNative, damn fast, not the most beautiful API

2 different API

OrientGraphTinkerPop Blueprints, slowest but:

common to other impls, Gremlin, SPARQL (via Sail)

All APIsare compatibleamong them!

So use the right onefor the right case

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 54

What to choose?

OGraphDatabase if you needperformance at any cost.

Use it for massive insertion orlow resources

OGraphDatabaseNative, damn fast, not the most beautiful API

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 55

What to choose?

OrientGraph if you want to stayPortable

at the cost of less speed and more memory used

or to use Gremlin language,or as RDF store + SPARQL

OrientGraphTinkerPop Blueprints, slowest but:

common to other impls, Gremlin, SPARQL (Sail)

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 56

TinkerPop technologiessort of “standard” for GraphDB

a lot of free open-source projects

http://tinkerpop.com

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 57

TinkerPop Blueprintsbasic API to interact with GraphDB

implements transactional andindexable property graph model

bidirectional edges

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 58

GraphDB & Blueprints API

OrientGraph graph = new OrientGraph("local:/tmp/db/graph”);

Vertex actor = graph.addVertex(null);actor.setProperty("name", "Leonardo");actor.setProperty("surname", "Di Caprio");

Vertex movie = graph.addVertex(null);movie.setProperty("name", "Inception");

Edge edge = graph.addEdge(null, actor, movie, "StarredIn");

graph.shutdown();

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 59

TinkerPop

scripting language

easy to learn and understandUsed for operations against graphs

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 60www.orientechnologies.com

gra

ph-e

xam

ple

-1

.xm

l

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 61

Load graph

Run the console, open the database and load a graph in xml format

marko:~/software/gremlin$ ./gremlin.sh

\,,,/ (o o)-----oOOo-(_)-oOOo-----

gremlin> $_g := orientdb:open('/tmp/graph/test')==>orientgraph[/tmp/graph/test]

gremlin> g:load('data/graph-example-1.xml')==>true

gremlin> $_g==>orientgraph[/tmp/graph/test]

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 62

SearchDisplays outgoing edges of vertices with name equals to 'marko',then the name of inbound vertices

gremlin> g:key-v('name','marko')/outE==>e[6:0][5:2-knows->5:1]==>e[6:1][5:2-knows->5:4]==>e[6:4][5:2-created->5:0]

gremlin> g:key-v('name','marko')/outE/inV/@name==>vadas==>josh==>lop

gremlin> g:close()==>true

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 63

High-AvailabilityMulti-Master replication

Servers can be heterogeneous withdifferent replicated databases

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 64

Where is the previousOrientDB

Master/Slavearchitecture?

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 65

Master/slave only. Do not

recycle!

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 66

After first tests we decided tothrow away the old Master-Slave

architecture because it wasagainst the OrientDB philosophy:

(1) It didn't scaleand

(2) It was hard to configure

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 67

ConsoleORIENT database v.0.9.23 www.orientechnologies.comType 'help' to display all the commands supported.

> connect remote:localhost/demo admin adminConnecting to database [remote:localhost/demo] with user 'admin'...OK

> select from profile where nick.startsWith('L')---+--------+--------------------+--------------------+--------------------+ #| REC ID |NICK |SEX |AGE |---+--------+--------------------+--------------------+--------------------+ 0| 10:0|Lvca |male |34 1| 10:3|Leo |male |22 2| 10:7|Luisa |female |273 item(s) found. Query executed in 0.013 sec(s).

> closeDisconnecting from the database [demo]...OK

> quit

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 68

OrientDB Studio/View graph

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 69

Multi-Modeluse case

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 70

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 71

Always FreeOpen Source Apache 2 license

free for any purposes,even commercials

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 72

Prof€$$ional$€rvic€$

directly by NuvolaBase Ltd or partners

support, training, consulting, mentoring

Do you want to be a partner?

Contact info@nuvolabase.com

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 73

OrientDBfor Java developers

8 hours

OrientDBMaster Development

14 hours

OrientDBfor SOA

6 hours

OrientDBand the power of graphs

6 hours

OrientDBfor DBA

6 hours

OrientPlanetfor Web Developers

6 hours

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 74

Certification Programto be part of the network

do coursesshare revenues for support

work as consultantContactinfo@nuvolabase.com

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 75

“OrientDB in Action”book

by Manning Publicationsis coming: January 2013

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 76

NuvolaBase.com

The firstGraph Database

on the Cloud

always availablefew seconds to setup it

use it from app & mobile

(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 77

Luca Garulli

www.twitter.com/lgarulli

CEO atAuthor of

Document-Graph NoSQLOpen Source project

Ltd, London UK

Recommended