public FsDatasetCache(FsDatasetImpl dataset) { this.dataset = dataset; this.maxBytes = dataset.datanode.GetDnConf().GetMaxLockedMemory(); ThreadFactory workerFactory = new ThreadFactoryBuilder().SetDaemon(true).SetNameFormat ("FsDatasetCache-%d-" + dataset.ToString()).Build(); this.usedBytesCount = new FsDatasetCache.UsedBytesCount(this); this.uncachingExecutor = new ThreadPoolExecutor(0, 1, 60, TimeUnit.Seconds, new LinkedBlockingQueue <Runnable>(), workerFactory); this.uncachingExecutor.AllowCoreThreadTimeOut(true); this.deferredUncachingExecutor = new ScheduledThreadPoolExecutor(1, workerFactory ); this.revocationMs = dataset.datanode.GetConf().GetLong(DFSConfigKeys.DfsDatanodeCacheRevocationTimeoutMs , DFSConfigKeys.DfsDatanodeCacheRevocationTimeoutMsDefault); long confRevocationPollingMs = dataset.datanode.GetConf().GetLong(DFSConfigKeys.DfsDatanodeCacheRevocationPollingMs , DFSConfigKeys.DfsDatanodeCacheRevocationPollingMsDefault); long minRevocationPollingMs = revocationMs / 2; if (minRevocationPollingMs < confRevocationPollingMs) { throw new RuntimeException("configured value " + confRevocationPollingMs + "for " + DFSConfigKeys.DfsDatanodeCacheRevocationPollingMs + " is too high. It must not be more than half of the " + "value of " + DFSConfigKeys.DfsDatanodeCacheRevocationTimeoutMs + ". Reconfigure this to " + minRevocationPollingMs); } this.revocationPollingMs = confRevocationPollingMs; }
/// <summary> /// Submit 101 objects to batcher, and make sure that batch /// of first 100 are processed "immediately" (as opposed to being /// subjected to a delay which would add latency) /// </summary> /// <exception cref="System.Exception"></exception> public virtual void TestBatcherLatencyInitialBatch() { CountDownLatch doneSignal = new CountDownLatch(1); ScheduledExecutorService workExecutor = new ScheduledThreadPoolExecutor(1); int inboxCapacity = 100; int processorDelay = 500; AtomicLong timeProcessed = new AtomicLong(); Batcher batcher = new Batcher <string>(workExecutor, inboxCapacity, processorDelay , new _BatchProcessor_34(timeProcessed, doneSignal)); AList <string> objectsToQueue = new AList <string>(); for (int i = 0; i < inboxCapacity + 1; i++) { objectsToQueue.AddItem(Sharpen.Extensions.ToString(i)); } long timeQueued = Runtime.CurrentTimeMillis(); batcher.QueueObjects(objectsToQueue); bool didNotTimeOut = doneSignal.Await(35, TimeUnit.Seconds); NUnit.Framework.Assert.IsTrue(didNotTimeOut); long delta = timeProcessed.Get() - timeQueued; NUnit.Framework.Assert.IsTrue(delta > 0); // we want the delta between the time it was queued until the // time it was processed to be as small as possible. since // there is some overhead, rather than using a hardcoded number // express it as a ratio of the processor delay, asserting // that the entire processor delay never kicked in. int acceptableDelta = processorDelay - 1; Log.V(Log.Tag, "delta: %d", delta); NUnit.Framework.Assert.IsTrue(delta < acceptableDelta); }
public void ShutdownNoContinueExisting() { ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor(5, Executors.DefaultThreadFactory()); e.SetExecuteExistingDelayedTasksAfterShutdownPolicy(false); bool run = false; e.Schedule(new RunnableAction(delegate { run = true; }), 100, TimeUnit.MILLISECONDS); Thread.Sleep(50); e.Shutdown(); Assert.IsTrue(e.IsShutdown()); Assert.IsTrue(e.IsTerminated(), "Terminated"); Assert.IsFalse(e.IsTerminating(), "Terminating"); Thread.Sleep(100); Assert.IsFalse(run); Assert.IsTrue(e.IsTerminated(), "Terminated"); Assert.IsFalse(e.IsTerminating(), "Terminating"); }
public void InsertDelayedTask () { ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor (5, Executors.DefaultThreadFactory ()); double t1 = 0; double t2 = 0; DateTime tim1 = DateTime.Now; e.Schedule (new RunnableAction (delegate { t1 = (DateTime.Now - tim1).TotalMilliseconds; }),100, TimeUnit.MILLISECONDS); Thread.Sleep (20); DateTime tim2 = DateTime.Now; e.Schedule (new RunnableAction (delegate { t2 = (DateTime.Now - tim2).TotalMilliseconds; }),50, TimeUnit.MILLISECONDS); Thread.Sleep (150); Assert.IsTrue (t2 >= 50, "Elapsed: " + t2); Assert.IsTrue (t2 < 50 + delayDif, "Elapsed: " + t2); Assert.IsTrue (t1 >= 100, "Elapsed: " + t1); Assert.IsTrue (t1 < 100 + delayDif, "Elapsed: " + t1); e.ShutdownNow (); }
/// <summary> /// Run a set of threads making changes to the deprecations /// concurrently with another set of threads calling get() /// and set() on Configuration objects. /// </summary> /// <exception cref="System.Exception"/> public virtual void TestConcurrentDeprecateAndManipulate() { int NumThreadIds = 10; int NumKeysPerThread = 1000; ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(2 * NumThreadIds , new ThreadFactoryBuilder().SetDaemon(true).SetNameFormat("testConcurrentDeprecateAndManipulate modification thread %d" ).Build()); CountDownLatch latch = new CountDownLatch(1); AtomicInteger highestModificationThreadId = new AtomicInteger(1); IList <Future <Void> > futures = new List <Future <Void> >(); for (int i = 0; i < NumThreadIds; i++) { futures.AddItem(executor.Schedule(new _Callable_363(latch, highestModificationThreadId , NumKeysPerThread), 0, TimeUnit.Seconds)); } AtomicInteger highestAccessThreadId = new AtomicInteger(1); for (int i_1 = 0; i_1 < NumThreadIds; i_1++) { futures.AddItem(executor.Schedule(new _Callable_382(latch, highestAccessThreadId, NumKeysPerThread), 0, TimeUnit.Seconds)); } latch.CountDown(); // allow all threads to proceed foreach (Future <Void> future in futures) { Uninterruptibles.GetUninterruptibly(future); } }
public void ShutdownNow() { ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor(5, Executors.DefaultThreadFactory()); bool run = false; e.Schedule(new RunnableAction(delegate { run = true; }), 100, TimeUnit.MILLISECONDS); Thread.Sleep(50); var pending = e.ShutdownNow(); Assert.AreEqual(0, pending.Count); Assert.IsTrue(e.IsShutdown()); Assert.IsTrue(e.IsTerminated(), "Terminated"); Assert.IsFalse(e.IsTerminating(), "Terminating"); Thread.Sleep(100); Assert.IsFalse(run); Assert.IsTrue(e.IsTerminated(), "Terminated"); Assert.IsFalse(e.IsTerminating(), "Terminating"); }
public void InsertDelayedTask() { ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor(5, Executors.DefaultThreadFactory()); double t1 = 0; double t2 = 0; DateTime tim1 = DateTime.Now; e.Schedule(new RunnableAction(delegate { t1 = (DateTime.Now - tim1).TotalMilliseconds; }), 100, TimeUnit.MILLISECONDS); Thread.Sleep(20); DateTime tim2 = DateTime.Now; e.Schedule(new RunnableAction(delegate { t2 = (DateTime.Now - tim2).TotalMilliseconds; }), 50, TimeUnit.MILLISECONDS); Thread.Sleep(150); Assert.IsTrue(t2 >= 50, "Elapsed: " + t2); Assert.IsTrue(t2 < 50 + delayDif, "Elapsed: " + t2); Assert.IsTrue(t1 >= 100, "Elapsed: " + t1); Assert.IsTrue(t1 < 100 + delayDif, "Elapsed: " + t1); e.ShutdownNow(); }
/// <summary> /// Set batch processing delay to 500 ms, and every second, add a new item /// to the batcher queue. /// </summary> /// <remarks> /// Set batch processing delay to 500 ms, and every second, add a new item /// to the batcher queue. Make sure that each item is processed immediately. /// </remarks> /// <exception cref="System.Exception"></exception> public virtual void TestBatcherLatencyTrickleIn() { CountDownLatch doneSignal = new CountDownLatch(10); ScheduledExecutorService workExecutor = new ScheduledThreadPoolExecutor(1); int inboxCapacity = 100; int processorDelay = 500; AtomicLong maxObservedDelta = new AtomicLong(-1); Batcher batcher = new Batcher <long>(workExecutor, inboxCapacity, processorDelay, new _BatchProcessor_91(maxObservedDelta, doneSignal)); AList <long> objectsToQueue = new AList <long>(); for (int i = 0; i < 10; i++) { batcher.QueueObjects(Arrays.AsList(Runtime.CurrentTimeMillis())); Sharpen.Thread.Sleep(1000); } bool didNotTimeOut = doneSignal.Await(35, TimeUnit.Seconds); NUnit.Framework.Assert.IsTrue(didNotTimeOut); Log.V(Log.Tag, "maxDelta: %d", maxObservedDelta.Get()); // we want the max observed delta between the time it was queued until the // time it was processed to be as small as possible. since // there is some overhead, rather than using a hardcoded number // express it as a ratio of 1/4th the processor delay, asserting // that the entire processor delay never kicked in. int acceptableMaxDelta = processorDelay - 1; Log.V(Log.Tag, "maxObservedDelta: %d", maxObservedDelta.Get()); NUnit.Framework.Assert.IsTrue((maxObservedDelta.Get() < acceptableMaxDelta)); }
protected override void OnResume() { base.OnResume(); new Task(() => DoUpdateTicker(true)).Start(); updater = new ScheduledThreadPoolExecutor(1); updater.ScheduleAtFixedRate(() => DoUpdateTicker(false), 15, 15, TimeUnit.SECONDS); }
/// <exception cref="System.Exception"/> protected override void ServiceInit(Configuration conf) { // Default 3 hours. this.deleteDelaySeconds = conf.GetLong(YarnConfiguration.NmLogRetainSeconds, YarnConfiguration .DefaultNmLogRetainSeconds); sched = CreateScheduledThreadPoolExecutor(conf); base.ServiceInit(conf); Recover(); }
// Ignore internal virtual ScheduledThreadPoolExecutor CreateScheduledThreadPoolExecutor(Configuration conf) { ThreadFactory tf = new ThreadFactoryBuilder().SetNameFormat("LogDeleter #%d").Build (); sched = new ScheduledThreadPoolExecutor(conf.GetInt(YarnConfiguration.NmLogDeletionThreadsCount , YarnConfiguration.DefaultNmLogDeleteThreadCount), tf); return(sched); }
public virtual void TestShutdownThreadPool() { ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1); executor.Execute(sampleRunnable); bool ret = ShutdownThreadsHelper.ShutdownExecutorService(executor); bool isTerminated = executor.IsTerminated(); Assert.Equal("Incorrect return value", ret, isTerminated); Assert.True("ExecutorService is not shutdown", isTerminated); }
public override void startup() { base.startup(); /* initial delay to execute schedule task, unit: ms */ long initialDelay = ConfigManager.conn_monitor_initial_delay(); /* period of schedule task, unit: ms*/ long period = ConfigManager.conn_monitor_period(); executor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("ConnectionMonitorThread", true), new ThreadPoolExecutor.AbortPolicy()); executor.scheduleAtFixedRate(new TempRunnable(this), initialDelay, period, TimeUnit.MILLISECONDS); }
public void DelayedTask () { ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor (5, Executors.DefaultThreadFactory ()); DateTime tim = DateTime.Now; var future = e.Schedule (new RunnableAction (delegate { Console.WriteLine ("t1"); }),50, TimeUnit.MILLISECONDS); future.Get (); double elapsed = (DateTime.Now - tim).TotalMilliseconds; Assert.IsTrue (elapsed >= 50, "Elapsed: " + elapsed); Assert.IsTrue (elapsed < 60 + delayDif, "Elapsed: " + elapsed); e.ShutdownNow (); }
/// <exception cref="System.Exception"/> protected override void ServiceStart() { hsManager.Start(); if (storage is Org.Apache.Hadoop.Service.Service) { ((Org.Apache.Hadoop.Service.Service)storage).Start(); } scheduledExecutor = new ScheduledThreadPoolExecutor(2, new ThreadFactoryBuilder() .SetNameFormat("Log Scanner/Cleaner #%d").Build()); scheduledExecutor.ScheduleAtFixedRate(new JobHistory.MoveIntermediateToDoneRunnable (this), moveThreadInterval, moveThreadInterval, TimeUnit.Milliseconds); // Start historyCleaner ScheduleHistoryCleaner(); base.ServiceStart(); }
public void DelayedTask() { ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor(5, Executors.DefaultThreadFactory()); DateTime tim = DateTime.Now; var future = e.Schedule(new RunnableAction(delegate { Console.WriteLine("t1"); }), 50, TimeUnit.MILLISECONDS); future.Get(); double elapsed = (DateTime.Now - tim).TotalMilliseconds; Assert.IsTrue(elapsed >= 50, "Elapsed: " + elapsed); Assert.IsTrue(elapsed < 60 + delayDif, "Elapsed: " + elapsed); e.ShutdownNow(); }
static BatchingProgressMonitor() { // To support garbage collection, start our thread but // swap out the thread factory. When our class is GC'd // the alarmQueueKiller will finalize and ask the executor // to shutdown, ending the worker. // int threads = 1; alarmQueue = new ScheduledThreadPoolExecutor(threads, new _ThreadFactory_66()); alarmQueue.SetContinueExistingPeriodicTasksAfterShutdownPolicy(false); alarmQueue.SetExecuteExistingDelayedTasksAfterShutdownPolicy(false); alarmQueue.PrestartAllCoreThreads(); // Now that the threads are running, its critical to swap out // our own thread factory for one that isn't in the ClassLoader. // This allows the class to GC. // alarmQueue.SetThreadFactory(Executors.DefaultThreadFactory()); alarmQueueKiller = new _object_87(); }
/// <exception cref="System.Exception"></exception> public virtual void TestBatcherSingleBatch() { CountDownLatch doneSignal = new CountDownLatch(10); ScheduledExecutorService workExecutor = new ScheduledThreadPoolExecutor(1); int inboxCapacity = 10; int processorDelay = 1000; Batcher batcher = new Batcher <string>(workExecutor, inboxCapacity, processorDelay , new _BatchProcessor_146(doneSignal)); // add this to make it a bit more realistic AList <string> objectsToQueue = new AList <string>(); for (int i = 0; i < inboxCapacity * 10; i++) { objectsToQueue.AddItem(Sharpen.Extensions.ToString(i)); } batcher.QueueObjects(objectsToQueue); bool didNotTimeOut = doneSignal.Await(35, TimeUnit.Seconds); NUnit.Framework.Assert.IsTrue(didNotTimeOut); }
public void TestRateThreaded() { var config = new Configuration(); config.AddEventType<SupportBean>(); epService = EPServiceProviderManager.GetDefaultProvider(config); epService.Initialize(); var runnable = new RateSendRunnable(epService.EPRuntime); var timer = new ScheduledThreadPoolExecutor(1); //string viewExpr = "select RATE(LongPrimitive) as myrate from SupportBean#time(10) output every 1 sec"; var viewExpr = "select RATE(10) as myrate from SupportBean output snapshot every 1 sec"; var stmt = epService.EPAdministrator.CreateEPL(viewExpr); stmt.Events += (sender, args) => Log.Info(newEvents[0].Get("myrate")); var rateDelay = 133; // <== change here var future = timer.ScheduleAtFixedRate(runnable, 0, rateDelay, TimeUnit.MILLISECONDS); System.Threading.Thread.Sleep(2 * 60 * 1000); future.Cancel(true); }
public void Shutdown() { ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor (5, Executors.DefaultThreadFactory ()); bool run = false; e.Schedule (new RunnableAction (delegate { run = true; }),100, TimeUnit.MILLISECONDS); Thread.Sleep (50); e.Shutdown (); Assert.IsTrue (e.IsShutdown ()); Assert.IsFalse (e.IsTerminated (), "Terminated"); Assert.IsTrue (e.IsTerminating (), "Terminating"); Thread.Sleep (100); Assert.IsTrue (run, "Not run"); Assert.IsTrue (e.IsTerminated (), "Terminated"); Assert.IsFalse (e.IsTerminating (), "Terminating"); }
/// <exception cref="System.Exception"/> protected override void ServiceInit(Configuration conf) { ThreadFactory tf = new ThreadFactoryBuilder().SetNameFormat("DeletionService #%d" ).Build(); if (conf != null) { sched = new DeletionService.DelServiceSchedThreadPoolExecutor(conf.GetInt(YarnConfiguration .NmDeleteThreadCount, YarnConfiguration.DefaultNmDeleteThreadCount), tf); debugDelay = conf.GetInt(YarnConfiguration.DebugNmDeleteDelaySec, 0); } else { sched = new DeletionService.DelServiceSchedThreadPoolExecutor(YarnConfiguration.DefaultNmDeleteThreadCount , tf); } sched.SetExecuteExistingDelayedTasksAfterShutdownPolicy(false); sched.SetKeepAliveTime(60L, TimeUnit.Seconds); if (stateStore.CanRecover()) { Recover(stateStore.LoadDeletionServiceState()); } base.ServiceInit(conf); }
public virtual void TestDelayedDelete() { FilePath[] localLogDirs = GetLocalLogDirFiles(this.GetType().FullName, 2); string localLogDirsString = localLogDirs[0].GetAbsolutePath() + "," + localLogDirs [1].GetAbsolutePath(); conf.Set(YarnConfiguration.NmLogDirs, localLogDirsString); conf.SetBoolean(YarnConfiguration.LogAggregationEnabled, false); conf.SetLong(YarnConfiguration.NmLogRetainSeconds, YarnConfiguration.DefaultNmLogRetainSeconds ); dirsHandler.Init(conf); NonAggregatingLogHandler logHandler = new TestNonAggregatingLogHandler.NonAggregatingLogHandlerWithMockExecutor (this, dispatcher, mockDelService, dirsHandler); logHandler.Init(conf); logHandler.Start(); logHandler.Handle(new LogHandlerAppStartedEvent(appId, user, null, ContainerLogsRetentionPolicy .AllContainers, null)); logHandler.Handle(new LogHandlerContainerFinishedEvent(container11, 0)); logHandler.Handle(new LogHandlerAppFinishedEvent(appId)); Path[] localAppLogDirs = new Path[2]; localAppLogDirs[0] = new Path(localLogDirs[0].GetAbsolutePath(), appId.ToString() ); localAppLogDirs[1] = new Path(localLogDirs[1].GetAbsolutePath(), appId.ToString() ); ScheduledThreadPoolExecutor mockSched = ((TestNonAggregatingLogHandler.NonAggregatingLogHandlerWithMockExecutor )logHandler).mockSched; Org.Mockito.Mockito.Verify(mockSched).Schedule(Matchers.Any <Runnable>(), Matchers.Eq (10800l), Matchers.Eq(TimeUnit.Seconds)); logHandler.Close(); for (int i = 0; i < localLogDirs.Length; i++) { FileUtils.DeleteDirectory(localLogDirs[i]); } }
public void ShutdownNoContinueExisting () { ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor (5, Executors.DefaultThreadFactory ()); e.SetExecuteExistingDelayedTasksAfterShutdownPolicy (false); bool run = false; e.Schedule (new RunnableAction (delegate { run = true; }),100, TimeUnit.MILLISECONDS); Thread.Sleep (50); e.Shutdown (); Assert.IsTrue (e.IsShutdown ()); Assert.IsTrue (e.IsTerminated (), "Terminated"); Assert.IsFalse (e.IsTerminating (), "Terminating"); Thread.Sleep (100); Assert.IsFalse (run); Assert.IsTrue (e.IsTerminated (), "Terminated"); Assert.IsFalse (e.IsTerminating (), "Terminating"); }
/// <summary> /// Queries datanodes for the blocks specified in <code>datanodeBlocks</code>, /// making one RPC to each datanode. /// </summary> /// <remarks> /// Queries datanodes for the blocks specified in <code>datanodeBlocks</code>, /// making one RPC to each datanode. These RPCs are made in parallel using a /// threadpool. /// </remarks> /// <param name="datanodeBlocks">Map of datanodes to the blocks present on the DN</param> /// <returns>metadatas Map of datanodes to block metadata of the DN</returns> /// <exception cref="Org.Apache.Hadoop.Hdfs.Security.Token.Block.InvalidBlockTokenException /// ">if client does not have read access on a requested block</exception> internal static IDictionary <DatanodeInfo, HdfsBlocksMetadata> QueryDatanodesForHdfsBlocksMetadata (Configuration conf, IDictionary <DatanodeInfo, IList <LocatedBlock> > datanodeBlocks , int poolsize, int timeoutMs, bool connectToDnViaHostname) { IList <BlockStorageLocationUtil.VolumeBlockLocationCallable> callables = CreateVolumeBlockLocationCallables (conf, datanodeBlocks, timeoutMs, connectToDnViaHostname, Trace.CurrentSpan()); // Use a thread pool to execute the Callables in parallel IList <Future <HdfsBlocksMetadata> > futures = new AList <Future <HdfsBlocksMetadata> > (); ExecutorService executor = new ScheduledThreadPoolExecutor(poolsize); try { futures = executor.InvokeAll(callables, timeoutMs, TimeUnit.Milliseconds); } catch (Exception) { } // Swallow the exception here, because we can return partial results executor.Shutdown(); IDictionary <DatanodeInfo, HdfsBlocksMetadata> metadatas = Maps.NewHashMapWithExpectedSize (datanodeBlocks.Count); // Fill in metadatas with results from DN RPCs, where possible for (int i = 0; i < futures.Count; i++) { BlockStorageLocationUtil.VolumeBlockLocationCallable callable = callables[i]; DatanodeInfo datanode = callable.GetDatanodeInfo(); Future <HdfsBlocksMetadata> future = futures[i]; try { HdfsBlocksMetadata metadata = future.Get(); metadatas[callable.GetDatanodeInfo()] = metadata; } catch (CancellationException e) { Log.Info("Cancelled while waiting for datanode " + datanode.GetIpcAddr(false) + ": " + e.ToString()); } catch (ExecutionException e) { Exception t = e.InnerException; if (t is InvalidBlockTokenException) { Log.Warn("Invalid access token when trying to retrieve " + "information from datanode " + datanode.GetIpcAddr(false)); throw (InvalidBlockTokenException)t; } else { if (t is NotSupportedException) { Log.Info("Datanode " + datanode.GetIpcAddr(false) + " does not support" + " required #getHdfsBlocksMetadata() API" ); throw (NotSupportedException)t; } else { Log.Info("Failed to query block locations on datanode " + datanode.GetIpcAddr(false ) + ": " + t); } } if (Log.IsDebugEnabled()) { Log.Debug("Could not fetch information from datanode", t); } } catch (Exception) { // Shouldn't happen, because invokeAll waits for all Futures to be ready Log.Info("Interrupted while fetching HdfsBlocksMetadata"); } } return(metadatas); }
internal override ScheduledThreadPoolExecutor CreateScheduledThreadPoolExecutor(Configuration conf) { this.mockSched = Org.Mockito.Mockito.Mock <ScheduledThreadPoolExecutor>(); return(this.mockSched); }
/// <summary> /// Default ctor /// </summary> private TaskMonitorService() { executor = new ScheduledThreadPoolExecutor(1); }