示例#1
0
        public virtual void TestInit()
        {
            LinuxContainerExecutor mockLCE = new TestCgroupsLCEResourcesHandler.MockLinuxContainerExecutor
                                                 ();

            TestCgroupsLCEResourcesHandler.CustomCgroupsLCEResourceHandler handler = new TestCgroupsLCEResourcesHandler.CustomCgroupsLCEResourceHandler
                                                                                         ();
            YarnConfiguration conf          = new YarnConfiguration();
            int numProcessors               = 4;
            ResourceCalculatorPlugin plugin = Org.Mockito.Mockito.Mock <ResourceCalculatorPlugin
                                                                        >();

            Org.Mockito.Mockito.DoReturn(numProcessors).When(plugin).GetNumProcessors();
            handler.SetConf(conf);
            handler.InitConfig();
            // create mock cgroup
            FilePath cgroupMountDir = CreateMockCgroupMount(cgroupDir);
            // create mock mtab
            FilePath mockMtab = CreateMockMTab(cgroupDir);

            // setup our handler and call init()
            handler.SetMtabFile(mockMtab.GetAbsolutePath());
            // check values
            // in this case, we're using all cpu so the files
            // shouldn't exist(because init won't create them
            handler.Init(mockLCE, plugin);
            FilePath periodFile = new FilePath(cgroupMountDir, "cpu.cfs_period_us");
            FilePath quotaFile  = new FilePath(cgroupMountDir, "cpu.cfs_quota_us");

            NUnit.Framework.Assert.IsFalse(periodFile.Exists());
            NUnit.Framework.Assert.IsFalse(quotaFile.Exists());
            // subset of cpu being used, files should be created
            conf.SetInt(YarnConfiguration.NmResourcePercentagePhysicalCpuLimit, 75);
            handler.limits[0] = 100 * 1000;
            handler.limits[1] = 1000 * 1000;
            handler.Init(mockLCE, plugin);
            int period = ReadIntFromFile(periodFile);
            int quota  = ReadIntFromFile(quotaFile);

            NUnit.Framework.Assert.AreEqual(100 * 1000, period);
            NUnit.Framework.Assert.AreEqual(1000 * 1000, quota);
            // set cpu back to 100, quota should be -1
            conf.SetInt(YarnConfiguration.NmResourcePercentagePhysicalCpuLimit, 100);
            handler.limits[0] = 100 * 1000;
            handler.limits[1] = 1000 * 1000;
            handler.Init(mockLCE, plugin);
            quota = ReadIntFromFile(quotaFile);
            NUnit.Framework.Assert.AreEqual(-1, quota);
            FileUtils.DeleteQuietly(cgroupDir);
        }
