• Resolved rikq

    (@rikq)


    First off, our site is quite large, and we have already noticed some significant speed improvements using this plugin. So, we would really love some help to figure out the issue below so that we can keep using the plugin.

    The problem is that this plugin is messing with our cron jobs. Here’s the scenario.

    The Setup

    We have disabled WordPress cron on our website using the following piece of code:

    define('DISABLE_WP_CRON', true);

    We then created a real linux cronjob that is triggered every 15 minutes via an external server (not the server hosting the site). The command that gets triggered every 15 minutes is:

    wget -q -O - https://ourdomain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

    This setup has been working very well for us for many years until we started using Docket Cache a couple of days ago.

    We have disabled the Docket Cronbot Service (never used it at all).

    When we began to notice conflicts with Docket Cache, we cleared both Docket Caches, and restarted the server.

    For test purposes, we created a cron event (10 minute recurrence) using the WP Crontrol plugin. This cron event just sends us an email every time it runs. It does nothing else.

    The Problem:
    After our first real linux cron job is triggered, when Docket Cache is enabled, we start to get calls to WordPress cron every 3 minutes (instead of the 15 minutes that we configured externally). The real problem is that all the calls to WordPress cron fail constantly. This can be seen from our server logs:

    2022/08/02 20:30:01 [error] 1399#1399: *44367 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 66.248.200.18, server: ourdomain.com, request: "GET /wp-cron.php?doing_wp_cron HTTP/1.1", upstream: "fastcgi://unix:/var/php-nginx/164280564033490.sock/socket", host: "ourdomain.com"
    2022/08/02 20:33:01 [error] 1399#1399: *44949 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 66.248.200.18, server: ourdomain.com, request: "GET /wp-cron.php?doing_wp_cron HTTP/1.1", upstream: "fastcgi://unix:/var/php-nginx/164280564033490.sock/socket", host: "ourdomain.com"
    2022/08/02 20:36:01 [error] 1399#1399: *45732 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 66.248.200.18, server: ourdomain.com, request: "GET /wp-cron.php?doing_wp_cron HTTP/1.1", upstream: "fastcgi://unix:/var/php-nginx/164280564033490.sock/socket", host: "ourdomain.com"
    2022/08/02 20:39:01 [error] 1399#1399: *46339 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 66.248.200.18, server: ourdomain.com, request: "GET /wp-cron.php?doing_wp_cron HTTP/1.1", upstream: "fastcgi://unix:/var/php-nginx/164280564033490.sock/socket", host: "ourdomain.com"
    2022/08/02 20:42:01 [error] 1399#1399: *46971 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 66.248.200.18, server: ourdomain.com, request: "GET /wp-cron.php?doing_wp_cron HTTP/1.1", upstream: "fastcgi://unix:/var/php-nginx/164280564033490.sock/socket", host: "ourdomain.com"

    From the date and time of each line above, you can see that the issue is occurring every 3 minutes. The effect of this is that our 10 minute cron event that sends us an email now sends the email every 3 minutes. All other WordPress cron events are also getting re-triggered every 3 minutes. This cannot be good at all. Some cron events are scheduled to run daily. Others weekly. 3 minutes re-execution of ALL WordPress cron events is a problem for sure. The even bigger problem is the fact that all calls to WordPress cron now fail (as shown in the server logs above).

    When we clear the Docket Caches and disable the Docket Cache plugin, everything goes back to normal: Calls to wp-cron.php no longer fail (no new doing_wp_cron errors in the logs). And our 10 minute WordPress cron event sends out the email notification every 10 minutes as expected. As soon as Docket Cache is re-enabled, the problem starts again.

    Here’s Our Docket Cache Overview Page:

    Web Server	nginx / 1.18.0
    PHP SAPI	7.4.3 / cgi-fcgi (Linux)
    Object Cache Stats	125M object of 214565 files
    Object OPcache Stats	1G memory of 511004 files
    WP OPcache Stats	94M memory of 4148 files
    PHP Memory Limit	5G
    WP Frontend Memory Limit	40M
    WP Backend Memory Limit	5G
    Drop-in Writable	Yes
    Drop-in File	/wp-content/object-cache.php
    Cache Writable	Yes
    Cache Files Limit	214565 / 1000000
    Cache Disk Limit	236M / 5G
    Cache Path	/wp-content/cache/docket-cache
    Chunk Cache Directory	Yes
    Config Writable	Yes
    Config Path	/wp-content/docket-cache-data

    We took a look into the code of the plugin and noticed that it indeed has some components that do stuff with wp-cron.php and doing_wp_cron GET requests. But before investigating this too far, we decided to ask for help here instead.

    Looking forward to your reply.

    Thank you.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Nawawi Jamili

    (@nawawijamili)

    Hi there,

    Thank you for the detailed feedback.

    You may try to disable these options one by one if enabled:
    – Advanced Post Caching
    – Object Cache Precaching
    – Optimize WP Query
    – Optimize Term Count Queries
    – Misc Performance Tweaks
    – Deactivate XML-RPC / Pingbacks

    Docket Cache only do conditional checking with doing_wp_cron in
    – includes/cache.php
    – includes/src/CronAgent.php
    – includes/src/Tweaks.php

    that’s related with:
    – Object Cache Precaching
    – Cronbot Service
    – Deactivate XML-RPC / Pingbacks

    Docket Cache is a file-based cache alternative to Redis and Memcached that may or may not handle large caches, if before using Docket Cache your setup has been working very well, suggested you may leave it as is.

    Thanks.

    Thread Starter rikq

    (@rikq)

    – Advanced Post Caching: This was enabled.

    – Object Cache Precaching: This was enabled, but we already tested with it disabled yesterday. The problem was still there even when disabled. We also tested with “Auto Remove Stale Cache” both ON and OFF. Same results.

    – Optimize WP Query: We never enabled this.

    – Optimize Term Count Queries: We never enabled this.

    – Misc Performance Tweaks: We never enabled this.

    – Deactivate XML-RPC / Pingbacks: We never enabled this. We already have a line of code in our Nginx configuration that disables XMLRPC.

    From the above, it appears that Docket Cache still does cron stuff even when the features you mentioned that use doing_wp_cron are NOT enabled.

    We can try disabling Advanced Post Caching and testing again, but I strongly doubt if this would solve the problem. I will let you know the results of my test.

    My guess is that Docket Cache attempts to perform a long running cron operation. The cron operation times out because of the number of files involved in the process. And Docket Cache just keeps trying to redo the same operation every 3 minutes, and the operation continues to timeout.

    If my guess is correct, then if you could help us identify exactly what cron process(es) Docket Cache attempts to perform, we might be able to figure out a solution together.

    You may notice that we allocated a relatively large amount to disk space (and memory) to Docket Cache and OPCache (5GB in each case). I suspect that if we reduce this disk and memory allocation by at least one order of magnitude (below 500MB), we may not have the above issues. But if we do that, we won’t be getting much of the benefits of Docket Cache either.

    Slightly unrelated, but could be useful in your diagnosis: When we first installed Docket Cache, it crashed our website after the first few minutes. We noticed that a ton of files were being created inside the cache folder at a very fast rate. The solution to this was to enable “Chunk Cache Directory”. It was disabled by default. Once we did this, we immediately noticed speed improvements, but hours later, we started noticing and investigating the cron issue reported here.

    We have already noticed significant speed improvements using Docket Cache on our dynamic pages (pages that don’t use any page caching). For this reason, we really don’t want to “leave it as is”. Also, if we can work together to get to the bottom of this problem, we are sure that it would help other websites that are relatively large like ours, and that want to use your plugin.

    Please let me know if you need any additional information from me. Thank you.

    Thread Starter rikq

    (@rikq)

    One more thing…

    Even though we plan to test with “Advanced Post Caching” disabled, we need an actual solution to this problem that would allow us keep this option enabled because most of our contents are WooCommerce products (not regular posts). We only have few regular blog posts.

    So, if I understand correctly, “Advanced Post Caching” would need to be enabled in order to get any object caching benefits for WooCommerce products which are not regular WordPress posts.

    Plugin Author Nawawi Jamili

    (@nawawijamili)

    Hi,

    Seems like “Garbage Collector” can’t finish its job. You may disable it by comment out this line of code

    https://github.com/nawawi/docket-cache/blob/master/includes/src/Event.php#L85

    File: includes/src/Event.php
    Line: 86 to 89
    Original Code:

    // gc: always enable
                    add_action('docketcache_gc', [$this, 'garbage_collector']);
                    if (!wp_next_scheduled('docketcache_gc')) {
                        wp_schedule_event(time(), 'docketcache_gc_schedule', 'docketcache_gc');
                    }

    Changes:

    // gc: always enable
                    /*add_action('docketcache_gc', [$this, 'garbage_collector']);
                    if (!wp_next_scheduled('docketcache_gc')) {
                        wp_schedule_event(time(), 'docketcache_gc_schedule', 'docketcache_gc');
                    }*/

    Because the garbage collector is an important part of Docket Cache, we need to run it manually by using wp-cli, you may install it on your server if not available yet. And then, run this command.

    wp cache run:gc

    You can run it by using real-cron, or just replace your current cron by using wp-cli entirely.

    wp cron event run --due-now

    I hope this helps.

    Thanks.

    Thread Starter rikq

    (@rikq)

    That makes a lot of sense. I suspected this already. Thank you.

    I will test the above code tomorrow and get back to you.

    When I was investigating this originally, I saw via the WP Crontrol plugin that docketcache_gc was scheduled to run every 5 minutes. I tried to change the schedule for this cron job to something like every 4 hours or even longer. But my changes did not take effect. It always reverted back to 5 minutes, and this made me think that something in the plugin code was resetting it. The code you shared above confirms this.

    So, I’ll let you know how this goes after testing.

    Couple of questions in the meantime:

    • Do you have any thoughts on how frequently the garbage collector must run? Would we have any major issues if we increase this to say every 4 hours and run it via WP CLI?
    • Yesterday, I noticed that Docket Cache creates two cron schedules: docketcache_gc which runs every 5 minutes, and another one (can’t remember the name) which was scheduled to run every 1 hour. Could you please let me know what the second cron job does? That way, I can proactively determine if it might also cause issues for us.
    • If I comment out the garbage collector code (as above) and this solves the problem, could you perhaps add an option to the plugin to disable garbage collector from the settings? Or even better, as a constant defined in wp-config.php? That way, we wouldn’t need to keep our old copy of the plugin when the plugin is updated. This option can be enabled by default since most users need it. And you can add a message to let users know that they must run the garbage collector by themselves if they disable it.

    As per question #3 above, the only constant related to garbage collector I found in the Docket Cache docs is this one: DOCKET_CACHE_GCACTION.
    It would be nice to have a constant that can actually turn OFF garbage collector completely and let the user run it either manually or via WP CLI.

    Please let me know. Thank you for your help so far!

    Thread Starter rikq

    (@rikq)

    Follow up to my second question above. I just took another look at the plugin code, and I found the second cron schedule that Docket Cache creates. It is named docketcache_watchproc and it runs every hour. Please what does this do? Could this also be a long running operation?

    Thread Starter rikq

    (@rikq)

    Update:
    First we commented out garbage collector as per the code you shared. The issue remained. Then, leaving garbage collector commented out, we disabled both Advanced Post Caching and Object Cache Precaching, and then the issue stopped.

    Plugin Author Nawawi Jamili

    (@nawawijamili)

    Hi,

    Glad to hear that. To answer your question.

    Docket Cache has 4 cron task: docketcache_gc, docketcache_watchproc, docketcache_optimizedb and docketcache_checkversion.

    docketcache_gc
    This task for Garbage Collector, and same as its name, is responsible to clean up any cache that has been expired or stale and keep the file and disk limit in check.

    docketcache_watchproc
    This task is responsible for collecting cache stats for the Overview page. Remove expired transient in DB and previously to cleanup unknown cron.

    docketcache_optimizedb
    This task for “Optimize Database Tables” and scheduled depending on options selected and never run if “never” is selected.

    docketcache_checkversion
    This task for “Check Critical Version” and scheduled to run every 15 days if enabled.

    For busy sites, it is not recommended to enable Advanced Post Cache and Object Cache Precaching. These two features will create another cache to short-circuit and cache repeating tasks and DB queries. This only can be good to enable for a busy site if can run the Garbage Collector from CLI or use other custom scripts.

    I hope this answers your question.

    Thanks.

    Plugin Author Nawawi Jamili

    (@nawawijamili)

    Hi,

    I’m marking this thread as resolved. Feel free to open a new topic if you have further questions.

    Thanks.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Docket Cache Conflicts with Cron Jobs’ is closed to new replies.