Home > Blockchain >  Nginx cannot write cache content to the gcsfuse mount directory
Nginx cannot write cache content to the gcsfuse mount directory

Time:12-30

I mounted the bucket to compute the engine VM via gcsfuse and then ran the Nginx program in the VM. Normally the Nginx program writes the cache to the directory, i.e. the mounted bucket, using the proxy_cache directive. However, I have a problem that the Nginx can create cache files in the filesystem under the bucket directory, but the size of the cache file is always 0B. client requests keep getting "Miss cache" status. So it seems that after mounting with gcsfuse, the Nginx application can only create cache files, but cannot write to them.

My VM environment is. Machine type: n2-standard-2 CPU platform: Intel Cascade Lake Architecture: x86/64 System: ubuntu-1804

In addition, gcsfuse has specified a service account with owner privileges via the --key-file directive, and the Nginx program has been run with the root user.

For example, the following debug log is an empty file (8/2b/0a7ed71cddee71b9276a0d72a030f2b8) created in the bucket after a client request and not written to the cache. What could be the cause of this possibility?

https://storage.googleapis.com/cloud_cdn_cache_bucket/debug_log.txt

Here is the debug log obtained by the command --debug_fuse --debug_fs --debug_gcs --debug_http -foreground.

CodePudding user response:

You can't use Cloud Storage Fuse for cache.

There is a technical reason to that: GCSFuse is a Cloud Storage API call wrapper that transforms system calls to API calls. However, all the system calls aren't supported, especially those related to "database" format with stream write, seek, and rewrite partial content of the file. All common operations for a database (or cache) but not compliant with Cloud Storage: you can only write/read/delete a file. Update/partial write aren't supported. It's not a file system!

In addition, because you now know that GCSFuse is a wrapper (of system calls to API calls), you should feel that using that file system type is not a good idea: the latency is terrible!! It's API calls! Absolutely not recommended for cache and low latency operations.


The best solution is to use a local file system dedicated to cache. But if you scale out (more servers in parallel) you could have issues (cache is not shared between instances):

  • Use sticky session mechanism to always route the same user session on the same NGINX server and therefore always use the same cache context
  • Use the Filestore service that offers a NFS (Network File Share) system to mount the same storage space on different servers, with an interesting latency (not as good as a local file system)

You talked about a key file in your question also. I recommend you to avoid as much as you can to use the service account key files; especially if your app runs on Google Cloud. Let me know what's your key file usage in detail if you want more guidance

CodePudding user response:

In the gcsfuse logs we don't find any read or write calls after the file creation. so we suspect there would be some another app/cache/program layer which is handling read or write calls.

Just a follow up question do you also see this issue with normal file system(not gcsfuse mounted) ?

  • Related