From a56520d26d70ae731ed929660e29df119290114f Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Tue, 13 Jan 2015 11:43:13 +0100 Subject: [PATCH] Internal: clean up memory reuse a bit. - don't allow for soft references anymore in the recycler - remove some abusive thread locals - don't recycle independently float/double and int/long pages, they are the same and just interpret bits differently. Close #9272 --- .../cache/recycler/PageCacheRecycler.java | 50 +----------------- .../common/recycler/Recyclers.java | 39 -------------- .../common/util/AbstractBigArray.java | 20 -------- .../elasticsearch/common/util/BigArrays.java | 51 +++++++++---------- .../common/util/BigDoubleArray.java | 33 ++++++------ .../common/util/BigFloatArray.java | 33 ++++++------ .../mapper/core/AbstractFieldMapper.java | 11 +--- .../elasticsearch/search/dfs/DfsPhase.java | 12 +---- .../common/recycler/RecyclerBenchmark.java | 3 +- .../recycler/SoftConcurrentRecyclerTests.java | 29 ----------- .../cache/recycler/MockPageCacheRecycler.java | 9 ---- 11 files changed, 64 insertions(+), 226 deletions(-) delete mode 100644 src/test/java/org/elasticsearch/common/recycler/SoftConcurrentRecyclerTests.java diff --git a/src/main/java/org/elasticsearch/cache/recycler/PageCacheRecycler.java b/src/main/java/org/elasticsearch/cache/recycler/PageCacheRecycler.java index c2fc53c2c5f..9489cfad04c 100644 --- a/src/main/java/org/elasticsearch/cache/recycler/PageCacheRecycler.java +++ b/src/main/java/org/elasticsearch/cache/recycler/PageCacheRecycler.java @@ -46,16 +46,12 @@ public class PageCacheRecycler extends AbstractComponent { private final Recycler bytePage; private final Recycler intPage; private final Recycler longPage; - private final Recycler floatPage; - private final Recycler doublePage; private final Recycler objectPage; public void close() { bytePage.close(); intPage.close(); longPage.close(); - floatPage.close(); - doublePage.close(); objectPage.close(); } @@ -104,12 +100,10 @@ public class PageCacheRecycler extends AbstractComponent { final double bytesWeight = componentSettings.getAsDouble(WEIGHT + ".bytes", 1d); final double intsWeight = componentSettings.getAsDouble(WEIGHT + ".ints", 1d); final double longsWeight = componentSettings.getAsDouble(WEIGHT + ".longs", 1d); - final double floatsWeight = componentSettings.getAsDouble(WEIGHT + ".floats", 1d); - final double doublesWeight = componentSettings.getAsDouble(WEIGHT + ".doubles", 1d); // object pages are less useful to us so we give them a lower weight by default final double objectsWeight = componentSettings.getAsDouble(WEIGHT + ".objects", 0.1d); - final double totalWeight = bytesWeight + intsWeight + longsWeight + doublesWeight + objectsWeight; + final double totalWeight = bytesWeight + intsWeight + longsWeight + objectsWeight; bytePage = build(type, maxCount(limit, BigArrays.BYTE_PAGE_SIZE, bytesWeight, totalWeight), searchThreadPoolSize, availableProcessors, new AbstractRecyclerC() { @Override @@ -141,26 +135,6 @@ public class PageCacheRecycler extends AbstractComponent { // nothing to do } }); - floatPage = build(type, maxCount(limit, BigArrays.FLOAT_PAGE_SIZE, floatsWeight, totalWeight), searchThreadPoolSize, availableProcessors, new AbstractRecyclerC() { - @Override - public float[] newInstance(int sizing) { - return new float[BigArrays.FLOAT_PAGE_SIZE]; - } - @Override - public void recycle(float[] value) { - // nothing to do - } - }); - doublePage = build(type, maxCount(limit, BigArrays.DOUBLE_PAGE_SIZE, doublesWeight, totalWeight), searchThreadPoolSize, availableProcessors, new AbstractRecyclerC() { - @Override - public double[] newInstance(int sizing) { - return new double[BigArrays.DOUBLE_PAGE_SIZE]; - } - @Override - public void recycle(double[] value) { - // nothing to do - } - }); objectPage = build(type, maxCount(limit, BigArrays.OBJECT_PAGE_SIZE, objectsWeight, totalWeight), searchThreadPoolSize, availableProcessors, new AbstractRecyclerC() { @Override public Object[] newInstance(int sizing) { @@ -197,22 +171,6 @@ public class PageCacheRecycler extends AbstractComponent { return v; } - public Recycler.V floatPage(boolean clear) { - final Recycler.V v = floatPage.obtain(); - if (v.isRecycled() && clear) { - Arrays.fill(v.v(), 0f); - } - return v; - } - - public Recycler.V doublePage(boolean clear) { - final Recycler.V v = doublePage.obtain(); - if (v.isRecycled() && clear) { - Arrays.fill(v.v(), 0d); - } - return v; - } - public Recycler.V objectPage() { // object pages are cleared on release anyway return objectPage.obtain(); @@ -235,12 +193,6 @@ public class PageCacheRecycler extends AbstractComponent { return concurrentDeque(c, limit); } }, - SOFT_CONCURRENT { - @Override - Recycler build(Recycler.C c, int limit, int estimatedThreadPoolSize, int availableProcessors) { - return concurrent(softFactory(dequeFactory(c, limit / availableProcessors)), availableProcessors); - } - }, CONCURRENT { @Override Recycler build(Recycler.C c, int limit, int estimatedThreadPoolSize, int availableProcessors) { diff --git a/src/main/java/org/elasticsearch/common/recycler/Recyclers.java b/src/main/java/org/elasticsearch/common/recycler/Recyclers.java index ef934f6e656..da526664513 100644 --- a/src/main/java/org/elasticsearch/common/recycler/Recyclers.java +++ b/src/main/java/org/elasticsearch/common/recycler/Recyclers.java @@ -91,45 +91,6 @@ public enum Recyclers { }; } - /** - * Create a recycler that is wrapped inside a soft reference, so that it cannot cause {@link OutOfMemoryError}s. - */ - public static Recycler soft(final Recycler.Factory factory) { - return new FilterRecycler() { - - SoftReference> ref; - - { - ref = new SoftReference<>(null); - } - - @Override - protected Recycler getDelegate() { - Recycler recycler = ref.get(); - if (recycler == null) { - recycler = factory.build(); - ref = new SoftReference<>(recycler); - } - return recycler; - } - - }; - } - - /** - * Create a recycler that wraps data in a SoftReference. - * - * @see #soft(org.elasticsearch.common.recycler.Recycler.Factory) - */ - public static Recycler.Factory softFactory(final Recycler.Factory factory) { - return new Recycler.Factory() { - @Override - public Recycler build() { - return soft(factory); - } - }; - } - /** * Wrap the provided recycler so that calls to {@link Recycler#obtain()} and {@link Recycler.V#close()} are protected by * a lock. diff --git a/src/main/java/org/elasticsearch/common/util/AbstractBigArray.java b/src/main/java/org/elasticsearch/common/util/AbstractBigArray.java index 22175387f77..2a2620338cb 100644 --- a/src/main/java/org/elasticsearch/common/util/AbstractBigArray.java +++ b/src/main/java/org/elasticsearch/common/util/AbstractBigArray.java @@ -32,8 +32,6 @@ import java.util.Arrays; /** Common implementation for array lists that slice data into fixed-size blocks. */ abstract class AbstractBigArray extends AbstractArray { - private static final long EMPTY_SIZE = RamUsageEstimator.shallowSizeOfInstance(AbstractBigArray.class) + RamUsageEstimator.NUM_BYTES_OBJECT_REF + RamUsageEstimator.NUM_BYTES_ARRAY_HEADER; - private final PageCacheRecycler recycler; private Recycler.V[] cache; @@ -130,24 +128,6 @@ abstract class AbstractBigArray extends AbstractArray { } } - protected final float[] newFloatPage(int page) { - if (recycler != null) { - final Recycler.V v = recycler.floatPage(clearOnResize); - return registerNewPage(v, page, BigArrays.FLOAT_PAGE_SIZE); - } else { - return new float[BigArrays.FLOAT_PAGE_SIZE]; - } - } - - protected final double[] newDoublePage(int page) { - if (recycler != null) { - final Recycler.V v = recycler.doublePage(clearOnResize); - return registerNewPage(v, page, BigArrays.DOUBLE_PAGE_SIZE); - } else { - return new double[BigArrays.DOUBLE_PAGE_SIZE]; - } - } - protected final Object[] newObjectPage(int page) { if (recycler != null) { final Recycler.V v = recycler.objectPage(); diff --git a/src/main/java/org/elasticsearch/common/util/BigArrays.java b/src/main/java/org/elasticsearch/common/util/BigArrays.java index ae1cc6a70b5..4e6309e43c3 100644 --- a/src/main/java/org/elasticsearch/common/util/BigArrays.java +++ b/src/main/java/org/elasticsearch/common/util/BigArrays.java @@ -37,7 +37,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.breaker.CircuitBreakerService; import java.util.Arrays; -import java.util.concurrent.atomic.AtomicLong; /** Utility class to work with arrays. */ public class BigArrays extends AbstractComponent { @@ -48,9 +47,7 @@ public class BigArrays extends AbstractComponent { public static final int PAGE_SIZE_IN_BYTES = 1 << 14; public static final int BYTE_PAGE_SIZE = BigArrays.PAGE_SIZE_IN_BYTES / RamUsageEstimator.NUM_BYTES_BYTE; public static final int INT_PAGE_SIZE = BigArrays.PAGE_SIZE_IN_BYTES / RamUsageEstimator.NUM_BYTES_INT; - public static final int FLOAT_PAGE_SIZE = BigArrays.PAGE_SIZE_IN_BYTES / RamUsageEstimator.NUM_BYTES_FLOAT; public static final int LONG_PAGE_SIZE = BigArrays.PAGE_SIZE_IN_BYTES / RamUsageEstimator.NUM_BYTES_LONG; - public static final int DOUBLE_PAGE_SIZE = BigArrays.PAGE_SIZE_IN_BYTES / RamUsageEstimator.NUM_BYTES_DOUBLE; public static final int OBJECT_PAGE_SIZE = BigArrays.PAGE_SIZE_IN_BYTES / RamUsageEstimator.NUM_BYTES_OBJECT_REF; /** Returns the next size to grow when working with parallel arrays that may have different page sizes or number of bytes per element. */ @@ -247,9 +244,9 @@ public class BigArrays extends AbstractComponent { private static class DoubleArrayWrapper extends AbstractArrayWrapper implements DoubleArray { - private final double[] array; + private final long[] array; - DoubleArrayWrapper(BigArrays bigArrays, double[] array, long size, Recycler.V releasable, boolean clearOnResize) { + DoubleArrayWrapper(BigArrays bigArrays, long[] array, long size, Recycler.V releasable, boolean clearOnResize) { super(bigArrays, size, releasable, clearOnResize); this.array = array; } @@ -262,37 +259,37 @@ public class BigArrays extends AbstractComponent { @Override public double get(long index) { assert indexIsInt(index); - return array[(int) index]; + return Double.longBitsToDouble(array[(int) index]); } @Override public double set(long index, double value) { assert indexIsInt(index); - double ret = array[(int) index]; - array[(int) index] = value; + double ret = Double.longBitsToDouble(array[(int) index]); + array[(int) index] = Double.doubleToRawLongBits(value); return ret; } @Override public double increment(long index, double inc) { assert indexIsInt(index); - return array[(int) index] += inc; + return array[(int) index] = Double.doubleToRawLongBits(Double.longBitsToDouble(array[(int) index]) + inc); } @Override public void fill(long fromIndex, long toIndex, double value) { assert indexIsInt(fromIndex); assert indexIsInt(toIndex); - Arrays.fill(array, (int) fromIndex, (int) toIndex, value); + Arrays.fill(array, (int) fromIndex, (int) toIndex, Double.doubleToRawLongBits(value)); } } private static class FloatArrayWrapper extends AbstractArrayWrapper implements FloatArray { - private final float[] array; + private final int[] array; - FloatArrayWrapper(BigArrays bigArrays, float[] array, long size, Recycler.V releasable, boolean clearOnResize) { + FloatArrayWrapper(BigArrays bigArrays, int[] array, long size, Recycler.V releasable, boolean clearOnResize) { super(bigArrays, size, releasable, clearOnResize); this.array = array; } @@ -305,28 +302,28 @@ public class BigArrays extends AbstractComponent { @Override public float get(long index) { assert indexIsInt(index); - return array[(int) index]; + return Float.intBitsToFloat(array[(int) index]); } @Override public float set(long index, float value) { assert indexIsInt(index); - float ret = array[(int) index]; - array[(int) index] = value; + float ret = Float.intBitsToFloat(array[(int) index]); + array[(int) index] = Float.floatToRawIntBits(value); return ret; } @Override public float increment(long index, float inc) { assert indexIsInt(index); - return array[(int) index] += inc; + return array[(int) index] = Float.floatToRawIntBits(Float.intBitsToFloat(array[(int) index]) + inc); } @Override public void fill(long fromIndex, long toIndex, float value) { assert indexIsInt(fromIndex); assert indexIsInt(toIndex); - Arrays.fill(array, (int) fromIndex, (int) toIndex, value); + Arrays.fill(array, (int) fromIndex, (int) toIndex, Float.floatToRawIntBits(value)); } } @@ -629,13 +626,13 @@ public class BigArrays extends AbstractComponent { */ public DoubleArray newDoubleArray(long size, boolean clearOnResize) { final DoubleArray arr; - if (size > DOUBLE_PAGE_SIZE) { + if (size > LONG_PAGE_SIZE) { arr = new BigDoubleArray(size, this, clearOnResize); - } else if (size >= DOUBLE_PAGE_SIZE / 2 && recycler != null) { - final Recycler.V page = recycler.doublePage(clearOnResize); + } else if (size >= LONG_PAGE_SIZE / 2 && recycler != null) { + final Recycler.V page = recycler.longPage(clearOnResize); arr = new DoubleArrayWrapper(this, page.v(), size, page, clearOnResize); } else { - arr = new DoubleArrayWrapper(this, new double[(int) size], size, null, clearOnResize); + arr = new DoubleArrayWrapper(this, new long[(int) size], size, null, clearOnResize); } return validate(arr); } @@ -665,7 +662,7 @@ public class BigArrays extends AbstractComponent { if (minSize <= array.size()) { return array; } - final long newSize = overSize(minSize, DOUBLE_PAGE_SIZE, RamUsageEstimator.NUM_BYTES_DOUBLE); + final long newSize = overSize(minSize, LONG_PAGE_SIZE, RamUsageEstimator.NUM_BYTES_LONG); return resize(array, newSize); } @@ -676,13 +673,13 @@ public class BigArrays extends AbstractComponent { */ public FloatArray newFloatArray(long size, boolean clearOnResize) { final FloatArray array; - if (size > FLOAT_PAGE_SIZE) { + if (size > INT_PAGE_SIZE) { array = new BigFloatArray(size, this, clearOnResize); - } else if (size >= FLOAT_PAGE_SIZE / 2 && recycler != null) { - final Recycler.V page = recycler.floatPage(clearOnResize); + } else if (size >= INT_PAGE_SIZE / 2 && recycler != null) { + final Recycler.V page = recycler.intPage(clearOnResize); array = new FloatArrayWrapper(this, page.v(), size, page, clearOnResize); } else { - array = new FloatArrayWrapper(this, new float[(int) size], size, null, clearOnResize); + array = new FloatArrayWrapper(this, new int[(int) size], size, null, clearOnResize); } return validate(array); } @@ -712,7 +709,7 @@ public class BigArrays extends AbstractComponent { if (minSize <= array.size()) { return array; } - final long newSize = overSize(minSize, FLOAT_PAGE_SIZE, RamUsageEstimator.NUM_BYTES_FLOAT); + final long newSize = overSize(minSize, INT_PAGE_SIZE, RamUsageEstimator.NUM_BYTES_FLOAT); return resize(array, newSize); } diff --git a/src/main/java/org/elasticsearch/common/util/BigDoubleArray.java b/src/main/java/org/elasticsearch/common/util/BigDoubleArray.java index 4f6818acef5..44bbd6817de 100644 --- a/src/main/java/org/elasticsearch/common/util/BigDoubleArray.java +++ b/src/main/java/org/elasticsearch/common/util/BigDoubleArray.java @@ -20,12 +20,13 @@ package org.elasticsearch.common.util; import com.google.common.base.Preconditions; + import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.RamUsageEstimator; import java.util.Arrays; -import static org.elasticsearch.common.util.BigArrays.DOUBLE_PAGE_SIZE; +import static org.elasticsearch.common.util.BigArrays.LONG_PAGE_SIZE; /** * Double array abstraction able to support more than 2B values. This implementation slices data into fixed-sized blocks of @@ -33,15 +34,15 @@ import static org.elasticsearch.common.util.BigArrays.DOUBLE_PAGE_SIZE; */ final class BigDoubleArray extends AbstractBigArray implements DoubleArray { - private double[][] pages; + private long[][] pages; /** Constructor. */ public BigDoubleArray(long size, BigArrays bigArrays, boolean clearOnResize) { - super(DOUBLE_PAGE_SIZE, bigArrays, clearOnResize); + super(LONG_PAGE_SIZE, bigArrays, clearOnResize); this.size = size; - pages = new double[numPages(size)][]; + pages = new long[numPages(size)][]; for (int i = 0; i < pages.length; ++i) { - pages[i] = newDoublePage(i); + pages[i] = newLongPage(i); } } @@ -49,16 +50,16 @@ final class BigDoubleArray extends AbstractBigArray implements DoubleArray { public double get(long index) { final int pageIndex = pageIndex(index); final int indexInPage = indexInPage(index); - return pages[pageIndex][indexInPage]; + return Double.longBitsToDouble(pages[pageIndex][indexInPage]); } @Override public double set(long index, double value) { final int pageIndex = pageIndex(index); final int indexInPage = indexInPage(index); - final double[] page = pages[pageIndex]; - final double ret = page[indexInPage]; - page[indexInPage] = value; + final long[] page = pages[pageIndex]; + final double ret = Double.longBitsToDouble(page[indexInPage]); + page[indexInPage] = Double.doubleToRawLongBits(value); return ret; } @@ -66,7 +67,8 @@ final class BigDoubleArray extends AbstractBigArray implements DoubleArray { public double increment(long index, double inc) { final int pageIndex = pageIndex(index); final int indexInPage = indexInPage(index); - return pages[pageIndex][indexInPage] += inc; + final long[] page = pages[pageIndex]; + return page[indexInPage] = Double.doubleToRawLongBits(Double.longBitsToDouble(page[indexInPage]) + inc); } @Override @@ -81,7 +83,7 @@ final class BigDoubleArray extends AbstractBigArray implements DoubleArray { pages = Arrays.copyOf(pages, ArrayUtil.oversize(numPages, RamUsageEstimator.NUM_BYTES_OBJECT_REF)); } for (int i = numPages - 1; i >= 0 && pages[i] == null; --i) { - pages[i] = newDoublePage(i); + pages[i] = newLongPage(i); } for (int i = numPages; i < pages.length && pages[i] != null; ++i) { pages[i] = null; @@ -93,16 +95,17 @@ final class BigDoubleArray extends AbstractBigArray implements DoubleArray { @Override public void fill(long fromIndex, long toIndex, double value) { Preconditions.checkArgument(fromIndex <= toIndex); + final long longBits = Double.doubleToRawLongBits(value); final int fromPage = pageIndex(fromIndex); final int toPage = pageIndex(toIndex - 1); if (fromPage == toPage) { - Arrays.fill(pages[fromPage], indexInPage(fromIndex), indexInPage(toIndex - 1) + 1, value); + Arrays.fill(pages[fromPage], indexInPage(fromIndex), indexInPage(toIndex - 1) + 1, longBits); } else { - Arrays.fill(pages[fromPage], indexInPage(fromIndex), pages[fromPage].length, value); + Arrays.fill(pages[fromPage], indexInPage(fromIndex), pages[fromPage].length, longBits); for (int i = fromPage + 1; i < toPage; ++i) { - Arrays.fill(pages[i], value); + Arrays.fill(pages[i], longBits); } - Arrays.fill(pages[toPage], 0, indexInPage(toIndex - 1) + 1, value); + Arrays.fill(pages[toPage], 0, indexInPage(toIndex - 1) + 1, longBits); } } diff --git a/src/main/java/org/elasticsearch/common/util/BigFloatArray.java b/src/main/java/org/elasticsearch/common/util/BigFloatArray.java index 98540ff12e8..5d90a23e7e1 100644 --- a/src/main/java/org/elasticsearch/common/util/BigFloatArray.java +++ b/src/main/java/org/elasticsearch/common/util/BigFloatArray.java @@ -20,12 +20,13 @@ package org.elasticsearch.common.util; import com.google.common.base.Preconditions; + import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.RamUsageEstimator; import java.util.Arrays; -import static org.elasticsearch.common.util.BigArrays.FLOAT_PAGE_SIZE; +import static org.elasticsearch.common.util.BigArrays.INT_PAGE_SIZE; /** * Float array abstraction able to support more than 2B values. This implementation slices data into fixed-sized blocks of @@ -33,15 +34,15 @@ import static org.elasticsearch.common.util.BigArrays.FLOAT_PAGE_SIZE; */ final class BigFloatArray extends AbstractBigArray implements FloatArray { - private float[][] pages; + private int[][] pages; /** Constructor. */ public BigFloatArray(long size, BigArrays bigArrays, boolean clearOnResize) { - super(FLOAT_PAGE_SIZE, bigArrays, clearOnResize); + super(INT_PAGE_SIZE, bigArrays, clearOnResize); this.size = size; - pages = new float[numPages(size)][]; + pages = new int[numPages(size)][]; for (int i = 0; i < pages.length; ++i) { - pages[i] = newFloatPage(i); + pages[i] = newIntPage(i); } } @@ -49,9 +50,9 @@ final class BigFloatArray extends AbstractBigArray implements FloatArray { public float set(long index, float value) { final int pageIndex = pageIndex(index); final int indexInPage = indexInPage(index); - final float[] page = pages[pageIndex]; - final float ret = page[indexInPage]; - page[indexInPage] = value; + final int[] page = pages[pageIndex]; + final float ret = Float.intBitsToFloat(page[indexInPage]); + page[indexInPage] = Float.floatToRawIntBits(value); return ret; } @@ -59,13 +60,14 @@ final class BigFloatArray extends AbstractBigArray implements FloatArray { public float increment(long index, float inc) { final int pageIndex = pageIndex(index); final int indexInPage = indexInPage(index); - return pages[pageIndex][indexInPage] += inc; + final int[] page = pages[pageIndex]; + return page[indexInPage] = Float.floatToRawIntBits(Float.intBitsToFloat(page[indexInPage]) + inc); } public float get(long index) { final int pageIndex = pageIndex(index); final int indexInPage = indexInPage(index); - return pages[pageIndex][indexInPage]; + return Float.intBitsToFloat(pages[pageIndex][indexInPage]); } @Override @@ -80,7 +82,7 @@ final class BigFloatArray extends AbstractBigArray implements FloatArray { pages = Arrays.copyOf(pages, ArrayUtil.oversize(numPages, RamUsageEstimator.NUM_BYTES_OBJECT_REF)); } for (int i = numPages - 1; i >= 0 && pages[i] == null; --i) { - pages[i] = newFloatPage(i); + pages[i] = newIntPage(i); } for (int i = numPages; i < pages.length && pages[i] != null; ++i) { pages[i] = null; @@ -92,16 +94,17 @@ final class BigFloatArray extends AbstractBigArray implements FloatArray { @Override public void fill(long fromIndex, long toIndex, float value) { Preconditions.checkArgument(fromIndex <= toIndex); + final int intBits = Float.floatToRawIntBits(value); final int fromPage = pageIndex(fromIndex); final int toPage = pageIndex(toIndex - 1); if (fromPage == toPage) { - Arrays.fill(pages[fromPage], indexInPage(fromIndex), indexInPage(toIndex - 1) + 1, value); + Arrays.fill(pages[fromPage], indexInPage(fromIndex), indexInPage(toIndex - 1) + 1, intBits); } else { - Arrays.fill(pages[fromPage], indexInPage(fromIndex), pages[fromPage].length, value); + Arrays.fill(pages[fromPage], indexInPage(fromIndex), pages[fromPage].length, intBits); for (int i = fromPage + 1; i < toPage; ++i) { - Arrays.fill(pages[i], value); + Arrays.fill(pages[i], intBits); } - Arrays.fill(pages[toPage], 0, indexInPage(toIndex - 1) + 1, value); + Arrays.fill(pages[toPage], 0, indexInPage(toIndex - 1) + 1, intBits); } } diff --git a/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java index 709b238cf94..459c7162427 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java @@ -273,12 +273,6 @@ public abstract class AbstractFieldMapper implements FieldMapper { } } - private static final ThreadLocal> FIELD_LIST = new ThreadLocal>() { - protected List initialValue() { - return new ArrayList<>(2); - } - }; - protected final Names names; protected float boost; protected FieldType fieldType; @@ -419,8 +413,7 @@ public abstract class AbstractFieldMapper implements FieldMapper { @Override public void parse(ParseContext context) throws IOException { - final List fields = FIELD_LIST.get(); - assert fields.isEmpty(); + final List fields = new ArrayList<>(2); try { parseCreateField(context, fields); for (Field field : fields) { @@ -433,8 +426,6 @@ public abstract class AbstractFieldMapper implements FieldMapper { } } catch (Exception e) { throw new MapperParsingException("failed to parse [" + names.fullName() + "]", e); - } finally { - fields.clear(); } multiFields.parse(this, context); if (copyTo != null) { diff --git a/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java b/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java index c24b1a6e870..a7b8ff48618 100644 --- a/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java +++ b/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java @@ -44,13 +44,6 @@ import java.util.Map; */ public class DfsPhase implements SearchPhase { - private static ThreadLocal> cachedTermsSet = new ThreadLocal>() { - @Override - protected ObjectOpenHashSet initialValue() { - return new ObjectOpenHashSet<>(); - } - }; - @Override public Map parseElements() { return ImmutableMap.of(); @@ -61,15 +54,12 @@ public class DfsPhase implements SearchPhase { } public void execute(SearchContext context) { - final ObjectOpenHashSet termsSet = cachedTermsSet.get(); + final ObjectOpenHashSet termsSet = new ObjectOpenHashSet<>(); try { if (!context.queryRewritten()) { context.updateRewriteQuery(context.searcher().rewrite(context.query())); } - if (!termsSet.isEmpty()) { - termsSet.clear(); - } context.query().extractTerms(new DelegateSet(termsSet)); for (RescoreSearchContext rescoreContext : context.rescore()) { rescoreContext.rescorer().extractTerms(context, rescoreContext, new DelegateSet(termsSet)); diff --git a/src/test/java/org/elasticsearch/benchmark/common/recycler/RecyclerBenchmark.java b/src/test/java/org/elasticsearch/benchmark/common/recycler/RecyclerBenchmark.java index 37a662dec90..97113a6d1c5 100644 --- a/src/test/java/org/elasticsearch/benchmark/common/recycler/RecyclerBenchmark.java +++ b/src/test/java/org/elasticsearch/benchmark/common/recycler/RecyclerBenchmark.java @@ -93,8 +93,7 @@ public class RecyclerBenchmark { .put("none", none(c)) .put("concurrent-queue", concurrentDeque(c, limit)) .put("locked", locked(deque(c, limit))) - .put("concurrent", concurrent(dequeFactory(c, limit), Runtime.getRuntime().availableProcessors())) - .put("soft-concurrent", concurrent(softFactory(dequeFactory(c, limit)), Runtime.getRuntime().availableProcessors())).build(); + .put("concurrent", concurrent(dequeFactory(c, limit), Runtime.getRuntime().availableProcessors())).build(); // warmup final long start = System.nanoTime(); diff --git a/src/test/java/org/elasticsearch/common/recycler/SoftConcurrentRecyclerTests.java b/src/test/java/org/elasticsearch/common/recycler/SoftConcurrentRecyclerTests.java deleted file mode 100644 index 9ccc9908091..00000000000 --- a/src/test/java/org/elasticsearch/common/recycler/SoftConcurrentRecyclerTests.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.common.recycler; - -public class SoftConcurrentRecyclerTests extends AbstractRecyclerTests { - - @Override - protected Recycler newRecycler(int limit) { - return Recyclers.concurrent(Recyclers.softFactory(Recyclers.dequeFactory(RECYCLER_C, limit)), randomIntBetween(1, 5)); - } - -} diff --git a/src/test/java/org/elasticsearch/test/cache/recycler/MockPageCacheRecycler.java b/src/test/java/org/elasticsearch/test/cache/recycler/MockPageCacheRecycler.java index 521420a6ae5..b7c2d07d4d2 100644 --- a/src/test/java/org/elasticsearch/test/cache/recycler/MockPageCacheRecycler.java +++ b/src/test/java/org/elasticsearch/test/cache/recycler/MockPageCacheRecycler.java @@ -144,15 +144,6 @@ public class MockPageCacheRecycler extends PageCacheRecycler { return wrap(page); } - @Override - public V doublePage(boolean clear) { - final V page = super.doublePage(clear); - if (!clear) { - Arrays.fill(page.v(), 0, page.v().length, random.nextDouble() - 0.5); - } - return wrap(page); - } - @Override public V objectPage() { return wrap(super.objectPage());