From 108db38788cad4d53f71a62e0603359f0a218695 Mon Sep 17 00:00:00 2001 From: Karthik Kambatla Date: Tue, 24 May 2016 10:54:11 -0700 Subject: [PATCH] YARN-4878. Expose scheduling policy and max running apps over JMX for Yarn queues. (Yufei Gu via kasha) (cherry picked from commit f979d779e192ac05906b7eb880dfc8884d0078a0) --- .../scheduler/fair/FSQueue.java | 4 +++ .../scheduler/fair/FSQueueMetrics.java | 25 ++++++++++++++++--- .../scheduler/fair/QueueManager.java | 5 +++- .../scheduler/fair/TestFSLeafQueue.java | 12 +++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSQueue.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSQueue.java index a33084f80c9..4e6b99d1961 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSQueue.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSQueue.java @@ -70,6 +70,10 @@ public abstract class FSQueue implements Queue, Schedulable { this.metrics = FSQueueMetrics.forQueue(getName(), parent, true, scheduler.getConf()); metrics.setMinShare(getMinShare()); metrics.setMaxShare(getMaxShare()); + + AllocationConfiguration allocConf = scheduler.getAllocationConfiguration(); + metrics.setMaxApps(allocConf.getQueueMaxApps(name)); + metrics.setSchedulingPolicy(allocConf.getSchedulingPolicy(name).getName()); this.parent = parent; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSQueueMetrics.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSQueueMetrics.java index 82c422b8207..109cce578ea 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSQueueMetrics.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSQueueMetrics.java @@ -39,7 +39,10 @@ public class FSQueueMetrics extends QueueMetrics { @Metric("Minimum share of CPU in vcores") MutableGaugeInt minShareVCores; @Metric("Maximum share of memory in MB") MutableGaugeInt maxShareMB; @Metric("Maximum share of CPU in vcores") MutableGaugeInt maxShareVCores; - + @Metric("Maximum number of applications") MutableGaugeInt maxApps; + + private String schedulingPolicy; + FSQueueMetrics(MetricsSystem ms, String queueName, Queue parent, boolean enableUserMetrics, Configuration conf) { super(ms, queueName, parent, enableUserMetrics, conf); @@ -96,8 +99,24 @@ public class FSQueueMetrics extends QueueMetrics { public int getMaxShareVirtualCores() { return maxShareVCores.value(); } - - public synchronized + + public int getMaxApps() { + return maxApps.value(); + } + + public void setMaxApps(int max) { + maxApps.set(max); + } + + public String getSchedulingPolicy() { + return schedulingPolicy; + } + + public void setSchedulingPolicy(String policy) { + schedulingPolicy = policy; + } + + public synchronized static FSQueueMetrics forQueue(String queueName, Queue parent, boolean enableUserMetrics, Configuration conf) { MetricsSystem ms = DefaultMetricsSystem.instance(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/QueueManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/QueueManager.java index 51a298bc79a..aeadcf6b496 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/QueueManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/QueueManager.java @@ -430,11 +430,14 @@ public class QueueManager { FSQueueMetrics queueMetrics = queue.getMetrics(); queueMetrics.setMinShare(queue.getMinShare()); queueMetrics.setMaxShare(queue.getMaxShare()); - // Set scheduling policies + // Set scheduling policies and update queue metrics try { SchedulingPolicy policy = queueConf.getSchedulingPolicy(queue.getName()); policy.initialize(scheduler.getClusterResource()); queue.setPolicy(policy); + + queueMetrics.setMaxApps(queueConf.getQueueMaxApps(queue.getName())); + queueMetrics.setSchedulingPolicy(policy.getName()); } catch (AllocationConfigurationException ex) { LOG.warn("Cannot apply configured scheduling policy to queue " + queue.getName(), ex); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFSLeafQueue.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFSLeafQueue.java index 7daccad5655..867fd22a710 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFSLeafQueue.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFSLeafQueue.java @@ -86,7 +86,14 @@ public class TestFSLeafQueue extends FairSchedulerTestBase { String queueName = "root.queue1"; when(scheduler.allocConf.getMaxResources(queueName)).thenReturn(maxResource); when(scheduler.allocConf.getMinResources(queueName)).thenReturn(Resources.none()); + when(scheduler.allocConf.getQueueMaxApps(queueName)). + thenReturn(Integer.MAX_VALUE); + when(scheduler.allocConf.getSchedulingPolicy(queueName)) + .thenReturn(SchedulingPolicy.DEFAULT_POLICY); FSLeafQueue schedulable = new FSLeafQueue(queueName, scheduler, null); + assertEquals(schedulable.getMetrics().getMaxApps(), Integer.MAX_VALUE); + assertEquals(schedulable.getMetrics().getSchedulingPolicy(), + SchedulingPolicy.DEFAULT_POLICY.getName()); FSAppAttempt app = mock(FSAppAttempt.class); Mockito.when(app.getDemand()).thenReturn(maxResource); @@ -118,6 +125,11 @@ public class TestFSLeafQueue extends FairSchedulerTestBase { resourceManager = new MockRM(conf); resourceManager.start(); scheduler = (FairScheduler) resourceManager.getResourceScheduler(); + for(FSQueue queue: scheduler.getQueueManager().getQueues()) { + assertEquals(queue.getMetrics().getMaxApps(), Integer.MAX_VALUE); + assertEquals(queue.getMetrics().getSchedulingPolicy(), + SchedulingPolicy.DEFAULT_POLICY.getName()); + } // Add one big node (only care about aggregate capacity) RMNode node1 =