You append data to a file on ECS-A and you view the contents of the file by using the tail -f command on ECS-B. Before you can view the contents, you must wait 10 to 30 seconds. Note: If you mount a Network File System (NFS) on two Elastic Compute Service (ECS) instances, the two ECS instances are ECS-A and ECS-B. However, if you use a tool such as vi to open the file on ECS-B, you can immediately view the contents.
The delay is caused by a mount option and the implementation of the tail -f command.
If you use the
mount -t nfs4 /mnt/ command to mount an NFS file system on an ECS instance, Linux caches the attributes
of files and directories as metadata by default.
These attributes include the permission, size, and timestamp. This reduces the number of NFSPROC_GETATTR RPC requests.
The tail -f command calls the sleep and fstat functions to monitor changes to file attributes, read files, and output results. In most cases, these changes are related to size. You can use the tail -f command to view file contents. These file contents that appear can be up-to-date or outdated. The result changes based on the output of the fstat function. Due to attribute caching, the fstat function may retrieve outdated file attributes. Even if a file has been updated on the NFS server, the tail -f command cannot retrieve the latest file. Therefore, the writing delay issue occurs.
Use the following command with the noac option to mount the file system. This option disables attribute caching.
mount -t nfs4 -o noac /mnt/