You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Brian Hirt <bh...@me.com> on 2011/03/11 19:48:14 UTC

[users@httpd] Question about RewriteMap files on a NFS filesystem

Hello,

We have a bunch of rewrite rules that use four standard plain text rewrite maps (ie RewriteMap mymap txt:/some/file).    These rewrite maps only change about once a month, but when they do change, apache picks up the chances pretty much immediately.   I'm assuming that apache is doing a stat on the file every so often but I'm not really sure how ofter.  Does it do it per request or does it limit it to a time frame like once per second?   We've been using this setup in production for years and have never had any problems.    We have many machines in our cluster that have the exact same setup with the exact same maps, and when we want to make changes we have to do it on each machine.  All the machines in the cluster have a shared nfs/drbd/pacemaker file system and the first thought is "wow things would be some much cleaner if all these rewrite maps were located in a single place", but that's where my concern comes in.   What happens if these maps are on a shared NFS filesystem.   Will apache be able to pick up changes made to the file?   Will i start getting 100s of stats per second to the NFS filesystem?

Is there anyone that has any sort of advice or experience with this sort of setup?  Any words of wisdom would be appreciated.

Thanks in advance,
Brian Hirt
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Question about RewriteMap files on a NFS filesystem

Posted by Mark Montague <ma...@catseye.org>.
  On March 11, 2011 13:48 , Brian Hirt <bh...@me.com> wrote:
> We have a bunch of rewrite rules that use four standard plain text rewrite maps (ie RewriteMap mymap txt:/some/file).    These rewrite maps only change about once a month, but when they do change, apache picks up the chances pretty much immediately.   I'm assuming that apache is doing a stat on the file every so often but I'm not really sure how ofter.  Does it do it per request or does it limit it to a time frame like once per second?

This question could be answered by using a tool like strace, truss, 
DTrace, or SystemTap (depending on which OS you're using).  However, 
looking in the source code for Apache HTTP Server 2.2.17, 
modules/mapper/mod_rewrite.c:

hook_fixup() and hook_uri2file handle rewriting in directory and server 
contexts, respectively.  Both call apply_rewrite_list(), which in turn 
calls apply_rewrite_rule(), which calls do_expand(), which calls 
lookup_map(), which calls apr_stat() if the map type is txt or rnd.  The 
file modification time from the apr_stat() call is then passed to 
get_cache_value(), which will fail -- forcing lookup_map() to re-read 
the map file -- if the modification time is later than the modification 
time associated with the cached map entry (or if the map entry does not 
exist in the cache).  Both positive and negative map results are 
cached.  See lines 1539 - 1572 of mod_rewrite.c.

So, the answer to your question is: a stat() is done for each request 
for which there is a RewriteRule in the applicable context whose 
substitution contains a map expression AND whose pattern matches the 
current request.  If the rewrite rule does not apply to or does not 
match the current request, then no stat() will be done.


> What happens if these maps are on a shared NFS filesystem.   Will apache be able to pick up changes made to the file?

I know of no reason why httpd would not pick up the changes in this 
situation, assuming the NFS client sees changes on the NFS server 
immediately.


> Will i start getting 100s of stats per second to the NFS filesystem?

If you have 100s of requests per second that match rewrite rules that 
apply maps, then yes.  You might want to look into how your NFS client 
handles stats in this context:  does each stat() call result in one or 
more RPC calls to the NFS server, or does the NFS client cache and/or 
optimize things in some way?

Do you have httpd configured to serve content from your NFS filesystem?  
If so, you're probably already doing multiple stat() calls per request, 
and even more if you have AllowOverride set for those paths, or if don't 
have FollowSymlinks set.  ( See 
http://httpd.apache.org/docs/2.2/misc/perf-tuning.html )   In other 
words, before assuming that 100s of stat() per second to the NFS 
filesystem for rewrite maps will be a problem, you should see how many 
stat() per second you're already doing.

If you determine it is worth optimizing around using NFS to store 
rewrite maps, set up a cron job that runs once a minute on each machine 
in your cluster that checks to see if each rewrite map in NFS is newer 
than a copy on the web server's local filesystem and, if it is, copies 
it from NFS to the local disk.  Then configure httpd to use the copies 
on local disk.

I hope this helps.

--
   Mark Montague
   mark@catseye.org


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org