Пример #1
0
 /// <summary>Process resource update on a node.</summary>
 public virtual void UpdateNodeResource(RMNode nm, ResourceOption resourceOption)
 {
     lock (this)
     {
         SchedulerNode node = GetSchedulerNode(nm.GetNodeID());
         Org.Apache.Hadoop.Yarn.Api.Records.Resource newResource = resourceOption.GetResource
                                                                       ();
         Org.Apache.Hadoop.Yarn.Api.Records.Resource oldResource = node.GetTotalResource();
         if (!oldResource.Equals(newResource))
         {
             // Log resource change
             Log.Info("Update resource on node: " + node.GetNodeName() + " from: " + oldResource
                      + ", to: " + newResource);
             Sharpen.Collections.Remove(nodes, nm.GetNodeID());
             UpdateMaximumAllocation(node, false);
             // update resource to node
             node.SetTotalResource(newResource);
             nodes[nm.GetNodeID()] = (N)node;
             UpdateMaximumAllocation(node, true);
             // update resource to clusterResource
             Resources.SubtractFrom(clusterResource, oldResource);
             Resources.AddTo(clusterResource, newResource);
         }
         else
         {
             // Log resource change
             Log.Warn("Update resource on node: " + node.GetNodeName() + " with the same resource: "
                      + newResource);
         }
     }
 }
Пример #2
0
        public virtual void TestUpdateMaxAllocationUsesTotal()
        {
            int configuredMaxVCores = 20;
            int configuredMaxMemory = 10 * 1024;

            Org.Apache.Hadoop.Yarn.Api.Records.Resource configuredMaximumResource = Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                                    .NewInstance(configuredMaxMemory, configuredMaxVCores);
            ConfigureScheduler();
            YarnConfiguration conf = GetConf();

            conf.SetInt(YarnConfiguration.RmSchedulerMaximumAllocationVcores, configuredMaxVCores
                        );
            conf.SetInt(YarnConfiguration.RmSchedulerMaximumAllocationMb, configuredMaxMemory
                        );
            conf.SetLong(YarnConfiguration.RmWorkPreservingRecoverySchedulingWaitMs, 0);
            MockRM rm = new MockRM(conf);

            try
            {
                rm.Start();
                AbstractYarnScheduler scheduler = (AbstractYarnScheduler)rm.GetResourceScheduler(
                    );
                Org.Apache.Hadoop.Yarn.Api.Records.Resource emptyResource = Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                            .NewInstance(0, 0);
                Org.Apache.Hadoop.Yarn.Api.Records.Resource fullResource1 = Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                            .NewInstance(1024, 5);
                Org.Apache.Hadoop.Yarn.Api.Records.Resource fullResource2 = Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                            .NewInstance(2048, 10);
                SchedulerNode mockNode1 = Org.Mockito.Mockito.Mock <SchedulerNode>();
                Org.Mockito.Mockito.When(mockNode1.GetNodeID()).ThenReturn(NodeId.NewInstance("foo"
                                                                                              , 8080));
                Org.Mockito.Mockito.When(mockNode1.GetAvailableResource()).ThenReturn(emptyResource
                                                                                      );
                Org.Mockito.Mockito.When(mockNode1.GetTotalResource()).ThenReturn(fullResource1);
                SchedulerNode mockNode2 = Org.Mockito.Mockito.Mock <SchedulerNode>();
                Org.Mockito.Mockito.When(mockNode1.GetNodeID()).ThenReturn(NodeId.NewInstance("bar"
                                                                                              , 8081));
                Org.Mockito.Mockito.When(mockNode2.GetAvailableResource()).ThenReturn(emptyResource
                                                                                      );
                Org.Mockito.Mockito.When(mockNode2.GetTotalResource()).ThenReturn(fullResource2);
                VerifyMaximumResourceCapability(configuredMaximumResource, scheduler);
                scheduler.nodes = new Dictionary <NodeId, SchedulerNode>();
                scheduler.nodes[mockNode1.GetNodeID()] = mockNode1;
                scheduler.UpdateMaximumAllocation(mockNode1, true);
                VerifyMaximumResourceCapability(fullResource1, scheduler);
                scheduler.nodes[mockNode2.GetNodeID()] = mockNode2;
                scheduler.UpdateMaximumAllocation(mockNode2, true);
                VerifyMaximumResourceCapability(fullResource2, scheduler);
                Sharpen.Collections.Remove(scheduler.nodes, mockNode2.GetNodeID());
                scheduler.UpdateMaximumAllocation(mockNode2, false);
                VerifyMaximumResourceCapability(fullResource1, scheduler);
                Sharpen.Collections.Remove(scheduler.nodes, mockNode1.GetNodeID());
                scheduler.UpdateMaximumAllocation(mockNode1, false);
                VerifyMaximumResourceCapability(configuredMaximumResource, scheduler);
            }
            finally
            {
                rm.Stop();
            }
        }
Пример #3
0
 protected internal virtual void UpdateMaximumAllocation(SchedulerNode node, bool
                                                         add)
 {
     Org.Apache.Hadoop.Yarn.Api.Records.Resource totalResource = node.GetTotalResource
                                                                     ();
     maxAllocWriteLock.Lock();
     try
     {
         if (add)
         {
             // added node
             int nodeMemory = totalResource.GetMemory();
             if (nodeMemory > maxNodeMemory)
             {
                 maxNodeMemory = nodeMemory;
                 maximumAllocation.SetMemory(Math.Min(configuredMaximumAllocation.GetMemory(), maxNodeMemory
                                                      ));
             }
             int nodeVCores = totalResource.GetVirtualCores();
             if (nodeVCores > maxNodeVCores)
             {
                 maxNodeVCores = nodeVCores;
                 maximumAllocation.SetVirtualCores(Math.Min(configuredMaximumAllocation.GetVirtualCores
                                                                (), maxNodeVCores));
             }
         }
         else
         {
             // removed node
             if (maxNodeMemory == totalResource.GetMemory())
             {
                 maxNodeMemory = -1;
             }
             if (maxNodeVCores == totalResource.GetVirtualCores())
             {
                 maxNodeVCores = -1;
             }
             // We only have to iterate through the nodes if the current max memory
             // or vcores was equal to the removed node's
             if (maxNodeMemory == -1 || maxNodeVCores == -1)
             {
                 foreach (KeyValuePair <NodeId, N> nodeEntry in nodes)
                 {
                     int nodeMemory = nodeEntry.Value.GetTotalResource().GetMemory();
                     if (nodeMemory > maxNodeMemory)
                     {
                         maxNodeMemory = nodeMemory;
                     }
                     int nodeVCores = nodeEntry.Value.GetTotalResource().GetVirtualCores();
                     if (nodeVCores > maxNodeVCores)
                     {
                         maxNodeVCores = nodeVCores;
                     }
                 }
                 if (maxNodeMemory == -1)
                 {
                     // no nodes
                     maximumAllocation.SetMemory(configuredMaximumAllocation.GetMemory());
                 }
                 else
                 {
                     maximumAllocation.SetMemory(Math.Min(configuredMaximumAllocation.GetMemory(), maxNodeMemory
                                                          ));
                 }
                 if (maxNodeVCores == -1)
                 {
                     // no nodes
                     maximumAllocation.SetVirtualCores(configuredMaximumAllocation.GetVirtualCores());
                 }
                 else
                 {
                     maximumAllocation.SetVirtualCores(Math.Min(configuredMaximumAllocation.GetVirtualCores
                                                                    (), maxNodeVCores));
                 }
             }
         }
     }
     finally
     {
         maxAllocWriteLock.Unlock();
     }
 }