WordPress.org

Make WordPress Core

Opened 15 months ago

Last modified 5 days ago

#20316 new enhancement

Garbage collect transients

Reported by: nacin Owned by:
Priority: normal Milestone: Future Release
Component: Database Version:
Severity: normal Keywords: dev-feedback has-patch 3.7-early
Cc: ocean90, joachim.kudish@…, xoodrew@…, luke.gedeon@…, bananastalktome@…, knut@…, kovshenin, wordpress@…, leho@…, ian.dunn@…, adamsilverstein@…, kenton.jacobsen@…, cyberhobo@…, contact@…

Description

Per an IRC discussion and long-considered changes:

  • In wp_scheduled_delete(), look for expired transients and purge them.
  • On DB upgrade, purge all transients, regardless of expiration. (This should probably happen on auto-update as well, but let's let that part slide for now, as DB upgrade will run on all major releases these days.)

We should only do this if ! $_wp_using_ext_object_cache.

Attachments (1)

20316.patch (3.4 KB) - added by SergeyBiryukov 14 months ago.

Download all attachments as: .zip

Change History (30)

comment:1 jkudish15 months ago

  • Cc joachim.kudish@… added

comment:2 DrewAPicture15 months ago

  • Cc xoodrew@… added

comment:3 lgedeon14 months ago

  • Cc luke.gedeon@… added
  • Keywords dev-feedback added

I would love to chase this one but I am rather new and could use some guidance.

Would it be better to set this up as a filter like rarst did here: http://wordpress.stackexchange.com/a/6652/11310 or just as a function call or even inline?

comment:4 ocean9014 months ago

  • Cc ocean90 added

+1 for this.

I just checked the transients on one of my sites with my plugin and noticed that there are about 400 browser_ transients which are expired since 250 days and still exists.

On DB upgrade, purge all transients, regardless of expiration.

I'm not sure about this. This could result in an heavy first page load, depends on how the transients are used.

comment:5 bananastalktome14 months ago

  • Cc bananastalktome@… added

Should transients also be purged when an object-cache.php file is dropped in? Or at least should a task be scheduled which could do so? This way when someone eventually adds a custom object cache they are not stuck with hundreds of transient records in the database (even non-expired but now no longer used ones).

Or is this grounds for a separate ticket (or just a non-issue)?

comment:6 SergeyBiryukov14 months ago

  • Keywords has-patch added; needs-patch removed

20316.patch is an attempt to address both points of the description.

I'm also not sure about the possible performance impact of the second one though.

SergeyBiryukov14 months ago

comment:7 ryan14 months ago

  • Keywords early added
  • Milestone changed from 3.4 to Future Release

comment:8 dartiss7 months ago

Meanwhile, I've released a plugin that will perform the proposed functionality.

Additionally, and based on a suggestion I read elsewhere, I've added in an optimisation of the table after the removals take place.

comment:9 knutsp7 months ago

  • Cc knut@… added

comment:10 kovshenin8 weeks ago

  • Cc kovshenin added

comment:11 SergeyBiryukov7 weeks ago

Closed #24206 as a duplicate.

comment:12 TobiasBg7 weeks ago

  • Cc wordpress@… added
  • Keywords 3.7-early added; early removed
  • Type changed from defect (bug) to enhancement

comment:13 follow-ups: DavidAnderson7 weeks ago

Is there anything we can do to help progress on this issue? It just bit me - I found my options table had bloated to 250,000 entries, after just 2 months of the site being live.

David

comment:14 in reply to: ↑ 13 ; follow-up: dartiss7 weeks ago

Replying to DavidAnderson:

Is there anything we can do to help progress on this issue? It just bit me - I found my options table had bloated to 250,000 entries, after just 2 months of the site being live.

I can't answer as to when it will be looked at, but can I assume you've tried my plugin in the meantime (link above)? This will, for the time being, perform the same processing and keep the entries cleared.

I'm looking to implement a further option to report on which plugins are causing it. Technically they're not doing anything wrong but there may be an advantage to them re-thinking their caching strategy (as I've been doing with my own).

Last edited 5 weeks ago by dartiss (previous) (diff)

comment:15 follow-up: DavidAnderson7 weeks ago

Yes - I'd seen the plugin and was about to deploy it. The code using transients was my own! I've used transients as expiring access-tokens on many and various sites. I thought it was great that I *didn't* then have to spend any time thinking about cacheing strategy since WordPress had core functionality to do that for me.

Deploying a plugin is little effort, of course. But having this in core seems like a no-brainer - is there any good reason to *not* garbage collect expired transients?

comment:16 in reply to: ↑ 15 dartiss7 weeks ago

Replying to DavidAnderson:

Yes - I'd seen the plugin and was about to deploy it. The code using transients was my own! I've used transients as expiring access-tokens on many and various sites. I thought it was great that I *didn't* then have to spend any time thinking about cacheing strategy since WordPress had core functionality to do that for me.

Deploying a plugin is little effort, of course. But having this in core seems like a no-brainer - is there any good reason to *not* garbage collect expired transients?

Not that I'm aware of.

I'm not a Core developer so not in a position to do it myself. However, I know Andrew (Nacin) is keen to get this included - I guess it's just a case of time and priorities.

Last edited 5 weeks ago by dartiss (previous) (diff)

comment:17 lkraav7 weeks ago

  • Cc leho@… added

comment:18 iandunn7 weeks ago

  • Cc ian.dunn@… added

comment:19 in reply to: ↑ 13 DrewAPicture7 weeks ago

Replying to DavidAnderson:

Is there anything we can do to help progress on this issue? It just bit me - I found my options table had bloated to 250,000 entries, after just 2 months of the site being live.

David

It's been marked 3.7-early, so hopefully we can get this in in the next version.

comment:20 in reply to: ↑ 14 wonderboymusic7 weeks ago

Is there anything we can do to help progress on this issue?


  1. Use Memcached
  2. Manually delete them, then use Memcached

comment:21 jamescollins6 weeks ago

The WP e-Commerce plugin includes a use case for unique transient keys.

The Australia Post API responses are cached using transients, and the cache key(s) depend on the volume/dimensions/destination of each customer's cart contents, which means there can be quite a few different transient cache keys on each store.

Garbage collection of expired transients would be a fantastic addition I think.

comment:22 adamsilverstein6 weeks ago

  • Cc adamsilverstein@… added

comment:23 follow-up: nacin6 weeks ago

Expired transients should probably be removed using either delete_option() — akin to how get_transient() removes an expired transient, rather than announcing it with delete_transient()'s hooks — or since we are already doing straight database calls, with a DELETE. I don't think there is a need to do this noisily. It's kind of like something silently vanishing from a cache backend.

comment:24 nacin6 weeks ago

+1 for early 3.7, btw.

comment:25 in reply to: ↑ 23 dartiss6 weeks ago

Replying to nacin:

Expired transients should probably be removed using either delete_option() — akin to how get_transient() removes an expired transient, rather than announcing it with delete_transient()'s hooks — or since we are already doing straight database calls, with a DELETE. I don't think there is a need to do this noisily. It's kind of like something silently vanishing from a cache backend.

I totally agree. I was using a simple selection of the transient by SQL in my plugin but using delete_transient to then remove them - amongst other things this isn't very efficient at removing large numbers of un-housekeep transients. I'm coding a change this week to replace it with a single SQL to achieve it.

Last edited 5 weeks ago by dartiss (previous) (diff)

comment:26 brokentone6 weeks ago

  • Cc kenton.jacobsen@… added

comment:27 cyberhobo6 weeks ago

  • Cc cyberhobo@… added

comment:28 dartiss5 weeks ago

Having worked on the aforementioned plugin to provide this functionality can I highlight two concerns that need to be considered?

  1. As a user has mentioned above some people have a LARGE number of expired transients. Can I suggest that whichever package this is implemented in should perform a total wipe of transient data even if a database upgrade is not due? Although it will only affect the first run, performance does need to be considered - a single SQL statement (or as few as possible) if at all possible.
  2. I have also experienced issues with orphaned transients - where one of the transient record pairs has either gone missing or, due to truncation of the name, are now mis-matched. This will mean that the regular housekeeping is likely to miss these but I would suggest that the database upgrade 'clear all' should handle these. In my case I've, basically, performed a delete on the options table for all '_transient_' records - it's rough and basic but is needed to ensure that all transients truly are removed.

comment:29 Rarst5 days ago

  • Cc contact@… added
Note: See TracTickets for help on using tickets.