SlideShare una empresa de Scribd logo
1 de 25
Descargar para leer sin conexión
ZODB Tips and Tricks

  Carlos de la Guardia
Most important performance tip

   Find the best size for the ZODB object cache.
   How to calculate best size: take amount of
    available memory and divide by one ;)
   Corollary: Increase RAM as a first step when
    you want better performance.
Looking inside the ZODB

   collective.zodbbrowser is a package that has to
    be installed inside Zope and provides access to
    all objects and their attributes, including
    callables and their source code.
   Eye is an external tool that can be used to
    browse the ZODB without having to install all
    the products it uses.
   You can always use the low-tech approach and
    use the debug mode of an instance to look at
    the values directly using Python.
Oh My God, a POSKey error!

   I feel your pain.
   Unfortunately, getting into the details of how to
    fix this would take a full talk.
   All is not lost, but you'll need to fire up debug
    mode and poke into the internals of your ZODB.
   Before anything else: MAKE A BACKUP!
   Some detailed information here:
    http://plonechix.blogspot.com/2009/12/definitive
    -guide-to-poskeyerror.html
Getting rid of persistent utilities

   Older products that you uninstall sometimes
    can leave persistent utilities installed.
   This will crash your site, because Zope will try
    to import that code.
   There is a package that can help (but
    remember, backup first!):

    http://pypi.python.org/pypi/wildcard.fixpersistent
    utilities/
Recovering objects

   Brute force way: truncate the database
   The civiliced way: use zc.beforestorage
    %import zc.beforestorage
    <before>
      before 2008-12-08T10:29:03
      <filestorage>
         path /zope/var/filestortage/Data.fs
      </filestorage>
    </before>
Searching for transactions

from ZODB.TimeStamp import TimeStamp
from ZODB.FileStorage import FileStorage

storage = FileStorage('/path/to/data.fs', read_only=True)
it = storage.iterator()

earliest = TimeStamp(2010, 2, 26, 6, 0, 0)
# the above is in GMT

for txn in it:
   tid = TimeStamp(txn.tid)
   if tid > earliest:
       print txn.user, txn.description, tid.timeTime(), txn.tid.encode('base64')
       for rec in txn:
          print rec.pos
RelStorage
   A storage implementation for ZODB that stores pickles in a
    relational database.
   It is a drop-in replacement for FileStorage and ZEO.
   Designed for high volume sites: multiple ZODB instances
    can share the same database. This is similar to ZEO, but
    RelStorage does not require ZEO.
   According to some tests, RelStorage handles high
    concurrency better than the standard combination of ZEO
    and FileStorage.
   RelStorage starts quickly regardless of database size.
   Supports undo, packing, and filesystem-based ZODB
    blobs.
   Capable of failover to replicated SQL databases.
Interesting packages

   zodbshootout – benchmark ZEO vs RelStorage
    with different backends
   zodbupdate – update moved or renamed
    classes
   dm.historical – get history of objects in the
    ZODB
   dm.zodb.repair – restore lost objects from a
    backup to a target database
   zc.zodbactivitylog - provides an activity log that
    lets you track database activity
Beginner tips for ZODB development
    Do not use the root to store objects. It doesn't scale.
    Learn about BTrees.
    Avoid storing mutable objects, use persistent sub-
     objects.
    If your objects are bigger than 64k, you need to divide
     them or use blobs.
    Avoid conflicts, organize application threads and data
     structures so that objects are unlikely to be modified
     by multiple threads at the same time.
    Use data structures that support conflict resolution.
    To resolve conflicts, retry. The developer is in charge
     of managing concurrency, not the database.
Tips From the Experts




    I asked some of the old time Zope
developers for some simple tips for using
  the ZODB. Here are their responses.
David Glick

  ”If you want instances of a class to have a new
attribute, add it as a class attribute so that existing
         instances get a reasonable default”
Tips From the Experts




               Lennart Regebro

”Products.ZMIntrospection is quick way to look at
 all the fields of any ZODB object from the ZMI.”