示例#2
0
        public virtual void TestContainerLimits()
        {
            LinuxContainerExecutor mockLCE = new TestCgroupsLCEResourcesHandler.MockLinuxContainerExecutor
                                                 ();

            TestCgroupsLCEResourcesHandler.CustomCgroupsLCEResourceHandler handler = new TestCgroupsLCEResourcesHandler.CustomCgroupsLCEResourceHandler
                                                                                         ();
            handler.generateLimitsMode = true;
            YarnConfiguration conf          = new YarnConfiguration();
            int numProcessors               = 4;
            ResourceCalculatorPlugin plugin = Org.Mockito.Mockito.Mock <ResourceCalculatorPlugin
                                                                        >();

            Org.Mockito.Mockito.DoReturn(numProcessors).When(plugin).GetNumProcessors();
            handler.SetConf(conf);
            handler.InitConfig();
            // create mock cgroup
            FilePath cgroupMountDir = CreateMockCgroupMount(cgroupDir);
            // create mock mtab
            FilePath mockMtab = CreateMockMTab(cgroupDir);

            // setup our handler and call init()
            handler.SetMtabFile(mockMtab.GetAbsolutePath());
            handler.Init(mockLCE, plugin);
            // check values
            // default case - files shouldn't exist, strict mode off by default
            ContainerId id = ContainerId.FromString("container_1_1_1_1");

            handler.PreExecute(id, Resource.NewInstance(1024, 1));
            FilePath containerDir = new FilePath(cgroupMountDir, id.ToString());

            NUnit.Framework.Assert.IsTrue(containerDir.Exists());
            NUnit.Framework.Assert.IsTrue(containerDir.IsDirectory());
            FilePath periodFile = new FilePath(containerDir, "cpu.cfs_period_us");
            FilePath quotaFile  = new FilePath(containerDir, "cpu.cfs_quota_us");

            NUnit.Framework.Assert.IsFalse(periodFile.Exists());
            NUnit.Framework.Assert.IsFalse(quotaFile.Exists());
            // no files created because we're using all cpu
            FileUtils.DeleteQuietly(containerDir);
            conf.SetBoolean(YarnConfiguration.NmLinuxContainerCgroupsStrictResourceUsage, true
                            );
            handler.InitConfig();
            handler.PreExecute(id, Resource.NewInstance(1024, YarnConfiguration.DefaultNmVcores
                                                        ));
            NUnit.Framework.Assert.IsTrue(containerDir.Exists());
            NUnit.Framework.Assert.IsTrue(containerDir.IsDirectory());
            periodFile = new FilePath(containerDir, "cpu.cfs_period_us");
            quotaFile  = new FilePath(containerDir, "cpu.cfs_quota_us");
            NUnit.Framework.Assert.IsFalse(periodFile.Exists());
            NUnit.Framework.Assert.IsFalse(quotaFile.Exists());
            // 50% of CPU
            FileUtils.DeleteQuietly(containerDir);
            conf.SetBoolean(YarnConfiguration.NmLinuxContainerCgroupsStrictResourceUsage, true
                            );
            handler.InitConfig();
            handler.PreExecute(id, Resource.NewInstance(1024, YarnConfiguration.DefaultNmVcores
                                                        / 2));
            NUnit.Framework.Assert.IsTrue(containerDir.Exists());
            NUnit.Framework.Assert.IsTrue(containerDir.IsDirectory());
            periodFile = new FilePath(containerDir, "cpu.cfs_period_us");
            quotaFile  = new FilePath(containerDir, "cpu.cfs_quota_us");
            NUnit.Framework.Assert.IsTrue(periodFile.Exists());
            NUnit.Framework.Assert.IsTrue(quotaFile.Exists());
            NUnit.Framework.Assert.AreEqual(500 * 1000, ReadIntFromFile(periodFile));
            NUnit.Framework.Assert.AreEqual(1000 * 1000, ReadIntFromFile(quotaFile));
            // CGroups set to 50% of CPU, container set to 50% of YARN CPU
            FileUtils.DeleteQuietly(containerDir);
            conf.SetBoolean(YarnConfiguration.NmLinuxContainerCgroupsStrictResourceUsage, true
                            );
            conf.SetInt(YarnConfiguration.NmResourcePercentagePhysicalCpuLimit, 50);
            handler.InitConfig();
            handler.Init(mockLCE, plugin);
            handler.PreExecute(id, Resource.NewInstance(1024, YarnConfiguration.DefaultNmVcores
                                                        / 2));
            NUnit.Framework.Assert.IsTrue(containerDir.Exists());
            NUnit.Framework.Assert.IsTrue(containerDir.IsDirectory());
            periodFile = new FilePath(containerDir, "cpu.cfs_period_us");
            quotaFile  = new FilePath(containerDir, "cpu.cfs_quota_us");
            NUnit.Framework.Assert.IsTrue(periodFile.Exists());
            NUnit.Framework.Assert.IsTrue(quotaFile.Exists());
            NUnit.Framework.Assert.AreEqual(1000 * 1000, ReadIntFromFile(periodFile));
            NUnit.Framework.Assert.AreEqual(1000 * 1000, ReadIntFromFile(quotaFile));
            FileUtils.DeleteQuietly(cgroupDir);
        }