-
-
Notifications
You must be signed in to change notification settings - Fork 606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to enable FastCGI background updates #962
Add option to enable FastCGI background updates #962
Conversation
@@ -46,6 +47,11 @@ server { | |||
set $skip_cache 1; | |||
} | |||
|
|||
# Update an expired cache item in the background, serve stale cache to client. | |||
{% if item.value.cache.enabled and item.value.cache.background_updates %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
background_update
not background_updates
I wonder if there's any reason not to make this the default? |
@@ -46,6 +47,11 @@ server { | |||
set $skip_cache 1; | |||
} | |||
|
|||
# Update an expired cache item in the background, serve stale cache to client. | |||
{% if item.value.cache.enabled and item.value.cache.background_update %} | |||
fastcgi_cache_background_update on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forgot the semi-colon at the end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also should this be in the cache_config block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I'd prefer this to be grouped in cache_config
👍
In what cases does it make sense to enable background_update? |
The better question is the opposite to me. Right now the cache is time based. Say it's 60s, and a client hits the site 60.1s after it was last cached. This would result in a cache miss and that client would incur the cost of a full request hitting WP. With background updates, and the same scenario above, that client would still result in a cache hit, but the cache would be updated in the background. This means no actual client would ever incur a cache miss. They'd either get stale cached data, or the next cache hit. This is obviously preferable as long as it works as we'd expect. Meaning if we trust Nginx to properly update the cache in the background within a reasonable time frame, it's a better user experience with barely any more cache time added. Here's a good article on this: https://siipo.la/blog/never-miss-the-cache-with-nginx-microcaching |
Then according to that article should we also consider the following?
Also, currently fastcgi_cache_valid is set to 30s, should we specify 200 301 302 404 and possibly increase caching to 1m? |
We already set those. Time is just a default, anyone can change it. Maybe we should only specific |
My mistake I only checked site config file and not the general nginx.conf |
Updated PR with cache_config grouping and missing I don't know where I stand on making this default behaviour or not, I think it could lead to some confusion - like I said in my initial suggestion - this isn't a perfect solution for all applications. Which makes me think it should be opt in behaviour. |
@@ -175,6 +176,11 @@ server { | |||
fastcgi_cache_bypass $skip_cache; | |||
fastcgi_no_cache $skip_cache; | |||
|
|||
# Update an expired cache item in the background, serve stale cache to client. | |||
{% if item.value.cache.background_update %} | |||
fastcgi_cache_background_update on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
; is still missing
I vote for it being default behavior and replacing |
@InTheDeepEnd I'm still curious why you think this is the case. Is there a downside/con I'm missing? |
@swalkinshaw - maybe I'm missing something actually, I guess this works in conjunction to whatever the cache expiry is in the group_vars, and that's set at the discretion/requirements of the project. +1 for default. My bad. |
Set to default to true. :) |
@InTheDeepEnd This is great. Thank you! It works as is, but more style opinions incoming! 😱 For the sake of consistency with existing Trellis caching options, I think there are two patterns this new Where defaults are defined. Notice that the cache options in the docs are absent from How defaults are defined. The cache directives in
A user could define ⭐ To be consistent with these patterns, could you...
I'm inclined to drop the explanatory comment because no other I'm inclined to not add the extra blank lines because then the templated conf on the server would have double blank lines in some spots. Of course, it could be argued that the goal should be readability in the Trellis http codes.
Looks like 200, 301, and 302 are covered by default (nginx docs). I don't know much about why and when to also include 404, but I'm inclined to continue with the default because desire for an alternative hasn't ever come up that I remember. Users could change it using child templates. |
Hey @InTheDeepEnd any chance you can update this with the fixes? I would love for this to be merged. |
…onditional option in NGINX site host file.
…onditional option in NGINX site host file.
Thanks everyone ❤️ |
The blog post @swalkinshaw linked also updated about the issues with 404 pages on 17 May 2018. Do we need to add |
We already have
|
@tangrufus thanks for pointing out the article update regarding 404 pages. I haven't tested the need nor the solution, but the description makes sense to me. Do you envision a change like this? - fastcgi_cache_valid {{ item.value.cache.duration | default(nginx_cache_duration) }};
+ fastcgi_cache_valid 200 301 302 404 {{ item.value.cache.duration | default(nginx_cache_duration) }}; Or we could do shorter expiration for 404s, but I doubt it makes a big difference: fastcgi_cache_valid {{ item.value.cache.duration | default(nginx_cache_duration) }};
+ fastcgi_cache_valid 404 1s; |
I vote for the second solution because it could prevent troubles when |
On one of our installs nginx was running on version 1.11.5, as this feature was added in 1.11.10 this causes an emergency log of:
To update nginx manually you can run:
Not opening this as issue as I presume it's an edge case, but may be helpful for others |
* Add xdebug.remote_autostart to simplify xdebug sessions * Update logrotate doc URL [ci skip] * Update WP-CLI to 1.5.1. * Update changelog. [ci skip] * Update geerlingguy.composer 1.6.1->1.7.0 (roots#983) Update from `1.6.1` -> `1.7.0` which addresses roots#943 ([DEPRECATION WARNING]: The use of 'include' for tasks has been deprecated.) * Update geerlingguy.ntp 1.5.2->1.6.0 (roots#984) Avoids deprecation warnings introduced in Ansible 2.4: "The use of 'include' for tasks has been deprecated." * Enable nginx to start on boot (roots#980) * update changelog * 'yarn run' -> 'yarn' [ci skip] * Issue warning for all Ubuntu releases that are not Xenial (roots#986) * Clarify that changelog entry indicates Trellis version (roots#987) * Validate python version on control machine (roots#988) * Common: Install `git` instead of `git-core` Because `git-core` is now a dummy package of `git`. See: http://git.661346.n2.nabble.com/git-core-vs-git-package-on-ubuntu-tp7576083p7576085.html * Add CSP frame-ancestors, make X-Frame-Options conditional (roots#977) The X-Frame-Options header has been obsoleted by the frame-ancestors directive. Retain the X-Frame-Options header for older browsers. Return empty X-Frame-Options header for WordPress Customizer content to prevent the conflict that SAMEORIGIN would have with the ALLOW-FROM option that WordPress adds on its own (Safari browser). Discussion in https://core.trac.wordpress.org/ticket/40020 * Improve failed_when rule for Wordpress Installed check (roots#991) In rare cases the wp_installed registered var may be missing the stderr attribute, so add a default to avoid related error. The `wp core is-installed` command return code is 1 if WP is simply not installed. However, in rare cases the command may return some other return code indicative of true failure, so fail if rc > 1. * deploy.sh: Return non-zero exit code when misuse (roots#990) - Exit with `127` when not enough arguments - Exit with `1` when hosts file not exist See: http://www.tldp.org/LDP/abs/html/exitcodes.html * Skip Acme Challenge failure message for non-failed sites (roots#993) * Bump Ansible version_tested_max to 2.5.3 (roots#981) * Bump Ansible version_tested_max to 2.5.3 Convert Jinja2 tests from filter format to `var is testname` format. Encourage users on Ansible 2.5.0 to upgrade to avoid erroneous warnings fixed in ansible/ansible 37538 * Add option to enable FastCGI background updates (roots#962) Enabled by default * Add quotes to nginx_cache_background_update value "on" Quotes prevent Ansible from interpolating the variable value as True. True is an invalid value for fastcgi_cache_background_update and would would make Nginx unable to reload. * Verify `wp-cli.phar` checksum
wordpress-site.conf.j2