Tips From the Experts


                  Alec Mitchell

”If you need to store arbitrary key/value pairs: use
 PersistentDict when the amount of data is "small"
  and/or you tend to require all the data in a given
transaction; use OOBTree (and friends) when you
   have a large number of keys and tend to only
   need a small subset of them in a transaction.”
Tips From the Experts



                  Alec Mitchell

 ”If you store data in one of the BTree structures
   and you need to count the number of entries,
don't use len(), ever. Use a Btrees.Length object
       to keep track of the count separately.”
Tips From the Experts




                 Alan Runyan

”use zc.zlibstorage for txt heavy databases it's a
    60-70% storage win for those records. ”
zc.zlibstorage

Standalone:                 With ZEO:
%import zc.zlibstorage    %import zc.zlibstorage
<zodb>                    <zeo>
 <zlibstorage>             address 8100
  <filestorage>           </zeo>
   path data.fs           <serverzlibstorage>
  </filestorage>           <filestorage>
 </zlibstorage>             path data.fs
</zodb>                    </filestorage>
                          </serverzlibstorage>
Tips From the Experts



                Alan Runyan

”Use zc.zodbgc, awesome library which provides
inverse graph of ZODB tree so you can see what
           leafs are referneced from”
zc.zodbdgc

   To use zc.zodbdgc just a part to the buildout
    that pulls the egg:

[zodbdgc]
recipe = zc.recipe.egg
eggs = ${instance:eggs}


You can the call the multi-zodb-gc and multi-zodb-
checkrefs.
Tips From the Experts


               Chris McDonough

 ”Use the "BTrees.Length" object to implement
counters in the ZODB. It has conflict resolution
  built in to it that has the potential to eliminate
conflict errors (as opposed to a normal integer
    counter attached to a persistent object).”
Tips From the Experts



                  Tres Seaver

   ”If you find yourself under intense fire, and
everything around you is crumbling, don't despair,
     just increase the ZEO client cache size”
Which cache is which

   Don't confuse the ZEO client cache with the ZODB
    object cache.
   The ZODB object cache stores objects in memory for
    faster responses. You set it with zodb-cache-size in a
    buildout.
   The ZEO client cache is used first when amn object is
    not in the ZODB object cache and avoids round trips
    to the ZEO server. You set it with zeo-client-cache-
    size in a buildout.
   You can enable cache tracing for analysis by setting
    the ZEO_CACHE_TRACE environment variable. More
    information at:
    http://wiki.zope.org/ZODB/trace.html
Tips From the Experts




             Jim Fulton

”Avoid non-persistent mutable objects”
Tips From the Experts




       Jim Fulton

     ”Don't be clever”
Thank You!

         Email: cguardia@yahoo.com

http://zodb.readthedocs.org/en/latest/index.html

Más contenido relacionado

La actualidad más candente

