+ All Categories
Home > Documents > ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper...

ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper...

Date post: 03-Jul-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
48
ZODB: A Presistent Graph of Python Objects By Christopher Lozinski t © Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #1
Transcript
Page 1: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

ZODB: A Presistent Graph of Python Objects

By

Christopher Lozinski

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #1

Page 2: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

Why Use a Graph Database?

Social Network Computer Network

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #2

Page 3: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

Neo 4J Property Graph DatabaseNeo, Graphagus

Sara follows Joe.Sara follows Ben.Sara likes bikes.Sara likes cars.Sara likes cats.Aria follows Joe.Maria loves Joe.Maria likes cars.Joe follows Sara.Joe follows Maria.Joe loves Maria.Joe likes bikes.Joe likes nature

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #3

Page 4: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

ArrangoDB

{ title: "Data modelling", text: "lorum ipsum...", author: "Mike Williamson", date: "2015-11-19", comments: [ { author:"Mike's Mum", email:"[email protected]", text: "That's great honey", }, { "author": "[email protected]", "title": "Brilliant", "text": "Gucci handbags...", } ], tags:["mongodb","modeling","nosql"]}

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #4

Page 5: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

ZODB

Graph of Persistent Python Objects

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #5

Page 6: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

Graphagus: A Property Graph Database on ZODB

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #6

Nodes

SaraBenMarthaJoe

CatsCarsBikes

Edges

Sara follows Joe.Sara follows Ben.Sara likes bikes.Sara likes cars.Sara likes cats.Aria follows Joe.Maria loves Joe.Maria likes cars.Joe follows Sara.Joe follows Maria.Joe loves Maria.Joe likes bikes.Joe likes nature.

Page 7: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

For Managing Complexity

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #7

Page 8: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

http://PythonLinks.info/home

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #8

Page 9: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

How to Use the ZODBSo Easy to use!

import persistent

class TreeLeaf(persistent.Persistent):

def __init__(self,title=’’): self.title=title

def render(self): return self.title

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #9

Page 10: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

ZODB Tutorial: Add Leaf Objects

Single Leaf Object Multiple LEAF Objects

#CREATE A SINGLE LEAF OBJECTleaf = TreeLeaf(‘Leaf’)root.leaf=leaf

#CREATE MULTIPLE LEAF OBJECTSLeaf1 = TreeLeaf(‘Green Leaf’)leaf2 = TreeLeaf(‘Red Leaf’)

#ADD THEM TO THE ROOTroot['leaf1'] = leaf1root['leaf2'] = leaf2

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #10

Page 11: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

ZODB Tutorial: Create a Databasehttp://www.zodb.org/en/latest/tutorial.html

import ZODB, ZODB.FileStorage

db = ZODB.db(‘Data.fs’)connection = db.open()root = connection.root

#DO SOMETHING

transaction.commit()

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #11

Page 12: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

It is just Python (No SQL SELECT)

#UPDATE THE Leaf

root[‘leaf1’].title=”Yellow Leaf”

transaction.commit()

#STUPID QUERY

For key, item in root.items():

print (key, item)

# DELETE AN OBJECTdel root[‘leaf1’]transaction.commit()

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #12

Page 13: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

ZODB is MagicalCreates the illusion that your Python Objects are Persistent

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #13

Page 14: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

ZODB is a graph databases

#CREATE THE OBJECTSLeaf1 = TreeLeaf(‘Green Leaf’)leaf2 = TreeLeaf(‘Red Leaf’)

#ADD THEM TO THE ROOTroot['leaf1'] = leaf1root['leaf2'] = leaf2

#IT IS A GRAPH DATABASEleaf1.sibling = leaf2leaf2.sibling = leaf1transaction.commit()

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #14

Page 15: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

Hierarchical Calculations

class Video(Persistent): def countLeaves(self): return 1

class Category (Container): def countLeaves(self): total=0 for item in self.values(): total+=item.countLeaves() self.branchSize = total return total

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #15

Page 16: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

The Best Videos on any branch of the tree]}

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #16

Page 17: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

ZODB Uses Pickle

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #17

Page 18: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

File Storage Objects are Written to the end of a File

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #18

Object 3

Object 2

Object 1

Object 4

Page 19: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

Ghost Objects

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #19

Object 3

Object 2

Object 1

Object 4

Object 2.1

Object 4 Ghost

Page 20: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

FileStorage Transactions

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #20

Object 3

Object 2

Object 1

Object 4

Object 6

Object 3

Object 5

Object 7

Object 3

Object B

Object A

Object C

Object F

Object E

Object D

Object G

Transaction 1 Transaction 3 Transaction 2 Transaction 4

Page 21: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

Object Versions

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #21

Version 2

Version 3Version 1

Page 22: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

Rel StorageStoring ZODB Objects ina Relational Database.

PostgreSQL, Oracle, MySQL

Object Id Version Number Pickle

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #22

Page 23: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

ZEOClient Server Storage

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #23

Page 24: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

ZODB Advantages by Jim Fulton

• No Database to administer

No Database Administrator

No Database Schema

No ORM

No Referential Integity Problems

