public async Task InvokeAsync(HttpContext httpContext, IOptionsMonitor <ThrottlingOptions> options, ILogger <ThrottlingMiddleware> logger)
 {
     _logger  = logger;
     _options = options.CurrentValue;
     await Throttle(_options, httpContext.Request.Method);
     await _next(httpContext);
 }
 public PreviewController(
     ThrottlingOptions throttlingOptions,
     RawFileStorageInfoProvider rawFileStorageInfoProvider,
     IObjectsStorageReader objectsStorageReader,
     ImagePreviewService imagePreviewService)
 {
     _retryAfter = throttlingOptions.RetryAfter;
     _rawFileStorageInfoProvider = rawFileStorageInfoProvider;
     _objectsStorageReader       = objectsStorageReader;
     _imagePreviewService        = imagePreviewService;
 }
Exemple #3
0
 public ImagePreviewService(
     CephOptions cephOptions,
     ThrottlingOptions throttlingOptions,
     IS3Client s3Client,
     MemoryBasedRequestLimiter requestLimiter)
 {
     _bucketName     = cephOptions.FilesBucketName;
     _requestTimeout = throttlingOptions.RequestTimeout;
     _s3Client       = s3Client;
     _requestLimiter = requestLimiter;
 }
Exemple #4
0
        public RequestQueueTests()
        {
            _threading = new TestTheadingServices();
            _options   = new ThrottlingOptions
            {
                ThreadingServices = _threading
            };

            CreateRequestQueue();

            _app = env => Task.FromResult(0);
        }
Exemple #5
0
        public RequestQueueTests()
        {
            _threading = new TestTheadingServices();
            _options = new ThrottlingOptions
            {
                ThreadingServices = _threading
            };

            CreateRequestQueue();

            _app = env => Task.FromResult(0);
        }
        public RequestQueue(ThrottlingOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            _threading = options.ThreadingServices;
            _activeThreadsBeforeLocalRequestsQueue     = options.ActiveThreadsBeforeLocalRequestsQueue;
            _activeThreadsBeforeRemoteRequestsQueue    = options.ActiveThreadsBeforeRemoteRequestsQueue;
            _queueLengthBeforeIncomingRequestsRejected = options.QueueLengthBeforeIncomingRequestsRejected;

            _maxThreads = _threading.GetMaxThreads();

            _executeIfNeeded = ExecuteIfNeeded;
        }
Exemple #7
0
        public RequestQueue(ThrottlingOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            _threading = options.ThreadingServices;
            _activeThreadsBeforeLocalRequestsQueue = options.ActiveThreadsBeforeLocalRequestsQueue;
            _activeThreadsBeforeRemoteRequestsQueue = options.ActiveThreadsBeforeRemoteRequestsQueue;
            _queueLengthBeforeIncomingRequestsRejected = options.QueueLengthBeforeIncomingRequestsRejected;

            _maxThreads = _threading.GetMaxThreads();

            _executeIfNeeded = ExecuteIfNeeded;
        }
        private async Task Throttle(ThrottlingOptions options, string httpMethodName)
        {
            var methodOptions = options.Methods.FirstOrDefault(o => string.Equals(o.Name, httpMethodName, StringComparison.InvariantCultureIgnoreCase));

            if (methodOptions != null && methodOptions.Enabled)
            {
                _logger.LogInformation($"Throttling enabled for {httpMethodName} method, level: {methodOptions.Level}, function check interval: {options.FunctionLevelCheckInterval}, Prodis busy state url: {options.ThrottlingInfoUrl}, LogRequestResponse: {options.LogRequestResponse}");
                var throttleState = await GetLoadInfoResponse(options.IdleCacheTime, options.BusyCacheTime);

                _logger.LogInformation($"Prodis response - IngestIsProcessing: {throttleState?.IngestIsProcessing}, SmartNodesAreProcessing: {throttleState?.SmartNodesAreProcessing}, TvaIsProcessing: {throttleState?.TvaIsProcessing}.");
                if (IsProdisBusy(throttleState))
                {
                    switch (methodOptions.Level)
                    {
                    case Levels.Low:
                        _logger.LogInformation($"Low throttling for {methodOptions.LowThrottleTime}");
                        await Task.Delay(methodOptions.LowThrottleTime);

                        break;

                    case Levels.High:
                        _logger.LogInformation($"High throttling for {methodOptions.HighThrottleTime}");
                        await Task.Delay(methodOptions.HighThrottleTime);

                        break;

                    case Levels.Function:
                        _logger.LogInformation("Function throttling start.");
                        await WaitUntil(async() =>
                        {
                            throttleState = await GetLoadInfoResponse(options.IdleCacheTime, options.BusyCacheTime);
                            return(IsProdisBusy(throttleState));
                        },
                                        options.FunctionLevelCheckInterval);

                        _logger.LogInformation("Function throttling end.");
                        break;
                    }
                }
            }
        }
        public const int DefaultMaxConcurrentBatches = 20;             //Hard "burst" limit is 25

        protected LogicBrokerCommand(string domainUrl, string commandUrl, string subscriptionKey, ThrottlingOptions throttlingOptions, Paging paging = null)
        {
            this.EndpointUrl = new BaseCommandUrl(domainUrl, commandUrl, subscriptionKey).Url;
            this.Paging      = paging ?? Paging.CreateDisabled();
            this.Throttler   = new Throttler(throttlingOptions ?? ThrottlingOptions.LogicBrokerDefaultThrottlingOptions);
        }
 public MemoryBasedRequestLimiter(ThrottlingOptions throttlingOptions)
 {
     _memoryToAllocateThreshold = (long)(throttlingOptions.ThresholdFactor * throttlingOptions.MemoryLimit);
 }
 public static IAppBuilder UseThrottling(this IAppBuilder builder, ThrottlingOptions options)
 {
     return(builder.Use(typeof(ThrottlingMiddleware), options));
 }
Exemple #12
0
 public MemoryBasedRequestLimiter(ThrottlingOptions throttlingOptions)
 {
     _memoryToAllocateThreshold = (int)(0.5 * throttlingOptions.MemoryLimit);
 }
Exemple #13
0
 public ThrottlingMiddleware(RequestDelegate next, ICacheClient cacheClient, ThrottlingOptions options)
 {
     _next        = next;
     _cacheClient = cacheClient;
     _options     = options;
 }