ActionEmbedding

16
ActionEmbedding Phil Cowans - LRUG, July 2010

description

Presentation on ActionEmbedding, a Rails plugin for working with pagelets. This talk was given at an LRUG meeting on July 12th 2010.

Transcript of ActionEmbedding

Page 1: ActionEmbedding

ActionEmbedding

Phil Cowans - LRUG, July 2010

Page 2: ActionEmbedding

Pagelets

(http://www.facebook.com/notes/facebook-engineering/bigpipe-pipelining-web-pages-for-high-performance/389414033919)

Page 3: ActionEmbedding
Page 4: ActionEmbedding

Characteristics Of Pagelets

• Substantial content.• Independence from the containing page.• Potential to be handled by a back-end service.• Can typically be cached.• Localisation.

Page 5: ActionEmbedding

Why Think About Pages This Way?

• Helps define a ubiquitous language.• Clean code: separation of responsibilities.• Code reuse.• Scalability.

Page 6: ActionEmbedding

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. 

Page 7: ActionEmbedding

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.

Page 8: ActionEmbedding

HMVC

• Pagelet render handled by secondary internal request.

• Secondary request handled by standard Rails Controller / View (you can hit it directly if you want).

Page 9: ActionEmbedding

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.

Page 10: ActionEmbedding

Edge Side Includes

• Page composition handled by a proxy server.

• Works with proxies which support Edge Side Includes (e.g. Varnish)

Page 11: ActionEmbedding

XHR Composition

• Pagelets are loaded via secondary XHR requests in JavaScript.

Page 12: ActionEmbedding

Other Options (not yet implemented)

• Parallel execution.o Potential to scale out for latency.

• BigPipe style composition.

Page 13: ActionEmbedding

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.

Page 14: ActionEmbedding

Practical Experience

• Songkick activity feeds use ActionEmbedding / HMVC since Thursday.

• Measurable but relatively insignificant overhead - still room for improvement.

• Stable so far...

Page 15: ActionEmbedding

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.

Page 16: ActionEmbedding

Thanks...

http://github.com/philcowans/action_embedding

[email protected]

@philcowans