Automatic Garbage Collection

No manual reads and writes

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #24

Page 25: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #25

Dolmen

Cromlech

Page 26: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

Traversal

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #26

Page 27: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

Zopache Canonincal URL’s

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #27

Page 28: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

ZODB Cell Phone Interfacehttp://PythonLinks.info/

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #28

Page 29: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

ZODB vs Relational Databases

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #29

Page 30: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

ZODB vs Relational Databases

ZODB Relational Databases

for item in node: print (item)

You have to do a database join across every single table. 10 Tables: App, Category, City, Company, Country, iFrame Link, Job, Link, Region,Product, and Video.

Zcatalog, Hypatia, repoze.catalog Select statement

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #30

Page 31: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

CREATING INDEXES Using Repoze.catalog

1) catalog = Catalog() 2) def get_area(object, default): return getattr(object, ‘area’, default) 3) catalog[‘area’] = CatalogFieldIndex(get_area) 4) leaf-1 = Leaf(area=20)

5) catalog.index_doc(1, leaf-1) 6) catalog.reIndex (1,leaf-1)

7) numdocs, results = catalog.query(Range(20,40))

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #31

Page 32: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

ZODB Storage Options

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #32

Page 33: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

NewtDB Persistetn Python + PostgeSQL Indexes

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #33

Page 34: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

Plone ZODB UsersUS Plone Sites

• Federal Bureau of Investigation (FBI)• Central Intelligence Agency (CIA)• Intellectual Property Rights Center• US Department of Energy• USDA Forest Service• Fermi National Accelerator Lab (Fermilab)• NASA Science• Continental Airlines• UCLA• Yale University• Harvard• The Pennsylvania State University• University of Notre Dame• University of Virginia• University of California - Davis• University of North Carolina• University of Louisville• Novell• Akamai• eBay• Google• Walmart• Marriott• ...and many more.

Worldwide Plone Sites• Brazilian Government• 2016 Olympics Brazil• The British Postal Museum and Archive• The New Zealand Treasury• Konica Minolta Printers - Australia• National Sports Council - Spain• National Library of South Africa• University of Oxford• University of Toronto• Academy of Performing Arts - Prague• Open Society Foundation• Amnesty International• OXFAM• Lufthansa• Nokia• Clean Clothes Campaign• RIPE• Cambridge University• Royal College of Surgeons• Oxford University Clinical Academic Graduate

School• ... and many more

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #34

Page 35: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

Speedby Jim Fulton

1000’s of Transactions per second

For simple transactions relational databases are slightly faster

For complex transactions ZODB is faster.

Try to write 10 different clases, in ZODB just append to a file, an RDB requires 10 different writes.

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #35

Page 36: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

Scalability

Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration with most data in a main database and a catalog database. The databases had several hundred gigabytes of ordinary database records plus multiple terabytes of blob data.

For larger systems move to NEO (neo.nexedi.com). Up to 80TB in production. 150TB (and growing) in test. Of course it takes time to move that much data around.

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #36

Page 37: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

Number of Objects

18,446,744,073,709,551,616 Objects

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #37

Page 38: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

SecurityZeroDB Decrypts Everything on the Client.

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #38

Page 39: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

MQTT Pub/Sub For Real-Time ChatMQTT.org

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #39

Subscribers

Page 40: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

ZODB is for Small Companies

Big Companies Small Companies

Big Data Quality Data

Database-Centric Object-Centric

Manage Complexity KISS. Pug

Armies of Transient Developers One Senior Dedicated Developer

Fad Driven Technology Driven

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #40

Page 41: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

Questions ?Follow @PythonLinks

on Twitter

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #41

Page 42: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

Contact InformationFollow @PythonLinks on Twitter

Christopher Lozinski

Http://PythonLinks.info

EMail: [email protected]

Twitter: @PythonLinks

Skype: clozinski

US Phone: +1 (650) 614 1836

EU Phone: +48 12 361 3136

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #42

Page 43: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

Storing Chat Logs

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #43

Object 1

Object 2

Object 3

Page 44: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

Chat Logs After Batching

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #44

Object 1

Object 2

Object 3

Object 3 Version 2

Object 2 Version 2

Object 1 Version 2

Page 45: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

Follow @PythonLinks

on Twitter

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #45

Page 46: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

Contact InformationFollow @PythonLinks on Twitter

Christopher Lozinski

Http://PythonLinks.info

EMail: [email protected]

Twitter: @PythonLinks

Skype: clozinski

US Phone: +1 (650) 614 1836

EU Phone: +48 12 361 3136

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #46

Page 47: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

PythonLinks is a Content Aggregation System

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #47

PyCon UK

PyData

EuroPythonPyCon US

PyCon CZYouTube SciPi

PythonLinks. info

Page 48: ZODB: A Presistent Graph of Python Objects · 2020-03-22 · Scalability Several hundred newspaper content-management systems and web sites were hosted using a multi-database configuration

Content Aggregation Syste

Plone is a Content Management System.

Blogory is also a Content Aggregation System

t© Christopher Lozinski CC BY-NC 3.0 US PythonLinks.info/zodb #48


Recommended