From aa5f9d51586caa98a1156e4160668ce3b8bb2b28 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 1 Feb 2016 11:19:19 +0100 Subject: [PATCH] Convert PageCacheRecycler settings --- .../cache/recycler/PageCacheRecycler.java | 30 ++++++++++--------- .../common/settings/ClusterSettings.java | 9 +++++- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/cache/recycler/PageCacheRecycler.java b/core/src/main/java/org/elasticsearch/cache/recycler/PageCacheRecycler.java index 9fbbb151d6a..7016718b302 100644 --- a/core/src/main/java/org/elasticsearch/cache/recycler/PageCacheRecycler.java +++ b/core/src/main/java/org/elasticsearch/cache/recycler/PageCacheRecycler.java @@ -25,7 +25,9 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.lease.Releasable; import org.elasticsearch.common.recycler.AbstractRecyclerC; import org.elasticsearch.common.recycler.Recycler; +import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.threadpool.ThreadPool; @@ -41,9 +43,13 @@ import static org.elasticsearch.common.recycler.Recyclers.none; /** A recycler of fixed-size pages. */ public class PageCacheRecycler extends AbstractComponent implements Releasable { - public static final String TYPE = "recycler.page.type"; - public static final String LIMIT_HEAP = "recycler.page.limit.heap"; - public static final String WEIGHT = "recycler.page.weight"; + public static final Setting TYPE_SETTING = new Setting<>("cache.recycler.page.type", Type.CONCURRENT.name(), Type::parse, false, Setting.Scope.CLUSTER); + public static final Setting LIMIT_HEAP_SETTING = Setting.byteSizeSetting("cache.recycler.page.limit.heap", "10%", false, Setting.Scope.CLUSTER); + public static final Setting WEIGHT_BYTES_SETTING = Setting.doubleSetting("cache.recycler.page.weight.bytes", 1d, 0d, false, Setting.Scope.CLUSTER); + public static final Setting WEIGHT_LONG_SETTING = Setting.doubleSetting("cache.recycler.page.weight.longs", 1d, 0d, false, Setting.Scope.CLUSTER); + public static final Setting WEIGHT_INT_SETTING = Setting.doubleSetting("cache.recycler.page.weight.ints", 1d, 0d, false, Setting.Scope.CLUSTER); + // object pages are less useful to us so we give them a lower weight by default + public static final Setting WEIGHT_OBJECTS_SETTING = Setting.doubleSetting("cache.recycler.page.weight.objects", 0.1d, 0d, false, Setting.Scope.CLUSTER); private final Recycler bytePage; private final Recycler intPage; @@ -73,8 +79,8 @@ public class PageCacheRecycler extends AbstractComponent implements Releasable { @Inject public PageCacheRecycler(Settings settings, ThreadPool threadPool) { super(settings); - final Type type = Type.parse(settings.get(TYPE)); - final long limit = settings.getAsMemory(LIMIT_HEAP, "10%").bytes(); + final Type type = TYPE_SETTING .get(settings); + final long limit = LIMIT_HEAP_SETTING .get(settings).bytes(); final int availableProcessors = EsExecutors.boundedNumberOfProcessors(settings); final int searchThreadPoolSize = maximumSearchThreadPoolSize(threadPool, settings); @@ -91,11 +97,10 @@ public class PageCacheRecycler extends AbstractComponent implements Releasable { // to direct ByteBuffers or sun.misc.Unsafe on a byte[] but this would have other issues // that would need to be addressed such as garbage collection of native memory or safety // of Unsafe writes. - final double bytesWeight = settings.getAsDouble(WEIGHT + ".bytes", 1d); - final double intsWeight = settings.getAsDouble(WEIGHT + ".ints", 1d); - final double longsWeight = settings.getAsDouble(WEIGHT + ".longs", 1d); - // object pages are less useful to us so we give them a lower weight by default - final double objectsWeight = settings.getAsDouble(WEIGHT + ".objects", 0.1d); + final double bytesWeight = WEIGHT_BYTES_SETTING .get(settings); + final double intsWeight = WEIGHT_INT_SETTING .get(settings); + final double longsWeight = WEIGHT_LONG_SETTING .get(settings); + final double objectsWeight = WEIGHT_OBJECTS_SETTING .get(settings); final double totalWeight = bytesWeight + intsWeight + longsWeight + objectsWeight; final int maxPageCount = (int) Math.min(Integer.MAX_VALUE, limit / BigArrays.PAGE_SIZE_IN_BYTES); @@ -190,7 +195,7 @@ public class PageCacheRecycler extends AbstractComponent implements Releasable { return recycler; } - public static enum Type { + public enum Type { QUEUE { @Override Recycler build(Recycler.C c, int limit, int estimatedThreadPoolSize, int availableProcessors) { @@ -211,9 +216,6 @@ public class PageCacheRecycler extends AbstractComponent implements Releasable { }; public static Type parse(String type) { - if (Strings.isNullOrEmpty(type)) { - return CONCURRENT; - } try { return Type.valueOf(type.toUpperCase(Locale.ROOT)); } catch (IllegalArgumentException e) { diff --git a/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java b/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java index 593d586ba96..aa576c8f462 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java @@ -22,6 +22,7 @@ import org.elasticsearch.action.admin.indices.close.TransportCloseIndexAction; import org.elasticsearch.action.support.AutoCreateIndex; import org.elasticsearch.action.support.DestructiveOperations; import org.elasticsearch.action.support.master.TransportMasterNodeReadAction; +import org.elasticsearch.cache.recycler.PageCacheRecycler; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClientNodesService; import org.elasticsearch.cluster.ClusterModule; @@ -346,6 +347,12 @@ public final class ClusterSettings extends AbstractScopedSettings { FsService.REFRESH_INTERVAL_SETTING, JvmGcMonitorService.ENABLED_SETTING, JvmGcMonitorService.REFRESH_INTERVAL_SETTING, - JvmGcMonitorService.GC_SETTING + JvmGcMonitorService.GC_SETTING, + PageCacheRecycler.LIMIT_HEAP_SETTING, + PageCacheRecycler.WEIGHT_BYTES_SETTING, + PageCacheRecycler.WEIGHT_INT_SETTING, + PageCacheRecycler.WEIGHT_LONG_SETTING, + PageCacheRecycler.WEIGHT_OBJECTS_SETTING, + PageCacheRecycler.TYPE_SETTING ))); }