Page MenuHomePhabricator

Reduce timeouts for prolific editors
Closed, ResolvedPublic

Description

Problem: the tool depends on databases that are updated on a monthly cadence. Between these updates, it uses the Mediawiki APIs to gather edit data since the last snapshot for any account that is queried -- e.g., if the snapshot was until April 30th and it's now May 15th, all edits made by the account between April 30th and May 15th would be gathered. For each of these new edits, the history of the edited page is also gathered to find overlapping accounts. For prolific editors / heavily-edited pages, this can result in a lot of API calls and cause timeouts. More context: T307023#7998668

Simplest fix: currently the tool caps the number of pages queried at 1000. This could be reduced down to e.g., 50, which would reduce the likelihood of timeouts. The missing data could be made transparent (the date range covered is already part of the API response) and subsequent calls would continue to update the databases until all the account's edits were incorporated. @Isaac will implement this and send to @Tchanders to coordinate testing / review.

Code: https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/services/similar-users/+/refs/heads/main/similar_users/wsgi.py#507

Caveats:

  • I don't know the right number of pages to cap this at but am going to try 50 and expect this to be reached relatively rarely -- i.e. to hit that cap, you'd need an editor who had edited 50 unique content pages in the past month and most suspected sockpuppets have fairly sparse activity in my observations. If we're seeing a lot of timeouts, we can always reduce further but I'm hesitant to go too low to start.
  • We're making some assumptions too about the data that aren't perfect and the more sessions the edit data update is spread across, the more likely we are to introduce error into the data. I wouldn't be super concerned about this and I haven't empirically evaluated it but an FYI. Each monthly database update resets this error to 0 though, so that's good.
  • A long term fix might also limit how much page history for each page is gathered but that's far more complicated so taking the simple route and monitoring for timeouts would be my preference before undergoing that work.

Event Timeline

Change 805472 had a related patch set uploaded (by Isaac Johnson; author: Isaac Johnson):

[mediawiki/services/similar-users@main] Reduce number of new pages queried per account and make logic more robust to reduce timeouts.

https://gerrit.wikimedia.org/r/805472

ok -- patch uploaded. @Tchanders let me know here or on the patch if there's any questions etc. Only caveat is I created a new config variable so it would be easier to adjust this in the future without changing code. but for testing/production, obviously have to make sure that the config file being used has this variable too.

If testing locally, you'll need to update flask_config. Now I think about this, the config on production presumably need updating too. @hnowlan do you know how we can do this?

@dom_walden If beta is now broken, I may need to revert the patch for this until we've fixed the production config - let me know if you find this is the case before I do...

@dom_walden If beta is now broken, I may need to revert the patch for this until we've fixed the production config - let me know if you find this is the case before I do...

Beta appears to be working fine. But then again it is using the mock client.

@dom_walden If beta is now broken, I may need to revert the patch for this until we've fixed the production config - let me know if you find this is the case before I do...

Beta appears to be working fine. But then again it is using the mock client.

Oh yes, of course.

Change 808923 had a related patch set uploaded (by Hnowlan; author: Hnowlan):

[operations/deployment-charts@master] similar-users: make max queries per account configurable

https://gerrit.wikimedia.org/r/808923

@hnowlan do you know how we can do this?

This change should make it configurable, we can tweak the value upwards and downwards as we see fit (or have it higher in staging)

Change 805472 merged by jenkins-bot:

[mediawiki/services/similar-users@main] Reduce number of new pages queried per account

https://gerrit.wikimedia.org/r/805472

Submitting the Special:SimilarEditors form with every user the Similarusers service knows about from the test data.

Previously, just over 300 users would lead to timeouts in the service. Now we have about 10.

I had MAX_PAGES_PER_LOOKUP: 50 (which is the default I think).

Test environment:

Previously, just over 300 users would lead to timeouts in the service. Now we have about 10.

Yay! Just a note that I've shared before -- this depends heavily on when the databases supporting the tool were last updated too. In production, we should have much more up-to-date databases, so in theory that 10 should drop even lower. If folks are concerned though, we could drop the MAX_PAGES_PER_LOOKUP down to e.g., 30 too just to be safe.

Change #808923 abandoned by Hnowlan:

[operations/deployment-charts@master] similar-users: make max queries per account configurable

https://gerrit.wikimedia.org/r/808923