[Catalyst] Serving "static" content from DB

Mihai Bazon mihai at bazon.net
Sat Jun 6 18:58:19 GMT 2009


John Romkey <romkey at apocalypse.org> wrote:
> On Jun 6, 2009, at 7:41 AM, Ian Docherty wrote:
> > Mihai Bazon wrote:
> >> Hi folks,
> >>
> >> I'm working on a simple CMS (actually started it for learning  
> >> Catalyst,
> >> but the goal is to be able to maintain a few websites with it).  Each
> >> page is stored in DB and it can have file attachments, also stored  
> >> in DB
> >> (content is BLOB).
> >>
> > I may get shot down in flames for this, but I would not personally  
> > put page data or attachments into the DB in the first place. I would  
> > put the page into the filesystem and use the DB to reference the  
> > file contents. This would also satisfy your cache problems since you  
> > can retrieve the static data directly from the filesystem.
> 
> I agree whole-heartedly.
> 
> There are very few drawbacks to serving directly from the filesystem  
> (only one I can think of, which has to do with access control to the  
> content), while there are several when serving from the DB, mostly  
> performance-related.

I am aware of the performance quirks, but I'm still a fan of holding all
the content into the DB.  In fact, the bigger plan is to store templates
and CSS/JS files in the DB as well.  MySQL blobs are pretty fast, btw.

Performance should be (almost) the same as for static files if I
implement a handler that (1) updates the static file from DB when it's
out of date and (2) DECLINE-s the request so that Apache^W the web
server itself can further serve the file.

Catalyst::Plugin::Static::Simple is doing the job (not strictly what I
asked though), but I'm not speaking a million requests per day.  I
looked at the source--it sets $c->response->body($filehandle).  It's
elegant, but probably slow.  When the need comes, I'll figure out
something faster -- but for now all I can think of is "early
optimization is the root of all evil". ;-)

Cheers,
-Mihai


More information about the Catalyst mailing list