• Resolved Angela Bowman

    (@askwpgirl)


    The shutdown hook is being used to clear expired transients. This can cause excessive PHP and MySQL usage resulting in extreme slowness to the site. We don’t know why this caused this specific issue on the site at the time it did, but it revealed a process that probably shouldn’t be being used. Why is shutdown being used rather than cron for clearing transients?

    Shutdown is typically used for error handling, not for twice daily tasks like cleaning up transients.

    We de-activated TEC to get the site back up functional.

    https://www.evernote.com/l/ABT_fdVpW6dLxb2mmQ5LPTn94BWXfad1PVc – this shows spike on the server caused by shutdown function

    https://www.evernote.com/l/ABQ7kAGFIEBCnr-MsaHVmlVxlPKpBG8ngLU – this shows PHP error on server related to the shutdown function to clear the transients.

    Questions:

    1) Why are transients being cleared using shutdown function rather than cron?

    2) More specifically, what is this doing and what would trigger it to cause issues on a site? Might not be possible to answer this. And, regardless of what triggered this to be a noticeable problem on this site is less relevant than the fact the shutdown hook is not ideal for this purpose and opens up a lot of potential problems.

Viewing 1 replies (of 1 total)
  • Plugin Author Gustavo Bordoni

    (@bordoni)

    Hi @askwpgirl,

    You are 100% correct that this can cause excessive PHP and MySQL usage resulting in slowness to the site. We have a bug on our bug tracking system to solve that particular problem, but let me try to explain the reason why we went that direction, hopefully it clears why we did that, which is a very weird one without context for sure.

    Our views for Month view in some websites get really loaded with a ton of Events, like in the thousands, which as you can imagine create a huge performance bottleneck if there is not HTML caching.

    The solution we took to the problem described above was to add some transient caching to the Month view and Week view of our Calendars.

    That solution presented a problem of when to expire the HTML caching, and on most cases this will not be a problem because it will properly expire when you have a modification to an event or some other setting changes.

    Now to come back to the transient purging on the shutdown method, the biggest problem was the following, we originally went with a Cron task to remove the transients like you mentioned, but the biggest problem was that a lot of WordPress installations don’t run Cron properly, and with as many customers as we have that ended up being a big problem.

    To combat all of the above we decided to move that to Shutdown because it would be an easy place to make sure the page load was not affected, in the sense that it would prevent bugs from breaking any behavior (edge cases that we noticed).

    That is all to answer the question one that you had and give some context, but I want to reinforce that we have this marked as a temporary solution that we intend to fix soon (no ETA).

    To answer your second question, if you have Cron you can simply disable that hook all together, it wont cause any problems because WordPress itself will do the garbage collection of the Transients that are expired and you wont have a DB flooded with cache items.

    Two ways to remove that from executing:

    
    // Execute a bit earlier than the transients removal to prevent it.
    add_action( 'shutdown', static function() {
       tribe_set_var( 'should_delete_expired_transients', false );
    } , 2 );
    

    Or

    
    remove_action( 'shutdown', [ tribe( 'cache' ), 'maybe_delete_expired_transients' ] );
    
    

    Let me know if I was able to provide a proper answer to your questions, we really do care about solving this problem for any customer with it.

    best Regards

Viewing 1 replies (of 1 total)
  • The topic ‘Shutdown hook for deleting transients causing excessive MySQL usage’ is closed to new replies.