public WorkScheduler(Configuration configuration, IPlatformPerformance performance)
 {
     Configuration = configuration;
     Performance = performance;
     PendingTasks = new List<PendingTask>();
     RunningTasks = new Dictionary<string, PendingTask>();
 }
Exemplo n.º 2
0
 public WorkScheduler(Configuration configuration, IPlatformPerformance performance)
 {
     Configuration = configuration;
     Performance = performance;
     PendingTasks = new List<PendingTask>();
     RunningTasks = new Dictionary<string, PendingTask>();
 }
Exemplo n.º 3
0
 public WorkScheduler(IMiniLogger logger, bool verbosePerformanceLogging, IPlatformPerformance performance, int maxParallelTasks)
 {
     _verbosePerformanceLogging = verbosePerformanceLogging;
     _logger           = logger;
     _performance      = performance;
     _maxParallelTasks = maxParallelTasks;
 }
Exemplo n.º 4
0
 public WorkScheduler(Configuration configuration, IPlatformPerformance performance)
 {
     Configuration = configuration;
     Performance   = performance;
     PendingTasks  = new PendingTasksQueue();
     RunningTasks  = new Dictionary <string, IImageLoaderTask>();
     SimilarTasks  = new ThreadSafeCollection <IImageLoaderTask>();
 }
Exemplo n.º 5
0
        public WorkScheduler(IMiniLogger logger, bool verbosePerformanceLogging, IPlatformPerformance performance)
        {
            _verbosePerformanceLogging = verbosePerformanceLogging;
            _logger = logger;
            _performance = performance;

            int _processorCount = Environment.ProcessorCount;
            if (_processorCount <= 2)
                _maxParallelTasks = 1;
            else
                _maxParallelTasks = (int)Math.Truncate((double)_processorCount / 2d) + 1;
        }
Exemplo n.º 6
0
        protected async Task RunImageLoadingTaskAsync(IImageLoaderTask pendingTask)
        {
            string keyRaw = pendingTask.KeyRaw;

            try
            {
                if (_imageLoader.VerbosePerformanceLogging)
                {
                    IPlatformPerformance performance = _imageLoader.Performance;

                    LogSchedulerStats(performance);
                    var stopwatch = Stopwatch.StartNew();

                    await pendingTask.RunAsync().ConfigureAwait(false);

                    stopwatch.Stop();

                    _imageLoader.Logger?.Debug(string.Format("[PERFORMANCE] RunAsync - NetManagedThreadId: {0}, NativeThreadId: {1}, Execution: {2} ms, Key: {3}",
                                                             performance.GetCurrentManagedThreadId(),
                                                             performance.GetCurrentSystemThreadId(),
                                                             stopwatch.Elapsed.Milliseconds,
                                                             pendingTask.Key));
                }
                else
                {
                    await pendingTask.RunAsync().ConfigureAwait(false);
                }
            }
            finally
            {
                lock (_lock)
                {
                    RunningTasks.Remove(keyRaw);

                    if (SimilarTasks.Count > 0)
                    {
                        SimilarTasks.RemoveAll(v => v == null || v.IsCompleted || v.IsCancelled);
                        var similarItems = SimilarTasks.Where(v => v.KeyRaw == keyRaw);
                        foreach (var similar in similarItems)
                        {
                            SimilarTasks.Remove(similar);

                            LoadImage(similar);
                        }
                    }
                }

                pendingTask.TryDispose();
                await TakeFromPendingTasksAndRunAsync().ConfigureAwait(false);
            }
        }
Exemplo n.º 7
0
        public WorkScheduler(IMiniLogger logger, bool verbosePerformanceLogging, IPlatformPerformance performance)
        {
            _verbosePerformanceLogging = verbosePerformanceLogging;
            _logger      = logger;
            _performance = performance;

            int _processorCount = Environment.ProcessorCount;

            if (_processorCount <= 2)
            {
                _maxParallelTasks = 1;
            }
            else
            {
                _maxParallelTasks = (int)Math.Truncate((double)_processorCount / 2d) + 1;
            }
        }
Exemplo n.º 8
0
        protected void LogSchedulerStats(IPlatformPerformance performance)
        {
            IMiniLogger?logger = _imageLoader.Logger;

            if (logger == null)
            {
                return;
            }

            logger.Debug(string.Format("[PERFORMANCE] Scheduler - Max: {0}, Pending: {1}, Running: {2}, TotalPending: {3}, TotalRunning: {4}, TotalMemoryCacheHit: {5}, TotalWaiting: {6}",
                                       MaxParallelTasks,
                                       PendingTasks.Count,
                                       RunningTasks.Count,
                                       _statsTotalPending,
                                       _statsTotalRunning,
                                       _statsTotalMemoryCacheHits,
                                       _statsTotalWaiting));

            logger.Debug(performance.GetMemoryInfo());
        }
Exemplo n.º 9
0
 public WorkScheduler(Configuration configuration, IPlatformPerformance performance)
 {
     Configuration = configuration;
     Performance   = performance;
 }