Re: images in database?

From: The Natural Philosopher <tnp_at_invalid.invalid>
Date: Mon, 6 Jun 2016 19:15:57 +0100
Message-ID: <nj4ekr$gle$1_at_news.albasani.net>


On 06/06/16 17:53, J.O. Aho wrote:
> On 06/06/2016 04:03 PM, Jerry Stuckle wrote:
>> On 6/6/2016 8:43 AM, mike7411_at_gmail.com wrote:
>>> I’m working on an advertising network.
>>>
>>> Is it better to store the banners in the database or on the file system?
>>
>> There are advantages and disadvantages to both. I like to store images
>> related to a page in a database. It helps maintain integrity - you
>> won't accidentally delete an image if you use the INNODB engine and set
>> up your referential integrity (foreign keys) properly.
>>
>> OTOH, if you're storing the images in the database, you'll need a script
>> to do the retrieval - you can't just do it in html. However, this can
>> also be advantageous because you can better control access to the images
>> (I've had other sites link to my images without my permissions before -
>> running up my bandwidth).
>>
>> Some people will say that images don't belong in a database. But when
>> you get right down to it, a file system is just a different kind of
>> database.
>
> Sure, but the file system seldom runs inside another file system and a
> database seldom handles directly with the block device, so could make
> things slower.

On a website speed of image dispatch is dominated by user bandwith. And memory by the forked process handling it.

That is any website dispatching 10 images, will have the images more or less in memory or cache memory until they are dispatched to the client browser.

And that is far and away the bottleneck

>
> But in the end it's just question about what solves the issue best.
>
>

And there is one other thing you need to do to dispatch images efficiently, and that is to look up and use the 'you already have that image cached' mechanism.

Etag and if-not-cached need to be sorted out.

https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching?hl=en

What I do is store an etag field with the image, as a hash of the image and then the code that spits the image out reads that an sets the header field, or if the etag matches if-not-cached sends a 304 response instead.

For standard images and raw apache that is all done automagically, but when you are constructing a bit of code to send the file, you have to replicate that 'manually'.

>

-- 
“But what a weak barrier is truth when it stands in the way of an 
hypothesis!”

Mary Wollstonecraft
Received on Mon Jun 06 2016 - 20:15:57 CEST

Original text of this message