Last modified: 2014-05-27 22:21:17 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T59021, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 57021 - Optimize IP::isInRange performance for CIDR comparisons
Optimize IP::isInRange performance for CIDR comparisons
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
1.23.0
All All
: Normal enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
: performance
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-11-13 17:52 UTC by Bryan Davis
Modified: 2014-05-27 22:21 UTC (History)
3 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Bryan Davis 2013-11-13 17:52:49 UTC
An IP can be checked for inclusion in a CIDR block via bitwise operations. The current general purpose solution provided by IP::isInRange() does not take this potential optimization into account.
Comment 1 Aaron Schulz 2013-11-13 17:55:02 UTC
This is probably premature optimization (as silly as the code is). That said, I'd like to see toUnsigned() removed, it's usage in the class is roundabout and overly complex (hurting readability).
Comment 2 Sam Reed (reedy) 2013-11-13 19:18:11 UTC
(In reply to comment #1)
> This is probably premature optimization (as silly as the code is). That said,
> I'd like to see toUnsigned() removed, it's usage in the class is roundabout
> and
> overly complex (hurting readability).

Really? Repeated calls resulted in a large jump in cluster CPU usage...
Comment 3 Aaron Schulz 2013-11-14 01:26:31 UTC
(In reply to comment #2)
> (In reply to comment #1)
> > This is probably premature optimization (as silly as the code is). That said,
> > I'd like to see toUnsigned() removed, it's usage in the class is roundabout
> > and
> > overly complex (hurting readability).
> 
> Really? Repeated calls resulted in a large jump in cluster CPU usage...

Where is the graph? I guess if you call something enough times...
Comment 4 Faidon Liambotis 2013-11-14 01:37:33 UTC
That would be http://ganglia.wikimedia.org/latest/graph.php?r=day&z=xlarge&c=Application+servers+eqiad&m=cpu_report&s=by+name&mc=2&g=cpu_report (ephemeral), I left some notes about it on 52829.
Comment 5 Bryan Davis 2013-11-14 16:31:14 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > Really? Repeated calls resulted in a large jump in cluster CPU usage...
> 
> Where is the graph? I guess if you call something enough times...

This was almost definitely a case of "calling something enough times". When I made the patch for 52829 I didn't fully comprehend the size of the WMF $wgSquidServersNoPurge list and the expected number of times it would be traversed in the course of a normal request. I have a hunch that if the configuration had been converted to the 10-15 CIDR ranges that should be able to cover the production cache clusters at the same time that the change enabling CIDR usage was rolled out we wouldn't be bothering to look at this.

The follow on patches that have been made for 52829 should help greatly, but there will still be a performance hit for sites configured with a large number of $wgSquidServersNoPurge entries. If the large list is primarily/entirely single IPv4/IPv6 addresses the cost should be constrained to a list traversal with a single strpos() call per entry.
Comment 6 Bryan Davis 2014-05-05 19:12:53 UTC
Brandon tried again to use the CIDR ranges in I5a2d86ef060b5b95412dbf42f8f955f3834aad8e, but this resulted in CPU utilization on the API servers jumping from ~50% to ~90%. It was reverted promptly.
Comment 7 Gerrit Notification Bot 2014-05-07 20:27:56 UTC
Change 131758 had a related patch set uploaded by MaxSem:
Speed up CIDR matching from $wgSquidServersNoPurge

https://gerrit.wikimedia.org/r/131758
Comment 8 Bryan Davis 2014-05-27 22:21:17 UTC
Brandon Black implemented a highly optimized CIDR matching engine in Ia3b12fb90c3e7e492374a128943b014481cc2730.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links