ActionEmbedding
-
Upload
philcowans -
Category
Technology
-
view
797 -
download
0
description
Transcript of ActionEmbedding
ActionEmbedding
Phil Cowans - LRUG, July 2010
Pagelets
(http://www.facebook.com/notes/facebook-engineering/bigpipe-pipelining-web-pages-for-high-performance/389414033919)
Characteristics Of Pagelets
• Substantial content.• Independence from the containing page.• Potential to be handled by a back-end service.• Can typically be cached.• Localisation.
Why Think About Pages This Way?
• Helps define a ubiquitous language.• Clean code: separation of responsibilities.• Code reuse.• Scalability.
Existing Tools / Patterns / Work
• Rails:o ActionController::Components in early versions of Rails -
dropped for performance reasons.o Cells - plugin implementing similar functionality.o Embedded Actions - another plugin.
• Elsewhere:o Kohana - PHP framework based on Hierarchical Model-
View-Controller (HMVC) pattern.o Facebook BigPipe framework - Javascript tricks to get as
much of the page to render as quickly as possible.
Why Start Again?
• An excuse to dig around inside of Rails.• Experiment with various techniques for composing content.• Make it easy for pagelet infrastructure to grow with the
application:o Easy to start using pagelets without complex
infrastructure.o Confidence that it will be possible to swap in more
sophisticated embedding mechanisms without a rewrite.• A couple of niggles with existing work:
o Wanted to reuse ActionController::Base for pagelets, rather than defining a new class.
o Use paths/URLs internally rather than controller/action/params.
HMVC
• Pagelet render handled by secondary internal request.
• Secondary request handled by standard Rails Controller / View (you can hit it directly if you want).
Request Forwarding
• Primary application forwards request to back end server
• Separate tier scales independently.• Useful tricks: time out slow back end
requests, silently drop pagelet on exception, easy killswitch for feature if necessary.
• Use appropriate mix of technologies - back end doesn't need to use same framework as front end, e.g. Sinatra for simple things.
Edge Side Includes
• Page composition handled by a proxy server.
• Works with proxies which support Edge Side Includes (e.g. Varnish)
XHR Composition
• Pagelets are loaded via secondary XHR requests in JavaScript.
Other Options (not yet implemented)
• Parallel execution.o Potential to scale out for latency.
• BigPipe style composition.
Internals
• HMVC requests use Rack internally.• Easy on Rails 2.3, as routing and controller speak Rack
natively - can just inject request into later parts of standard processing pipeline.
• Rails 2.2 support (needed for SK) - backport bits of 2.3 to push Rack requests into controller.
Practical Experience
• Songkick activity feeds use ActionEmbedding / HMVC since Thursday.
• Measurable but relatively insignificant overhead - still room for improvement.
• Stable so far...
Issues / Todos
• Try XHR embedding in production.• Better exception handling (right now you get the error
embedded in the pagelet - should interpret response code).• Consistent approach to constructing nested requests:
o Headerso Access to cookies
• Security / access control.• Investigate patterns for configuring pagelets.