Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#1712 closed defect (duplicate)

xfs - nginx cache manager wrongly calculates cache size

Reported by: vladimir.nikolic.74@… Owned by:
Priority: major Milestone:
Component: other Version: 1.12.x
Keywords: Cc:
uname -a: Linux 3.10.0-862.14.4.el7.x86_64 #1 SMP Wed Sep 26 15:12:11 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --with-debug

Description

If we put nginx proxy_cache_path and proxy_temp_path nginx configuration directives to the same xfs partition, cache manager calculates the size of cache improperly (it adds some 20-30%). It shows proper size only after the nginx restart.
If we put proxy_temp_path to different partition, the size is properly calculated all the time. But that brings us unnecessary I/O load for moving files between partitions.
We didn’t have this issue with ext3 partition.

Below are examples that show how cache manager sees the cache size during the 2 GB file download/caching. As we use ‘slice’ nginx directive, it shows 10 files, each one of them 200Mb size big.

nginx proxy_cache_path and proxy_temp_path nginx on the same partition

2019/01/18 03:54:27 [notice] 31118#31118: http file cache: /glide/cdn/nginx/cache 0.000M, bsize: 4096
2019/01/18 03:54:37 [debug] 31117#31117: http file cache size: 0 c:0 w:-1
2019/01/18 03:54:47 [debug] 31117#31117: http file cache size: 131056 c:3 w:-1
2019/01/18 03:54:57 [debug] 31117#31117: http file cache size: 393088 c:6 w:-1
2019/01/18 03:55:07 [debug] 31117#31117: http file cache size: 523952 c:8 w:-1
2019/01/18 03:55:17 [debug] 31117#31117: http file cache size: 653984 c:10 w:-1
systemctl restart nginx-debug
2019/01/18 04:08:27 [notice] 1282#1282: http file cache: /glide/cdn/nginx/cache 1998.250M, bsize: 4096
2019/01/18 04:08:37 [debug] 1281#1281: http file cache size: 511552 c:10 w:-1
Size is ‘right’ only after the restart.

nginx proxy_cache_path and proxy_temp_path nginx on different partitions

2019/01/18 04:12:02 [notice] 2145#2145: http file cache: /glide/cdn/nginx/cache 0.000M, bsize: 4096
2019/01/18 04:12:02 [debug] 2144#2144: http file cache size: 0 c:0 w:-1
2019/01/18 04:12:42 [debug] 2144#2144: http file cache size: 51201 c:2 w:-1
2019/01/18 04:13:02 [debug] 2144#2144: http file cache size: 102402 c:3 w:-1
2019/01/18 04:13:22 [debug] 2144#2144: http file cache size: 153603 c:4 w:-1
2019/01/18 04:13:42 [debug] 2144#2144: http file cache size: 204804 c:5 w:-1
2019/01/18 04:13:52 [debug] 2144#2144: http file cache size: 307206 c:7 w:-1
2019/01/18 04:14:02 [debug] 2144#2144: http file cache size: 358407 c:8 w:-1
2019/01/18 04:14:12 [debug] 2144#2144: http file cache size: 409608 c:9 w:-1
2019/01/18 04:14:22 [debug] 2144#2144: http file cache size: 460809 c:10 w:-1
2019/01/18 04:14:32 [debug] 2144#2144: http file cache size: 511552 c:10 w:-1
systemctl restart nginx-debug
2019/01/18 04:15:38 [notice] 2713#2713: http file cache: /glide/cdn/nginx/cache 1998.250M, bsize: 4096
2019/01/18 04:15:48 [debug] 2712#2712: http file cache size: 511552 c:10 w:-1
Size is 'right' all the time.

Change History (4)

comment:1 by Maxim Dounin, 6 years ago

Resolution: duplicate
Status: newclosed

There is a known problem with XFS when using large allocsize= in mount options, see #157.

comment:2 by vladimir.nikolic.74@…, 6 years ago

Resolution: duplicate
Status: closedreopened

I had seen #157 before opening this issue.
We are using default xfs 'allocsize', which is 64k.
Is that large by your standards?

comment:3 by Maxim Dounin, 6 years ago

Resolution: duplicate
Status: reopenedclosed

Quick search suggests that by default XFS is using speculative preallocation now, see here. As such, the same problem as observed in #157 can be triggered even without explicit allocsize= in mount options as long as files cached are big enough. As the link suggests, you can use allocsize=64k in mount options to revert the behaviour to use fixed preallocation.

comment:4 by vladimir.nikolic.74@…, 6 years ago

True, using allocsize=64k in the mount options makes cache size calculation accurate.
Thanks.

Note: See TracTickets for help on using tickets.