neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t...

35
Neo4j 3.0 Benoit Simard (@logisima)

Upload: others

Post on 09-Oct-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Neo4j 3.0Benoit Simard (@logisima)

Page 2: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

introduction

Page 3: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

@logisima

Addicte aux graphes

Formateur

Benoit Simard, consultant

[email protected]

Page 4: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Les prochains évènements

1er juin : Les graphes dans les projets industriels orientés data, par Kernix

15 juin : Venue sur Paris de Andres Taylor (le créateur de Cypher)

28 juin: Graphes & Finance - Plongée dans les Panama Papers

21 septembre : Graph day Paris

Page 5: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

L’histoire de Neo4j

Page 6: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

API Java

JAR de petite taille

Indexation basique

Neo4j 0.X - 2000 à 2010

Page 7: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

API REST

Serveur Neo4j

Mode cluster

Cypher dans la 1.4

Neo4j 1.X - 2010 à 2014

Page 8: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Cypher par defaut (ajout de l’écriture)

Ajout des Labels

Schema

Neo4j Browser

Page Cache

Neo4j 2.X - 2014 à 2016

Page 9: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Neo4j 3.0

Page 10: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Permettre à tout le monde de développer desapplications graphes

Simplement

Rapidement

Sans contrainte de volumétrie

Les fondements

Page 11: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Les fondements

Page 12: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Du coté des architectes

Page 13: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Jusqu’au bout de l’extrême limite !EE : Un nouveau moteur de stockage qui abolit les limites de Neo4j (> 1 quadrillion) !

Page 14: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Mise à jour de lucene en version 5

Indexation en parallèle (meilleure performanceen écriture)

Partitonnement des indexes lucene(suppression de la limitation de 2 milliards)

Les indexes, c’est majeur

Page 15: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Pour les ops !

Page 16: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Amélioration des performances sur lesenvironnements virtualisés (Optimisation dupage-cache)

Image docker o�cielle

Cloud , virtualisation, containers

Page 17: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Refactoring : la structureModi�cation de la structure

├── bin

├── certificates

├── conf

├── data

│ ├── databases

│ │ └── graph.db

│ └── dbms

├── import

├── lib

├── logs

├── plugins

└── run

1

2

3

4

5

6

7

8

9

10

11

12

Page 18: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Refactoring : la con�gurationUn seul �chier de conf conf/neo4j.conf, avec les propriétés namespacés

/!\ Les noms des propriétés ont donc changé !

...

#

# Bolt connector

#

dbms.connector.bolt.type=BOLT

dbms.connector.bolt.enabled=true

dbms.connector.bolt.tls_level=OPTIONAL

# To have Bolt accept non-local connections, uncomment this line:

# dbms.connector.bolt.address=0.0.0.0:7687

...

1

2

3

4

5

6

7

8

9

10

Page 19: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Refactoring : les logsTous les �chiers de logs sont à présent dans le répertoire logs

logs/

├── debug.log <= anciennement messages.log dans graph.db

└── neo4j.log

1

2

3

Page 20: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Le coin des développeurs

Page 21: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Protocole binaire

Transport : TCP & Websocket

Sécurisé : TLS & authenti�cation par défaut

Versionné

bolt://localhost:7687

Bolt

Page 22: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Bolt: drivers o�ciels

Page 23: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Bolt// Javascript

var driver = Graph.Database.driver("bolt://localhost");

var session = driver.session();

var result = session.run("MATCH (u:User) RETURN u.name");

1

2

3

4

// Python

driver = Graph.Database.driver("bolt://localhost")

session = driver.session()

result = session.run("MATCH (u:User) RETURN u.name")

1

2

3

4

// Java

Driver driver = GraphDatabase.driver( "bolt://localhost" );

try ( Session session = driver.session() ) {

StatementResult result = session.run("MATCH (u:User) RETURN u.name");

}

1

2

3

4

5

// .NET

using (var driver = GraphDatabase.Driver("bolt://localhost"))

