Bfg Ploneconf Oct2008
Upcoming SlideShare
Loading in...5
×
 

Bfg Ploneconf Oct2008

on

  • 2,209 views

 

Statistics

Views

Total Views
2,209
Views on SlideShare
2,100
Embed Views
109

Actions

Likes
1
Downloads
12
Comments
1

2 Embeds 109

http://plone.org 108
http://www.slideshare.net 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Bfg Ploneconf Oct2008 Bfg Ploneconf Oct2008 Presentation Transcript

    • the repoze.bfg web framework Presented By Chris McDonough Agendaless Consulting Plone Conference 2008
    • • About a year old. • Allow Zope developers to use WSGI technologies more easily. • Allow non-Zope developers to use Zope technologies without using all of Zope.
    • • repoze.bfg: July 2008 • Chris McDonough, Tres Seaver, Paul Everitt, Carlos de la Guardia, Malthe Borch, Stefan Eletzhofer, Fernando Neto-Correa. • Big f'ing gun -OR- big friendly giant: you choose.
    • WHY? • Zope2: still kicking, but only due to Plone • Zope3: big, many dependencies. App developers encouraged to use CA. • Grok: quot;making Z3 easier to usequot; (see Zope 3). • Django: nice, but Z2-like. • Pylons/TG2: nice, but geared towards RDB / URL dispatch apps. • Others: not Zope-like / no traction.
    • Goals • Familiarity: like Zope, but less • Simplicity: pay only for what you eat • Speed: go as fast as possible while still actually doing something • Documentation: the lack of formal documentation of a feature or API is a bug • Collaboration: culture of using and promoting non-Zope stuff
    • What BFG Does • Maps URLs to code • Provides mechanisms that allow developers to make declarative security assertions • Provides text and HTML templating facilities • Allows for use of existing Zope libs (via ZCML).
    • What BFG Doesn't Do • Database / persistence • Sessions • Indexing / searching • ZMI / TTW code • View code sharing with Z3 / Five • etc...
    • The Application is the Application • You don't write quot;Productsquot; to plug into BFG. Extensibility is via normal Python packages and ZCML as necessary. • An application is generated for you; you develop the application and run the application; you don't run the framework.
    • Graph Traversal and URL Dispatch • BFG supports both graph traversal (ala Zope) and quot;URL dispatchquot; (ala everything else) to map URLs to code. • URL dispatch is backed by Routes.
    • Zope CA • The Zope Component Architecture was used to construct BFG. • BFG application developers don't need to use the CA. It's a framework implementation detail.
    • Components • WSGI pipeline. • Router (aka Publisher). • quot;Application registryquot; (ZCML / decorators). • Views (aka quot;controllersquot; in Pylons/Rails). • Templates (chameleon/XSL/other).
    • Dependencies Paste-1.7.1-py2.4.egg zope.deferredimport-3.4.0-py2.4.egg PasteDeploy-1.3.2-py2.4.egg zope.deprecation-3.4.0-py2.4.egg PasteScript-1.6.3-py2.4.egg zope.event-3.4.0-py2.4.egg Routes-1.9.2-py2.4.egg zope.exceptions-3.5.2-py2.4.egg WebOb-0.9.2-py2.4.egg zope.hookable-3.4.0-py2.4-macosx-10.5-i386.egg zope.i18n-3.5.0-py2.4.egg zope.proxy-3.4.1-py2.4-macosx-10.5-i386.egg elementtree-1.2.6_20050316-py2.4.egg zope.i18nmessageid-3.4.3-py2.4-macosx-10.5-i386.egg lxml-2.1.1-py2.4-macosx-10.5-i386.egg zope.interface-3.4.1-py2.4-macosx-10.5-i386.egg pytz-2008c-py2.4.egg zope.location-3.4.0-py2.4.egg setuptools-0.6c8-py2.4.egg zope.publisher-3.5.3-py2.4.egg zope.schema-3.4.0-py2.4.egg zope.traversing-3.5.0a3-py2.4.egg z3c.pt-1.0a1-py2.4.egg zope.security-3.5.1-py2.4-macosx-10.5-i386.egg zope.component-3.4.0-py2.4.egg zope.testing-3.5.1-py2.4.egg zope.configuration-3.4.0-py2.4.egg Many are due to inappropriate dependencies in Zope eggs.
    • How it Works
    • Models • quot;contentquot; objects • typically arranged in a graph (although not required) • For Zope people: think ZODB • ZODB not required for repoze.bfg applications: filesystem directories, XML documents, RDF graphs, SQL databases, etc. can be the source of model data
    • A Model from zope.interface import implements from zope.interface import Interface class IMyModel(Interface): pass class MyModel(object): implements(IMyModel) def __init__(self, name): self.name = name
    • Views • Views are functions which accept a quot;contextquot; (a model object) and a quot;requestquot;. • Views must return a response. Unlike Zope. • The view may use a template to generate the response body, or not.
    • A View from webob import Response def hello_world(context, request): return Response('Hello world!')
    • A View That Renders a chameleon.zpt Template from repoze.bfg.chameleon_zpt import render_template_to_response def hello_world(context, request): render_template_to_response( 'templates/hello.pt', context=context, myname='chris')
    • Using Model Data from a View from webob import Response def hello_world(context, request): name = context.name return Response('Hello %s!' % name)
    • Templates • Default templating engine: chalmeleon by Malthe Borch. ZPT or Genshi syntax. ~ 10X - 15X faster than zope.pagetemplate. • Included: XSLT. • Add-on: jinja2 (Django-style, via repoze.bfg.jinja2) • Any other you'd like to use; bindings are simple to create (see the jinja2 bindings).
    • Traversal • The BFG router traverses the model graph based on the path segments in the URL (like Zope does). • If traversal quot;falls offquot; the end of the model graph, and there are path segments remaining, it looks for a view registered against the interface of the last model traversed using the next path segment as the view name. • If there are no segments remaining, the default view is used. • If no view is found, a 404 not found error is returned.
    • View Registrations <configure xmlns=quot;http://namespaces.zope.org/zopequot; xmlns:bfg=quot;http://namespaces.repoze.org/bfgquot; i18n_domain=quot;repoze.bfgquot;> <include package=quot;repoze.bfgquot; /> <— default view for .interfaces.IMyModel —> <bfg:view for=quot;.interfaces.IMyModelquot; view=quot;.views.my_viewquot; /> <— named view for .interfaces.IMyModel —> <bfg:view for=quot;.interfaces.IMyModelquot; view=quot;.views.other_viewquot; name=quot;otherquot; /> </configure>
    • View Registrations via Decorators from webob import Response from repoze.bfg.convention import bfg_view @bfg_view(name='hello.html') def hello_world(context, request): name = context.name return Response('Hello %s!' % name)
    • Speed <html xmlns=quot;http://www.w3.org/1999/xhtmlquot; xmlns:tal=quot;http://xml.zope.org/namespaces/talquot;> <head> <title tal:content=quot;context.titlequot;>The title</title> <meta http-equiv=quot;content-typequot; content=quot;text/html;charset=utf-8quot;/> </head> <body> <h2><span tal:replace=quot;context.title_or_id()quot;>content title or id</span> <span tal:condition=quot;context.titlequot; tal:replace=quot;context.titlequot;>optional template title</span></h2> This is Page Template <em tal:content=quot;request.view_namequot;>template id</em>. </body> </html> Zope 2.10 view page template: 309 req/sec vs. BFG view + chameleon.zpt template: 869 req/sec
    • Memory Usage and Process Sharing • Existing Zope 2 and Zope 3 apps cannot run side-by-side in the same process due to globals sharing (ZCML global registry, database references); BFG has been written to make such a configuration work by default. • Lower memory requirements per application instance (BFG minimum ~15 MB vs. Zope 3 minimum ~50MB).
    • Startup Speed • repoze.bfg caches the ZCML registry as a pickle for faster startup. • Startup time with a single view defined: 900ms.
    • Paste-Derived Reload Feature [chrism@vitaminf myproj]$ ../bin/paster serve myproj.ini —reload Starting subprocess with file monitor Starting server in PID 61405. serving on 0.0.0.0:6543 view at http://127.0.0.1:6543 /Users/chrism/projects/repoze/bfgenv/myproj/myproj/run.py changed; reloading... —————————— Restarting —————————— Starting server in PID 61409. serving on 0.0.0.0:6543 view at http://127.0.0.1:6543
    • Template Auto-Reload Feature • Templates auto-reload by default. • This can be turned off for speed.
    • WSGI-Middleware- Derived Features • Profiler (repoze.profile) • Alternate exception handlers (paste.evalexception). • Caching (repoze.accelerator) • Theming (Deliverance). • Transaction management (repoze.tm2) • etc...
    • Project Setup Demo
    • Futures • Vudo CMS (http://docs.vudo.me) to be implemented using repoze.bfg, hopefully. Work towards this: repoze.bfg.skins, repoze.bfg.layout, repoze.bitblt, repoze.squeeze. • BFG will stay minimal. Add-ons and superframeworks like vudo and repoze.lemonade will provide functionality.
    • The End • For a more in-depth exploration of how a bfg app is written, see the screencast at http://static.repoze.org/presentations/repozebfg-wiki.mov