Esempio n. 1
0
        public virtual void TestMaxOutHedgedReadPool()
        {
            isHedgedRead = true;
            Configuration conf = new Configuration();
            int           numHedgedReadPoolThreads       = 5;
            int           initialHedgedReadTimeoutMillis = 50000;
            int           fixedSleepIntervalMillis       = 50;

            conf.SetInt(DFSConfigKeys.DfsDfsclientHedgedReadThreadpoolSize, numHedgedReadPoolThreads
                        );
            conf.SetLong(DFSConfigKeys.DfsDfsclientHedgedReadThresholdMillis, initialHedgedReadTimeoutMillis
                         );
            // Set up the InjectionHandler
            DFSClientFaultInjector.instance = Org.Mockito.Mockito.Mock <DFSClientFaultInjector
                                                                        >();
            DFSClientFaultInjector injector = DFSClientFaultInjector.instance;

            // make preads sleep for 50ms
            Org.Mockito.Mockito.DoAnswer(new _Answer_372(fixedSleepIntervalMillis)).When(injector
                                                                                         ).StartFetchFromDatanode();
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(3).Format(
                true).Build();
            DistributedFileSystem fileSys   = cluster.GetFileSystem();
            DFSClient             dfsClient = fileSys.GetClient();
            DFSHedgedReadMetrics  metrics   = dfsClient.GetHedgedReadMetrics();

            // Metrics instance is static, so we need to reset counts from prior tests.
            metrics.hedgedReadOps.Set(0);
            metrics.hedgedReadOpsWin.Set(0);
            metrics.hedgedReadOpsInCurThread.Set(0);
            try
            {
                Path file1 = new Path("hedgedReadMaxOut.dat");
                WriteFile(fileSys, file1);
                // Basic test. Reads complete within timeout. Assert that there were no
                // hedged reads.
                PReadFile(fileSys, file1);
                // assert that there were no hedged reads. 50ms + delta < 500ms
                NUnit.Framework.Assert.IsTrue(metrics.GetHedgedReadOps() == 0);
                NUnit.Framework.Assert.IsTrue(metrics.GetHedgedReadOpsInCurThread() == 0);

                /*
                 * Reads take longer than timeout. But, only one thread reading. Assert
                 * that there were hedged reads. But, none of the reads had to run in the
                 * current thread.
                 */
                dfsClient.SetHedgedReadTimeout(50);
                // 50ms
                PReadFile(fileSys, file1);
                // assert that there were hedged reads
                NUnit.Framework.Assert.IsTrue(metrics.GetHedgedReadOps() > 0);
                NUnit.Framework.Assert.IsTrue(metrics.GetHedgedReadOpsInCurThread() == 0);

                /*
                 * Multiple threads reading. Reads take longer than timeout. Assert that
                 * there were hedged reads. And that reads had to run in the current
                 * thread.
                 */
                int                    factor              = 10;
                int                    numHedgedReads      = numHedgedReadPoolThreads * factor;
                long                   initialReadOpsValue = metrics.GetHedgedReadOps();
                ExecutorService        executor            = Executors.NewFixedThreadPool(numHedgedReads);
                AList <Future <Void> > futures             = new AList <Future <Void> >();
                for (int i = 0; i < numHedgedReads; i++)
                {
                    futures.AddItem(executor.Submit(GetPReadFileCallable(fileSys, file1)));
                }
                for (int i_1 = 0; i_1 < numHedgedReads; i_1++)
                {
                    futures[i_1].Get();
                }
                NUnit.Framework.Assert.IsTrue(metrics.GetHedgedReadOps() > initialReadOpsValue);
                NUnit.Framework.Assert.IsTrue(metrics.GetHedgedReadOpsInCurThread() > 0);
                CleanupFile(fileSys, file1);
                executor.Shutdown();
            }
            finally
            {
                fileSys.Close();
                cluster.Shutdown();
                Org.Mockito.Mockito.Reset(injector);
            }
        }