using (var session = driver.Session())

{

var result = session.Run("MATCH (u:User) RETURN u.name");

}

1

2

3

4

5

6

Page 24: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Ecrivez du code personnalisé :

En Java (compatible JVM)

Stocké sur le serveur (un jar à déployer)

Accessible en Cypher

Les procédures stockées

Page 25: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Les procédures stockées : built-inCALL dbms.procedures() YIELD name

with split(name,".") AS parts

WHERE not parts[0] = 'apoc'

RETURN parts[0..-1] AS package, count(*),collect(parts[-1]) AS procs

1

2

3

4

Page 26: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

APOC

Obtenir le meta-graph : CALL apoc.meta.graph()

Charger des données en JDBC :

CALL apoc.load.driver('com.mysql.jdbc.Driver')

CALL apoc.load.jdbc('jdbc:mysql:localhost/mysql', 'SELECT * FROM user') YIELD rowCREATE (:User {name:row.User})

Charger des données JSON

Des fonctions spatiales

https://github.com/neo4j-contrib/neo4j-apoc-procedures

Page 27: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Neo4j Browser SyncSynchronisez vos scripts, con�guration, style sur tous vos navigateurs

Page 28: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Cypher

ENDS WITH et CONTAINS se basent maintenant sur les indexes (tout comme STARTS WITH en 2.3)

Amélioration globale des performances sur les aggregations (ex: count sur les labels)

Amélioration des performances d’écritures / écritures

Upgrade de lucene

Planneur basé sur les coûts pour les écritures

Page 29: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Cypher : planneur basé sur les coûts

Basé sur la connaissance des données en base (ie. des statistiques)

A été introduit en 2.2 pour les requêtes en lecture seule

Est disponible à présent aussi pour les requêtes d’écritures

Planneur par défaut

Page 30: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Cypher : exampleCypher version: CYPHER 3.0, planner: RULE. 3060001 total db hits in 7197 ms.

Cypher version: CYPHER 3.0, planner: COST. 50003 total db hits in 3280 ms.

cypher planner=rule

MATCH (p:Product),(c:Category)

WHERE p.category_id = c.id

CREATE (c)-[:CONTAINS]->(p);

1

2

3

4

cypher planner=cost

MATCH (p:Product),(c:Category)

WHERE p.category_id = c.id

CREATE (c)-[:CONTAINS]->(p);

1

2

3

4

Page 31: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Cypher : shortestpathLes prédicats utilisés dans la clause WHERE sont maintenant évalués pendant l’algorithme !

MATCH (a:Loc {name:"Nantes"}),(b:Loc {name:"Paris"})

MATCH trip = shortestPath((a)-[roads:ROAD*]->(b))

WHERE

NONE(r in roads WHERE r.closed or r.speed < 30) AND

ALL (r in roads WHERE r.type = 'Autoroute') AND

reduce(s=0, r in roads | s + r.distance) < 300

RETURN trip;

1

2

3

4

5

6

7

Page 32: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Comment upgrader ?

Page 33: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Upgrader en 3.X

Java 8

Mise à jour du store : dbms.allow_format_migration=true

Mise à jour de lucene : reconstruction des indexes

Mise à jour de la con�guration : java -jar config-migrator.jar path/to/neo4j2.3path/to/neo4j3.0

http://neo4j.com/guides/upgrade/#neo4j-3-0

Page 34: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Merci

Page 35: Neo4j 3 - sim51.github.iosim51.github.io/presentations/neo4j_3.0/slides.pdf · neo4j 3.0 b eno i t s i mar d (@l o g i si ma) in t ro d u ct io n # nq ikuko c $ f f kevgcw zitcr j

Des questions ?

Twitter: Suivez les comptes @neojFr & @neo4j

Google group : Avec les groupes Neo4jFr & Neo4j

Stackover�ow : avec les tags neo4j & cypher

Slack : http://neo4j-users-slack-invite.herokuapp.com/