Page MenuHomePhabricator

Updater got stuck on large update
Closed, ResolvedPublic

Description

On December 8, I have noticed that Updater is getting stuck on updates. Turns out there is a performance problem in Updater code, specifically in RdfRepository.java in this piece:

Collection<Statement> aboutStatements = new HashSet<>(insertStatements);
aboutStatements.removeAll(entityStatements);
aboutStatements.removeAll(statementStatements);
aboutStatements.removeAll(filtered(insertStatements).withSubjectStarts(uris.value()));
aboutStatements.removeAll(filtered(insertStatements).withSubjectStarts(uris.reference()));

The problem is in the implementation of removeAll:

if (size() > c.size()) {
     for (Iterator<?> i = c.iterator(); i.hasNext(); )
         modified |= remove(i.next());
 } else {
     for (Iterator<?> i = iterator(); i.hasNext(); ) {
         if (c.contains(i.next())) {
             i.remove();
             modified = true;
         }
     }
 }

As we can see, in certain situations, instead of going over elements of c and removing them, it opts to go over elements of the set and check if they are in c. The problem is that in this case c is a filter on a 100K-size list, which means each check produces the scan of the whole (or close to it) list. This makes the whole procedure extremely slow.

Event Timeline

Change 396474 had a related patch set uploaded (by Smalyshev; owner: Smalyshev):
[wikidata/query/rdf@master] Fix Updater performance issue

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

Change 396484 had a related patch set uploaded (by Smalyshev; owner: Smalyshev):
[wikidata/query/rdf@master] Temporary plug to cap batch size

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

Change 396484 merged by jenkins-bot:
[wikidata/query/rdf@master] Temporary plug to cap batch size

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

Mentioned in SAL (#wikimedia-operations) [2017-12-08T21:59:35Z] <smalyshev@tin> Started deploy [wdqs/wdqs@353b3cb]: temporary fix for T182464, better fix coming soon

Mentioned in SAL (#wikimedia-operations) [2017-12-08T22:05:30Z] <smalyshev@tin> Finished deploy [wdqs/wdqs@353b3cb]: temporary fix for T182464, better fix coming soon (duration: 05m 55s)

Change 396474 merged by jenkins-bot:
[wikidata/query/rdf@master] Fix Updater performance issue

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