ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject [1/2] ambari git commit: AMBARI-12859. AMS cache could result in OOM in ambari server. (swagle)
Date Tue, 25 Aug 2015 20:41:11 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 153ecfa56 -> e60dbb4e0


http://git-wip-us.apache.org/repos/asf/ambari/blob/e60dbb4e/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineMetricCacheProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineMetricCacheProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineMetricCacheProvider.java
index 8df957e..6d80687 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineMetricCacheProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineMetricCacheProvider.java
@@ -22,11 +22,15 @@ import com.google.inject.Singleton;
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.CacheManager;
 import net.sf.ehcache.config.CacheConfiguration;
+import net.sf.ehcache.config.PersistenceConfiguration;
 import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
 import org.apache.ambari.server.configuration.Configuration;
+import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static net.sf.ehcache.config.PersistenceConfiguration.*;
+
 /**
  * Cache implementation that provides ability to perform incremental reads
  * from Metrics backend and reduce the amount of calls between Ambari and the
@@ -56,26 +60,35 @@ public class TimelineMetricCacheProvider {
       return;
     }
 
-    //Create a singleton CacheManager using defaults
     System.setProperty("net.sf.ehcache.skipUpdateCheck", "true");
-    CacheManager manager = CacheManager.getInstance();
+    net.sf.ehcache.config.Configuration managerConfig =
+      new net.sf.ehcache.config.Configuration();
+
+    // Set max heap available to the cache manager
+    managerConfig.setMaxBytesLocalHeap(configuration.getMetricsCacheManagerHeapPercent());
+
+    //Create a singleton CacheManager using defaults
+    CacheManager manager = CacheManager.create(managerConfig);
 
     LOG.info("Creating Metrics Cache with timeouts => ttl = " +
       configuration.getMetricCacheTTLSeconds() + ", idle = " +
       configuration.getMetricCacheIdleSeconds());
 
+    PersistenceConfiguration persistenceConfiguration = new PersistenceConfiguration();
+    persistenceConfiguration.setStrategy(Strategy.NONE.name());
+
     //Create a Cache specifying its configuration.
-    Cache cache = new Cache(
-      new CacheConfiguration(TIMELINE_METRIC_CACHE_INSTANCE_NAME, configuration.getMetricCacheMaxEntries())
+    CacheConfiguration cacheConfiguration = new CacheConfiguration()
+        .name(TIMELINE_METRIC_CACHE_INSTANCE_NAME)
         .timeToLiveSeconds(configuration.getMetricCacheTTLSeconds()) // 1 hour
         .timeToIdleSeconds(configuration.getMetricCacheIdleSeconds()) // 5 minutes
         .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU)
         .eternal(false)
-        .diskPersistent(false)
-        .overflowToDisk(false)
-        .statistics(LOG.isDebugEnabled() || LOG.isTraceEnabled())
-    );
+        .persistence(persistenceConfiguration);
+
+    Cache cache = new Cache(cacheConfiguration);
 
+    // Decorate with UpdatingSelfPopulatingCache
     timelineMetricsCache = new TimelineMetricCache(cache, cacheEntryFactory);
 
     LOG.info("Registering metrics cache with provider: name = " +

http://git-wip-us.apache.org/repos/asf/ambari/blob/e60dbb4e/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/templates/hadoop-metrics2-hbase.properties.j2
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/templates/hadoop-metrics2-hbase.properties.j2
b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/templates/hadoop-metrics2-hbase.properties.j2
index 5a4dd16..3f404eb 100644
--- a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/templates/hadoop-metrics2-hbase.properties.j2
+++ b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/templates/hadoop-metrics2-hbase.properties.j2
@@ -39,21 +39,21 @@
 hbase.extendedperiod = 3600
 
 hbase.class=org.apache.hadoop.metrics2.sink.timeline.HadoopTimelineMetricsSink
-hbase.period=10
+hbase.period=30
 hbase.collector={{ams_collector_host_single}}:{{metric_collector_port}}
 
 jvm.class=org.apache.hadoop.metrics2.sink.timeline.HadoopTimelineMetricsSink
-jvm.period=10
+jvm.period=30
 jvm.collector={{ams_collector_host_single}}:{{metric_collector_port}}
 
 rpc.class=org.apache.hadoop.metrics2.sink.timeline.HadoopTimelineMetricsSink
-rpc.period=10
+rpc.period=30
 rpc.collector={{ams_collector_host_single}}:{{metric_collector_port}}
 
 *.timeline.plugin.urls=file:///usr/lib/ambari-metrics-hadoop-sink/ambari-metrics-hadoop-sink.jar
 *.sink.timeline.slave.host.name={{hostname}}
 hbase.sink.timeline.class=org.apache.hadoop.metrics2.sink.timeline.HadoopTimelineMetricsSink
-hbase.sink.timeline.period=10
+hbase.sink.timeline.period=60
 hbase.sink.timeline.collector={{ams_collector_host_single}}:{{metric_collector_port}}
 hbase.sink.timeline.serviceName-prefix=ams
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/e60dbb4e/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineMetricCacheTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineMetricCacheTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineMetricCacheTest.java
index b16024b..3432e1d 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineMetricCacheTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineMetricCacheTest.java
@@ -102,8 +102,13 @@ public class TimelineMetricCacheTest {
 
     replay(cacheEntryFactory);
 
-    CacheManager manager = CacheManager.getInstance();
-    Cache cache = new Cache("test", 10, false, false, 10000, 10000);
+    // Need to set this due what seems like a bug in Ehcache 2.10.0, setting
+    // it on the second cache instance results in a assertion error.
+    // Since this is not out production use case, setting it here as well.
+    net.sf.ehcache.config.Configuration managerConfig = new net.sf.ehcache.config.Configuration();
+    managerConfig.setMaxBytesLocalHeap("10%");
+    CacheManager manager = CacheManager.create(managerConfig);
+    Cache cache = new Cache("test", 0, false, false, 10000, 10000);
     UpdatingSelfPopulatingCache testCache = new UpdatingSelfPopulatingCache(cache, cacheEntryFactory);
     manager.addCache(testCache);
 
@@ -116,9 +121,11 @@ public class TimelineMetricCacheTest {
   @Test
   public void testTimlineMetricCacheProviderGets() throws Exception {
     Configuration configuration = createNiceMock(Configuration.class);
-    expect(configuration.getMetricCacheMaxEntries()).andReturn(1000);
     expect(configuration.getMetricCacheTTLSeconds()).andReturn(3600);
     expect(configuration.getMetricCacheIdleSeconds()).andReturn(100);
+    expect(configuration.getMetricsCacheManagerHeapPercent()).andReturn("10%");
+
+    replay(configuration);
 
     final long now = System.currentTimeMillis();
     Map<String, TimelineMetric> valueMap = new HashMap<String, TimelineMetric>();
@@ -150,7 +157,7 @@ public class TimelineMetricCacheTest {
     cacheEntryFactory.updateEntryValue(testKey, value);
     expectLastCall().once();
 
-    replay(configuration, cacheEntryFactory);
+    replay(cacheEntryFactory);
 
     TimelineMetricCacheProvider cacheProvider = getMetricCacheProvider(configuration, cacheEntryFactory);
     TimelineMetricCache cache = cacheProvider.getTimelineMetricsCache();


Mime
View raw message