Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I programmatically force changes to a file to propagate to all NFS clients?

I have a CMS built in PHP which stores the list of pages, page navigation structure, and the content of pages in files on disk. This application is hosted on a cluster of Apache/php-fpm servers which are behind a haproxy server. These servers mount the Apache DocumentRoot directory via NFS from a central file server, so all the changes made from the CMS get written to files on the NFS share.

I have found that, unless I mount the NFS share with the noac option, changes made may take up to 5-10 seconds to propagate to all servers in the cluster; meaning when multiple changes are made in rapid succession, the final change sometimes overwrites the earlier changes because the final change may go to a server which has not received the earlier changes yet.

However, when using the noac mount option, there's a 2-5 second delay in accessing the content on the visitor side, which is completely unacceptable.

Is there a way to programmatically force changes to a file on an NFS share to propigate to all clients, or to cause all clients to flush their cache of that file?

like image 573
Josh Avatar asked Oct 09 '22 21:10

Josh


2 Answers

I don't know of any NFS-level option to achieve what you want BUT if the applications accessing those files are under your control then you can make every file open use the O_DIRECT option - this bypasses any local NFS cache for any file opened this way...

A remark:

You write that noac leads to a delay of 2-5 seconds.. this seems to point to a network- and/or storage-level problem or to "far to many files/directories within one directory"...

like image 140
Yahia Avatar answered Oct 13 '22 12:10

Yahia


I solved the same issue with NFS parameter cto in combination with apache directives EnableMMAP Off and EnableSendFile Off. the noac parameter had the same symptoms you wrote about.

like image 21
tloudev Avatar answered Oct 13 '22 12:10

tloudev