From 1ced82cc812b830cf755d2d300351ea92a0dc9a2 Mon Sep 17 00:00:00 2001 From: Aaron Myers Date: Sat, 29 Sep 2012 00:59:04 +0000 Subject: [PATCH] HADOOP-8866. SampleQuantiles#query is O(N^2) instead of O(N). Contributed by Andrew Wang. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1391711 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../org/apache/hadoop/metrics2/util/SampleQuantiles.java | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 979b9410fc..40970210d0 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -280,6 +280,9 @@ Release 2.0.3-alpha - Unreleased OPTIMIZATIONS + HADOOP-8866. SampleQuantiles#query is O(N^2) instead of O(N). (Andrew Wang + via atm) + BUG FIXES HADOOP-8795. BASH tab completion doesn't look in PATH, assumes path to diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/util/SampleQuantiles.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/util/SampleQuantiles.java index c0b14cc21e..97685b4fe4 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/util/SampleQuantiles.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/util/SampleQuantiles.java @@ -210,9 +210,12 @@ private long query(double quantile) throws IOException { int rankMin = 0; int desired = (int) (quantile * count); + ListIterator it = samples.listIterator(); + SampleItem prev = null; + SampleItem cur = it.next(); for (int i = 1; i < samples.size(); i++) { - SampleItem prev = samples.get(i - 1); - SampleItem cur = samples.get(i); + prev = cur; + cur = it.next(); rankMin += prev.g;