Page MenuHomePhabricator

MediaSearch with synonyms turned on sometimes takes MUCH longer than without
Closed, ResolvedPublicBUG REPORT

Description

During T290652 we discovered that searching with synonyms turned on sometimes takes much longer than expected, and can even cause searching to time out

Here's a comparison of labeled queries ordered by response times

image.png (803×496 px, 43 KB)

The slowest running query (>10s, which means a timeout) is for "wikimedia commons" which only takes ~1s without synonyms

It's not clear what's going on. Here's what I've found so far:

  • the query that gets generated for "wikimedia commons" includes a search for 10 synonyms, and running it directly on production elasticsearch causes a timeout
  • the query that gets generated for "dog" includes a search for 7 synonyms, and running it directly on production elasticsearch takes around 1.5s
  • running the "wikimedia commons" search with all synonyms except one removed takes ~5s
  • running the "wikimedia commons" search with all synonyms removed takes ~1s

Just for comparison, here are the "dog" query and the "wikimedia commons" query, simplified for clarity, and with some synonym subqueries removed from the "wikimedia commons" query so that both have the same number of synonym subqueries


I'm running these queries by setting up a tunnel to production elasticsearch like this
ssh -n -L127.0.0.1:9243:<production elasticsearch server>:9243 mwdebug1002.eqiad.wmnet "sleep 36000"
and then executing the search like this
curl -k https://localhost:9243/commonswiki_file/_search?request_cache=false -H "Content-Type: application/json" -d @</path/to/json/file>

Warning: tunneling to production is dangerous. Be really careful NOT to do vagrant provision with the tunnel open (cos that might delete search indices on production), or tunnel to cloudelastic1001.wikimedia.org instead

The "dog" query takes ~1.5s, the "wikimedia commons" query takes ~8.5s. Even if I take out all synonym subqueries except 1, the "wikimedia commons" query takes ~3.5s

Event Timeline

Cparle renamed this task from MediaSearch with synonyms turned sometimes takes MUCH longer than without to MediaSearch with synonyms turned on sometimes takes MUCH longer than without.Oct 12 2021, 3:39 PM
Cparle updated the task description. (Show Details)
Cparle updated the task description. (Show Details)

The plan is to investigate this for three days, and then check in if we don't have a solution.

Change 753166 had a related patch set uploaded (by Matthias Mullie; author: Matthias Mullie):

[mediawiki/extensions/WikibaseMediaInfo@master] Optimize synonyms profile

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

Impact of synonyms on the overwhelmingly large majority of queries is quite small already, but it's huge for the extremes.
The slowest responses are all extremely common terms/letters/numbers (e.g. "commons", with ~70 million hits; "usa", "mountain" or "copyright"). Because they're complex to sort, and the additional terms make it even more expensive than they already were?

Note also that the differences at the extremes are in part caused by search terms (especially in other languages) that suddenly start to yielding a lot of results through the addition of English aliases, when before, they would have had non/little. In this case, the increased response time is acceptable; desirable even. Still, response times of 10 seconds is... wild.

I've submitted a patch that greatly optimizes which synonyms are sent, essentially getting rid of many variants that cause additional load without adding a meaningfully different term.
Dropping the term normalization that we're looking to remove in T296631 also makes a massive difference.
I also experimented with setting cutoff_frequency, but @dcausse pointed out that that will be deprecated in future versions. It didn't seem to make much difference for most terms anyway: made some extremes a bit faster, but seemed to hurt the average a little.

commons, for example, drops from ~13.5 seconds (current synonyms with term normalization) to ~3 seconds (optimizations in patch & no term normalization).
The existing profile (no synonyms) takes ~2.5 for that term.


Data of a couple of batches of ~3000 searches in similar circumstances for both search profiles. Here are the response times:

current
average: 836ms
median: 792ms
95%: 1031ms
99%: 1735ms

synonyms; original
average: 1041ms
median: 870ms
95%: 1748ms
99%: 4422ms

synonyms; optimized
average: 927ms
median: 821ms
95%: 1445ms
99%: 2602ms

synonyms; optimized, with cutoff_frequency
average: 941ms
median: 846ms
95%: 917ms
99%: 2658ms

Note that these are executed via an SSH tunnel to a replica. Actual production seems to produce responses about twice this fast, on average.

prod current
average: 358ms
median: 335ms
95%: 470ms
99%: 1049ms

Change 753722 had a related patch set uploaded (by Cparle; author: Cparle):

[operations/mediawiki-config@master] Remove fulltext normalisation in synonyms profile for performance

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

Change 753166 merged by jenkins-bot:

[mediawiki/extensions/WikibaseMediaInfo@master] Optimize synonyms profile

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

Etonkovidova closed this task as Resolved.EditedJan 28 2022, 12:35 AM
Etonkovidova subscribed.

Checked commons wmf.19 (for possible regression) - the test queries (mentioned in the task) took between 1.5 s-2.28 s.

Change 753722 abandoned by Matthias Mullie:

[operations/mediawiki-config@master] Remove fulltext normalisation in synonyms profile for performance

Reason:

This has already been done (and merged) in some other patch

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