Linux Kernel Extension for Databases / Александр Крижановский (Tempesta Techn...
Linux Kernel Extension for Databases / Александр Крижановский (Tempesta Techn...Linux Kernel Extension for Databases / Александр Крижановский (Tempesta Techn...
Linux Kernel Extension for Databases / Александр Крижановский (Tempesta Techn...
Ontico
 
glance replicator
glance replicatorglance replicator
glance replicator
irix_jp
 
Pgbr 2013 postgres on aws
Pgbr 2013   postgres on awsPgbr 2013   postgres on aws
Pgbr 2013 postgres on aws
Emanuel Calvo
 

La actualidad más candente (19)

Centralized + Unified Logging
Centralized + Unified LoggingCentralized + Unified Logging
Centralized + Unified Logging
 
Postgres-BDR with Google Cloud Platform
Postgres-BDR with Google Cloud PlatformPostgres-BDR with Google Cloud Platform
Postgres-BDR with Google Cloud Platform
 
PostgreSQL
PostgreSQLPostgreSQL
PostgreSQL
 
Linux Kernel Extension for Databases / Александр Крижановский (Tempesta Techn...
Linux Kernel Extension for Databases / Александр Крижановский (Tempesta Techn...Linux Kernel Extension for Databases / Александр Крижановский (Tempesta Techn...
Linux Kernel Extension for Databases / Александр Крижановский (Tempesta Techn...
 
GitLab PostgresMortem: Lessons Learned
GitLab PostgresMortem: Lessons LearnedGitLab PostgresMortem: Lessons Learned
GitLab PostgresMortem: Lessons Learned
 
HADOOP 실제 구성 사례, Multi-Node 구성
HADOOP 실제 구성 사례, Multi-Node 구성HADOOP 실제 구성 사례, Multi-Node 구성
HADOOP 실제 구성 사례, Multi-Node 구성
 
glance replicator
glance replicatorglance replicator
glance replicator
 
Administering and Monitoring SolrCloud Clusters
Administering and Monitoring SolrCloud ClustersAdministering and Monitoring SolrCloud Clusters
Administering and Monitoring SolrCloud Clusters
 
Perl Memory Use - LPW2013
Perl Memory Use - LPW2013Perl Memory Use - LPW2013
Perl Memory Use - LPW2013
 
Advanced Replication
Advanced ReplicationAdvanced Replication
Advanced Replication
 
PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).
PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).
PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).
 
2015.07.16 Способы диагностики PostgreSQL
2015.07.16 Способы диагностики PostgreSQL2015.07.16 Способы диагностики PostgreSQL
2015.07.16 Способы диагностики PostgreSQL
 
GOTO 2013: Why Zalando trusts in PostgreSQL
GOTO 2013: Why Zalando trusts in PostgreSQLGOTO 2013: Why Zalando trusts in PostgreSQL
GOTO 2013: Why Zalando trusts in PostgreSQL
 
Pgbr 2013 postgres on aws
Pgbr 2013   postgres on awsPgbr 2013   postgres on aws
Pgbr 2013 postgres on aws
 
Elastic 101 tutorial - Percona Europe 2018
Elastic 101 tutorial - Percona Europe 2018 Elastic 101 tutorial - Percona Europe 2018
Elastic 101 tutorial - Percona Europe 2018
 
Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)
 
PostgreSQL and RAM usage
PostgreSQL and RAM usagePostgreSQL and RAM usage
PostgreSQL and RAM usage
 
Troubleshooting PostgreSQL with pgCenter
Troubleshooting PostgreSQL with pgCenterTroubleshooting PostgreSQL with pgCenter
Troubleshooting PostgreSQL with pgCenter
 
MongoDB – Sharded cluster tutorial - Percona Europe 2017
MongoDB – Sharded cluster tutorial - Percona Europe 2017MongoDB – Sharded cluster tutorial - Percona Europe 2017
MongoDB – Sharded cluster tutorial - Percona Europe 2017
 

Destacado

Destacado (7)

Magic in ruby
Magic in rubyMagic in ruby
Magic in ruby
 
Ruby objects
Ruby objectsRuby objects
Ruby objects
 
Designing Ruby APIs
Designing Ruby APIsDesigning Ruby APIs
Designing Ruby APIs
 
MongoDB - Ruby document store that doesn't rhyme with ouch
MongoDB - Ruby document store that doesn't rhyme with ouchMongoDB - Ruby document store that doesn't rhyme with ouch
MongoDB - Ruby document store that doesn't rhyme with ouch
 
HTML Lecture Part 1 of 2
HTML Lecture Part 1 of 2HTML Lecture Part 1 of 2
HTML Lecture Part 1 of 2
 
Ruby object model
Ruby object modelRuby object model
Ruby object model
 
The Black Magic of Ruby Metaprogramming
The Black Magic of Ruby MetaprogrammingThe Black Magic of Ruby Metaprogramming
The Black Magic of Ruby Metaprogramming
 

Similar a ZODB Tips and Tricks

Cloud Best Practices
Cloud Best PracticesCloud Best Practices
Cloud Best Practices
Eric Bottard
 
Pse2010 rel storage
Pse2010 rel storagePse2010 rel storage
Pse2010 rel storage
Lars Noldan
 
Intro to BackboneJS + Intermediate Javascript
Intro to BackboneJS + Intermediate JavascriptIntro to BackboneJS + Intermediate Javascript
Intro to BackboneJS + Intermediate Javascript
Andrew Lovett-Barron
 
Adventures in Multithreaded Core Data
Adventures in Multithreaded Core DataAdventures in Multithreaded Core Data
Adventures in Multithreaded Core Data
Inferis
 

Similar a ZODB Tips and Tricks (20)

node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoon
 
Cloud Best Practices
Cloud Best PracticesCloud Best Practices
Cloud Best Practices
 
Python mongo db-training-europython-2011
Python mongo db-training-europython-2011Python mongo db-training-europython-2011
Python mongo db-training-europython-2011
 
Perl and Elasticsearch
Perl and ElasticsearchPerl and Elasticsearch
Perl and Elasticsearch
 
Pse2010 rel storage
Pse2010 rel storagePse2010 rel storage
Pse2010 rel storage
 
Intro to BackboneJS + Intermediate Javascript
Intro to BackboneJS + Intermediate JavascriptIntro to BackboneJS + Intermediate Javascript
Intro to BackboneJS + Intermediate Javascript
 
Lessons Learned Migrating 2+ Billion Documents at Craigslist
Lessons Learned Migrating 2+ Billion Documents at CraigslistLessons Learned Migrating 2+ Billion Documents at Craigslist
Lessons Learned Migrating 2+ Billion Documents at Craigslist
 
SFDX – Myth Buster, Svatopluk Sejkora
SFDX – Myth Buster, Svatopluk SejkoraSFDX – Myth Buster, Svatopluk Sejkora
SFDX – Myth Buster, Svatopluk Sejkora
 
MongoDB Pros and Cons
MongoDB Pros and ConsMongoDB Pros and Cons
MongoDB Pros and Cons
 
Monitoring Oracle Database Instances with Zabbix
Monitoring Oracle Database Instances with ZabbixMonitoring Oracle Database Instances with Zabbix
Monitoring Oracle Database Instances with Zabbix
 
10 Ways To Improve Your Code
10 Ways To Improve Your Code10 Ways To Improve Your Code
10 Ways To Improve Your Code
 
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Performance Tuning -  Memory leaks, Thread deadlocks, JDK toolsPerformance Tuning -  Memory leaks, Thread deadlocks, JDK tools
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
 
Toro DB- Open-source, MongoDB-compatible database, built on top of PostgreSQL
Toro DB- Open-source, MongoDB-compatible database,  built on top of PostgreSQLToro DB- Open-source, MongoDB-compatible database,  built on top of PostgreSQL
Toro DB- Open-source, MongoDB-compatible database, built on top of PostgreSQL
 
GWT is Smarter Than You
GWT is Smarter Than YouGWT is Smarter Than You
GWT is Smarter Than You
 
2019 PHP Serbia - Boosting your performance with Blackfire
2019 PHP Serbia - Boosting your performance with Blackfire2019 PHP Serbia - Boosting your performance with Blackfire
2019 PHP Serbia - Boosting your performance with Blackfire
 
Adventures in Multithreaded Core Data
Adventures in Multithreaded Core DataAdventures in Multithreaded Core Data
Adventures in Multithreaded Core Data
 
Dojo: Getting Started Today
Dojo: Getting Started TodayDojo: Getting Started Today
Dojo: Getting Started Today
 
Why databases cry at night
Why databases cry at nightWhy databases cry at night
Why databases cry at night
 
Zend framework 03 - singleton factory data mapper caching logging
Zend framework 03 - singleton factory data mapper caching loggingZend framework 03 - singleton factory data mapper caching logging
Zend framework 03 - singleton factory data mapper caching logging
 
Operating and Supporting Delta Lake in Production
Operating and Supporting Delta Lake in ProductionOperating and Supporting Delta Lake in Production
Operating and Supporting Delta Lake in Production
 

Más de Carlos de la Guardia

Más de Carlos de la Guardia (10)

Introduction to the transaction package
Introduction to the transaction packageIntroduction to the transaction package
Introduction to the transaction package
 
Pyramid as a base for higher level frameworks
Pyramid as a base for higher level frameworksPyramid as a base for higher level frameworks
Pyramid as a base for higher level frameworks
 
Pyramid patterns
Pyramid patternsPyramid patterns
Pyramid patterns
 
Pyramid tutorial
Pyramid tutorialPyramid tutorial
Pyramid tutorial
 
Pyramid faq
Pyramid faqPyramid faq
Pyramid faq
 
Python intro for Plone users
Python intro for Plone usersPython intro for Plone users
Python intro for Plone users
 
Pyramid deployment
Pyramid deploymentPyramid deployment
Pyramid deployment
 
A winning combination: Plone as CMS and your favorite Python web framework as...
A winning combination: Plone as CMS and your favorite Python web framework as...A winning combination: Plone as CMS and your favorite Python web framework as...
A winning combination: Plone as CMS and your favorite Python web framework as...
 
World Plone Day 2008 Mexico
World Plone Day 2008 MexicoWorld Plone Day 2008 Mexico
World Plone Day 2008 Mexico
 
Turning Plone into a dynamic site factory
Turning Plone into a dynamic site factoryTurning Plone into a dynamic site factory
Turning Plone into a dynamic site factory
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

ZODB Tips and Tricks

  • 1. ZODB Tips and Tricks Carlos de la Guardia
  • 2. Most important performance tip  Find the best size for the ZODB object cache.  How to calculate best size: take amount of available memory and divide by one ;)  Corollary: Increase RAM as a first step when you want better performance.
  • 3. Looking inside the ZODB  collective.zodbbrowser is a package that has to be installed inside Zope and provides access to all objects and their attributes, including callables and their source code.  Eye is an external tool that can be used to browse the ZODB without having to install all the products it uses.  You can always use the low-tech approach and use the debug mode of an instance to look at the values directly using Python.
  • 4. Oh My God, a POSKey error!  I feel your pain.  Unfortunately, getting into the details of how to fix this would take a full talk.  All is not lost, but you'll need to fire up debug mode and poke into the internals of your ZODB.  Before anything else: MAKE A BACKUP!  Some detailed information here: http://plonechix.blogspot.com/2009/12/definitive -guide-to-poskeyerror.html
  • 5. Getting rid of persistent utilities  Older products that you uninstall sometimes can leave persistent utilities installed.  This will crash your site, because Zope will try to import that code.  There is a package that can help (but remember, backup first!): http://pypi.python.org/pypi/wildcard.fixpersistent utilities/
  • 6. Recovering objects  Brute force way: truncate the database  The civiliced way: use zc.beforestorage %import zc.beforestorage <before> before 2008-12-08T10:29:03 <filestorage> path /zope/var/filestortage/Data.fs </filestorage> </before>
  • 7. Searching for transactions from ZODB.TimeStamp import TimeStamp from ZODB.FileStorage import FileStorage storage = FileStorage('/path/to/data.fs', read_only=True) it = storage.iterator() earliest = TimeStamp(2010, 2, 26, 6, 0, 0) # the above is in GMT for txn in it: tid = TimeStamp(txn.tid) if tid > earliest: print txn.user, txn.description, tid.timeTime(), txn.tid.encode('base64') for rec in txn: print rec.pos
  • 8. RelStorage  A storage implementation for ZODB that stores pickles in a relational database.  It is a drop-in replacement for FileStorage and ZEO.  Designed for high volume sites: multiple ZODB instances can share the same database. This is similar to ZEO, but RelStorage does not require ZEO.  According to some tests, RelStorage handles high concurrency better than the standard combination of ZEO and FileStorage.  RelStorage starts quickly regardless of database size.  Supports undo, packing, and filesystem-based ZODB blobs.  Capable of failover to replicated SQL databases.
  • 9. Interesting packages  zodbshootout – benchmark ZEO vs RelStorage with different backends  zodbupdate – update moved or renamed classes  dm.historical – get history of objects in the ZODB  dm.zodb.repair – restore lost objects from a backup to a target database  zc.zodbactivitylog - provides an activity log that lets you track database activity
  • 10. Beginner tips for ZODB development  Do not use the root to store objects. It doesn't scale.  Learn about BTrees.  Avoid storing mutable objects, use persistent sub- objects.  If your objects are bigger than 64k, you need to divide them or use blobs.  Avoid conflicts, organize application threads and data structures so that objects are unlikely to be modified by multiple threads at the same time.  Use data structures that support conflict resolution.  To resolve conflicts, retry. The developer is in charge of managing concurrency, not the database.
  • 11. Tips From the Experts I asked some of the old time Zope developers for some simple tips for using the ZODB. Here are their responses.
  • 12. David Glick ”If you want instances of a class to have a new attribute, add it as a class attribute so that existing instances get a reasonable default”
  • 13. Tips From the Experts Lennart Regebro ”Products.ZMIntrospection is quick way to look at all the fields of any ZODB object from the ZMI.”
  • 14. Tips From the Experts Alec Mitchell ”If you need to store arbitrary key/value pairs: use PersistentDict when the amount of data is "small" and/or you tend to require all the data in a given transaction; use OOBTree (and friends) when you have a large number of keys and tend to only need a small subset of them in a transaction.”
  • 15. Tips From the Experts Alec Mitchell ”If you store data in one of the BTree structures and you need to count the number of entries, don't use len(), ever. Use a Btrees.Length object to keep track of the count separately.”
  • 16. Tips From the Experts Alan Runyan ”use zc.zlibstorage for txt heavy databases it's a 60-70% storage win for those records. ”
  • 17. zc.zlibstorage Standalone: With ZEO: %import zc.zlibstorage %import zc.zlibstorage <zodb> <zeo> <zlibstorage> address 8100 <filestorage> </zeo> path data.fs <serverzlibstorage> </filestorage> <filestorage> </zlibstorage> path data.fs </zodb> </filestorage> </serverzlibstorage>
  • 18. Tips From the Experts Alan Runyan ”Use zc.zodbgc, awesome library which provides inverse graph of ZODB tree so you can see what leafs are referneced from”
  • 19. zc.zodbdgc  To use zc.zodbdgc just a part to the buildout that pulls the egg: [zodbdgc] recipe = zc.recipe.egg eggs = ${instance:eggs} You can the call the multi-zodb-gc and multi-zodb- checkrefs.
  • 20. Tips From the Experts Chris McDonough ”Use the "BTrees.Length" object to implement counters in the ZODB. It has conflict resolution built in to it that has the potential to eliminate conflict errors (as opposed to a normal integer counter attached to a persistent object).”
  • 21. Tips From the Experts Tres Seaver ”If you find yourself under intense fire, and everything around you is crumbling, don't despair, just increase the ZEO client cache size”
  • 22. Which cache is which  Don't confuse the ZEO client cache with the ZODB object cache.  The ZODB object cache stores objects in memory for faster responses. You set it with zodb-cache-size in a buildout.  The ZEO client cache is used first when amn object is not in the ZODB object cache and avoids round trips to the ZEO server. You set it with zeo-client-cache- size in a buildout.  You can enable cache tracing for analysis by setting the ZEO_CACHE_TRACE environment variable. More information at: http://wiki.zope.org/ZODB/trace.html
  • 23. Tips From the Experts Jim Fulton ”Avoid non-persistent mutable objects”
  • 24. Tips From the Experts Jim Fulton ”Don't be clever”
  • 25. Thank You! Email: cguardia@yahoo.com http://zodb.readthedocs.org/en/latest/index.html