<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Lazy Loading BLOBs in Active Record</title>
	<atom:link href="http://www.adaruby.com/2007/01/18/lazy-loading-blobs-in-active-record/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.adaruby.com/2007/01/18/lazy-loading-blobs-in-active-record/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=lazy-loading-blobs-in-active-record</link>
	<description>Rich Dynamic Applications with Ruby on Rails</description>
	<lastBuildDate>Fri, 03 Feb 2012 03:32:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: Casey</title>
		<link>http://www.adaruby.com/2007/01/18/lazy-loading-blobs-in-active-record/comment-page-1/#comment-95</link>
		<dc:creator>Casey</dc:creator>
		<pubDate>Tue, 29 Jan 2008 01:28:31 +0000</pubDate>
		<guid isPermaLink="false">http://adaruby.com/2007/01/18/lazy-loading-blobs-in-active-record/#comment-95</guid>
		<description>I wrote a lazy loading plugin... It&#039;s up on refactormycode.com &#039;cause I&#039;m not particularly proud of it :)

&lt;a href=&quot;http://refactormycode.com/codes/219-activerecord-lazy-attribute-loading-plugin-for-rails&quot; rel=&quot;nofollow&quot;&gt;http://refactormycode.com/codes/219-activerecord-lazy-attribute-loading-plugin-for-rails&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>I wrote a lazy loading plugin&#8230; It&#8217;s up on refactormycode.com &#8217;cause I&#8217;m not particularly proud of it <img src='http://www.adaruby.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://refactormycode.com/codes/219-activerecord-lazy-attribute-loading-plugin-for-rails" rel="nofollow">http://refactormycode.com/codes/219-activerecord-lazy-attribute-loading-plugin-for-rails</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hendy Irawan</title>
		<link>http://www.adaruby.com/2007/01/18/lazy-loading-blobs-in-active-record/comment-page-1/#comment-94</link>
		<dc:creator>Hendy Irawan</dc:creator>
		<pubDate>Sun, 09 Dec 2007 18:35:23 +0000</pubDate>
		<guid isPermaLink="false">http://adaruby.com/2007/01/18/lazy-loading-blobs-in-active-record/#comment-94</guid>
		<description>Joao:

As a quick workaround, I can only think of moving the huge BLOBs to flat files... :)</description>
		<content:encoded><![CDATA[<p>Joao:</p>
<p>As a quick workaround, I can only think of moving the huge BLOBs to flat files&#8230; <img src='http://www.adaruby.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joao Borges</title>
		<link>http://www.adaruby.com/2007/01/18/lazy-loading-blobs-in-active-record/comment-page-1/#comment-93</link>
		<dc:creator>Joao Borges</dc:creator>
		<pubDate>Fri, 07 Dec 2007 17:29:01 +0000</pubDate>
		<guid isPermaLink="false">http://adaruby.com/2007/01/18/lazy-loading-blobs-in-active-record/#comment-93</guid>
		<description>Hi Hendy,
After some googling about a problem I just found in a project of mine,
I found your post &quot;Lazy Loading BLOBs in Active Record&quot; in the site http://www.adaruby.com

I have been working on a RoR web application to serve as a simplified Document management system. My problem is the following:
After having provided the application for production, I just found out about the stupid amount of time taken by the query executed to retrieve a file stored in a bytea field
of my PostgreSQL DB (about 20 seconds for a 12 MB file!). In PHP, the same query takes just 0.5 seconds!
It also takes 6 seconds to save this same file to the DB!

I read somewhere that this has to do with the slowness of the parsing for blob objects to &quot;escape and unescape&quot; certain sequence characters...

So if this is so, there is no workaround to this problem, is there?

Much apreciated if you can give me some input to solve this problem.</description>
		<content:encoded><![CDATA[<p>Hi Hendy,<br />
After some googling about a problem I just found in a project of mine,<br />
I found your post &#8220;Lazy Loading BLOBs in Active Record&#8221; in the site <a href="http://www.adaruby.com" rel="nofollow">http://www.adaruby.com</a></p>
<p>I have been working on a RoR web application to serve as a simplified Document management system. My problem is the following:<br />
After having provided the application for production, I just found out about the stupid amount of time taken by the query executed to retrieve a file stored in a bytea field<br />
of my PostgreSQL DB (about 20 seconds for a 12 MB file!). In PHP, the same query takes just 0.5 seconds!<br />
It also takes 6 seconds to save this same file to the DB!</p>
<p>I read somewhere that this has to do with the slowness of the parsing for blob objects to &#8220;escape and unescape&#8221; certain sequence characters&#8230;</p>
<p>So if this is so, there is no workaround to this problem, is there?</p>
<p>Much apreciated if you can give me some input to solve this problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hendy Irawan</title>
		<link>http://www.adaruby.com/2007/01/18/lazy-loading-blobs-in-active-record/comment-page-1/#comment-92</link>
		<dc:creator>Hendy Irawan</dc:creator>
		<pubDate>Mon, 22 Jan 2007 02:52:59 +0000</pubDate>
		<guid isPermaLink="false">http://adaruby.com/2007/01/18/lazy-loading-blobs-in-active-record/#comment-92</guid>
		<description>Whoops, sorry!

I meant &quot;ERIK&quot;!!!

Sorry for the typo :-(</description>
		<content:encoded><![CDATA[<p>Whoops, sorry!</p>
<p>I meant &#8220;ERIK&#8221;!!!</p>
<p>Sorry for the typo <img src='http://www.adaruby.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hendy Irawan</title>
		<link>http://www.adaruby.com/2007/01/18/lazy-loading-blobs-in-active-record/comment-page-1/#comment-91</link>
		<dc:creator>Hendy Irawan</dc:creator>
		<pubDate>Mon, 22 Jan 2007 02:49:52 +0000</pubDate>
		<guid isPermaLink="false">http://adaruby.com/2007/01/18/lazy-loading-blobs-in-active-record/#comment-91</guid>
		<description>Thanks Eric!

I agree that would be the proper way to do it... :-)</description>
		<content:encoded><![CDATA[<p>Thanks Eric!</p>
<p>I agree that would be the proper way to do it&#8230; <img src='http://www.adaruby.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erik</title>
		<link>http://www.adaruby.com/2007/01/18/lazy-loading-blobs-in-active-record/comment-page-1/#comment-90</link>
		<dc:creator>Erik</dc:creator>
		<pubDate>Sun, 21 Jan 2007 02:39:34 +0000</pubDate>
		<guid isPermaLink="false">http://adaruby.com/2007/01/18/lazy-loading-blobs-in-active-record/#comment-90</guid>
		<description>It might be better and more robust to use a &quot;real&quot; cache like Squid.

Then all you would need to do is assign the proper Last Modified tags, ETags, expiration dates, caching pragmas, etc. Squid would do the rest, storing a local copy of the image the first time it is retrieved, and (depending on the combination of headers you use), either:

(1) hold onto it and serve it automatically until the expiration date passes, or

(2) Forward the request to your ruby app, along with the appropriate If-Modified-Since or ETag header (forgot the name of that one). Your ruby app would need to check the date/etag provided against the database and either return a 200 or a &quot;use cached version&quot; (304?) header.

Admittedly, this could introduce an extra source of latency, but it relies on standard, existing components and software, requiring much less special configuration on the part of the deployer. What will your code do if you run out of disk space? Will you evict older images from the cache in favor of more commonly viewed ones? What if the image file gets corrupted somehow - will your code detect it? If you have to delete or modify an image, will the cached version be deleted?

These are all things that are more likely to be easy to handle properly (or at all) with a real HTTP cache.</description>
		<content:encoded><![CDATA[<p>It might be better and more robust to use a &#8220;real&#8221; cache like Squid.</p>
<p>Then all you would need to do is assign the proper Last Modified tags, ETags, expiration dates, caching pragmas, etc. Squid would do the rest, storing a local copy of the image the first time it is retrieved, and (depending on the combination of headers you use), either:</p>
<p>(1) hold onto it and serve it automatically until the expiration date passes, or</p>
<p>(2) Forward the request to your ruby app, along with the appropriate If-Modified-Since or ETag header (forgot the name of that one). Your ruby app would need to check the date/etag provided against the database and either return a 200 or a &#8220;use cached version&#8221; (304?) header.</p>
<p>Admittedly, this could introduce an extra source of latency, but it relies on standard, existing components and software, requiring much less special configuration on the part of the deployer. What will your code do if you run out of disk space? Will you evict older images from the cache in favor of more commonly viewed ones? What if the image file gets corrupted somehow &#8211; will your code detect it? If you have to delete or modify an image, will the cached version be deleted?</p>
<p>These are all things that are more likely to be easy to handle properly (or at all) with a real HTTP cache.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

