You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by David Rush <da...@wyo.gov> on 2016/01/20 21:36:24 UTC

[users@httpd] Frequently updating static content

I'm using Apache 2.4 (on Linux) to serve some static files that are
re-created and re-written every two minutes.  The nature of our site is
that we get hammered with high request rates from time to time (thousands
of requests per minute at times).

Are there any issues with frequently updating a file that's being served?
What happens if it's updated (re-created) at the same instant that it's
being requested?

David

-- 

E-Mail to and from me, in connection with the transaction 
of public business, is subject to the Wyoming Public Records 
Act and may be disclosed to third parties.

Re: [users@httpd] Frequently updating static content

Posted by David Rush <da...@wyo.gov>.
Thanks for the input.  I'll give that a go.

David

On Wed, Jan 20, 2016 at 8:58 PM, Luca Toscano <to...@gmail.com>
wrote:

>
>
> 2016-01-21 1:55 GMT+01:00 Yann Ylavic <yl...@gmail.com>:
>
>> On Wed, Jan 20, 2016 at 9:36 PM, David Rush <da...@wyo.gov> wrote:
>>
>> > What happens if it's updated (re-created) at the same instant that it's
>> > being requested?
>>
>> This should be handled carefuly, the updater and the server should not
>> race on the content of the file but on the file (inode) itself.
>>
>> You could first create the new file with an extension (e.g. ".tmp")
>> and then rename it to the served file using "mv -f servedfile.tmp
>> servedfile", which is usually atomic on Unixes (at least Linux and
>> BSDs afaict).
>>
>
> +1
>
> The only issue that I can think of are slow clients requesting the content
> of "servedfile" at some point X in time, finishing to receive it from httpd
> at say X+4, meanwhile the new "servedfile" is created at X+2 (so the slow
> client should get the correct content without any glitch/error/etc..).
>
> With Yann's suggestion the slow client will keep receiving the right
> content even after the move from servedfile.tmp (new file) to servedfile
> because a file descriptor opened to the old servedfile's inode (held by
> httpd) will prevent the kernel to mark it as garbage (this of course on
> Unixes where the move is atomic and the kernel honors inodes in that way).
> New clients will get correctly the new content meanwhile the slow/unlucky
> ones won't experience any inconsistency.
>
>  Luca
>
>
>
>
>
>

-- 

E-Mail to and from me, in connection with the transaction 
of public business, is subject to the Wyoming Public Records 
Act and may be disclosed to third parties.

Re: [users@httpd] Frequently updating static content

Posted by Luca Toscano <to...@gmail.com>.
2016-01-21 1:55 GMT+01:00 Yann Ylavic <yl...@gmail.com>:

> On Wed, Jan 20, 2016 at 9:36 PM, David Rush <da...@wyo.gov> wrote:
>
> > What happens if it's updated (re-created) at the same instant that it's
> > being requested?
>
> This should be handled carefuly, the updater and the server should not
> race on the content of the file but on the file (inode) itself.
>
> You could first create the new file with an extension (e.g. ".tmp")
> and then rename it to the served file using "mv -f servedfile.tmp
> servedfile", which is usually atomic on Unixes (at least Linux and
> BSDs afaict).
>

+1

The only issue that I can think of are slow clients requesting the content
of "servedfile" at some point X in time, finishing to receive it from httpd
at say X+4, meanwhile the new "servedfile" is created at X+2 (so the slow
client should get the correct content without any glitch/error/etc..).

With Yann's suggestion the slow client will keep receiving the right
content even after the move from servedfile.tmp (new file) to servedfile
because a file descriptor opened to the old servedfile's inode (held by
httpd) will prevent the kernel to mark it as garbage (this of course on
Unixes where the move is atomic and the kernel honors inodes in that way).
New clients will get correctly the new content meanwhile the slow/unlucky
ones won't experience any inconsistency.

 Luca

Re: [users@httpd] Frequently updating static content

Posted by Yann Ylavic <yl...@gmail.com>.
On Wed, Jan 20, 2016 at 9:36 PM, David Rush <da...@wyo.gov> wrote:
> I'm using Apache 2.4 (on Linux) to serve some static files that are
> re-created and re-written every two minutes.  The nature of our site is that
> we get hammered with high request rates from time to time (thousands of
> requests per minute at times).
>
> Are there any issues with frequently updating a file that's being served?

Not that I'm aware of.

> What happens if it's updated (re-created) at the same instant that it's
> being requested?

This should be handled carefuly, the updater and the server should not
race on the content of the file but on the file (inode) itself.

You could first create the new file with an extension (e.g. ".tmp")
and then rename it to the served file using "mv -f servedfile.tmp
servedfile", which is usually atomic on Unixes (at least Linux and
BSDs afaict).

Regards,
Yann.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org