Ejemplo n.º 1
0
        internal EventStream(ActorSystem system)
        {
            var shouldThrottle = Throttle.Create(system.Config.DeadLetterThrottleCount, system.Config.DeadLetterThrottleInterval,
                                                 droppedLogs => _logger.LogInformation("[DeadLetter] Throttled {LogCount} logs.", droppedLogs)
                                                 );

            Subscribe <DeadLetterEvent>(
                dl => {
                if (system.Config.DeadLetterRequestLogging is false && dl.Sender is not null)
                {
                    return;
                }

                if (!system.Shutdown.IsCancellationRequested && shouldThrottle().IsOpen() && dl.Message is not IIgnoreDeadLetterLogging)
                {
                    _logger.LogInformation(
                        "[DeadLetter] could not deliver '{MessageType}:{Message}' to '{Target}' from '{Sender}'",
                        dl.Message.GetType().Name,
                        dl.Message,
                        dl.Pid,
                        dl.Sender
                        );
                }
            }
                );
        }
Ejemplo n.º 2
0
        public async Task OpensAfterTimespan()
        {
            const int maxEvents      = 2;
            var       triggered      = 0;
            var       shouldThrottle = Throttle.Create(maxEvents, TimeSpan.FromMilliseconds(50));

            for (var i = 0; i < 100; i++)
            {
                if (shouldThrottle().IsOpen())
                {
                    triggered++;
                }
            }

            triggered.Should().Be(maxEvents);

            await Task.Delay(2000);

            for (var i = 0; i < 100; i++)
            {
                if (shouldThrottle().IsOpen())
                {
                    triggered++;
                }
            }

            triggered.Should().Be(maxEvents * 2, "We expect the throttle to open after the timespan");
        }
Ejemplo n.º 3
0
        public async Task GivesCorrectValveStatus()
        {
            const int maxEvents      = 2;
            var       shouldThrottle = Throttle.Create(maxEvents, TimeSpan.FromMilliseconds(50));

            shouldThrottle().Should().Be(Throttle.Valve.Open, "It accepts multiple event before closing");
            shouldThrottle().Should().Be(Throttle.Valve.Closing, "Last event before close");
            shouldThrottle().Should().Be(Throttle.Valve.Closed, "Anything over the limit is throttled");
            await Task.Delay(1000);

            shouldThrottle().Should().Be(Throttle.Valve.Open, "After the period it should open again");
        }
        public DefaultClusterContext(IIdentityLookup identityLookup, PidCache pidCache, ClusterContextConfig config, CancellationToken killSwitch)
        {
            _identityLookup = identityLookup;
            _pidCache       = pidCache;

            _requestLogThrottle = Throttle.Create(
                config.MaxNumberOfEventsInRequestLogThrottlePeriod,
                config.RequestLogThrottlePeriod,
                i => Logger.LogInformation("Throttled {LogCount} TryRequestAsync logs", i)
                );
            _clock = new TaskClock(config.ActorRequestTimeout, TimeSpan.FromSeconds(1), killSwitch);
            _clock.Start();
        }
        public ExperimentalClusterContext(Cluster cluster)
        {
            _identityLookup = cluster.IdentityLookup;
            _pidCache       = cluster.PidCache;
            var config = cluster.Config;

            _requestLogThrottle = Throttle.Create(
                config.MaxNumberOfEventsInRequestLogThrottlePeriod,
                config.RequestLogThrottlePeriod,
                i => Logger.LogInformation("Throttled {LogCount} TryRequestAsync logs", i)
                );
            _clock = new TaskClock(config.ActorRequestTimeout, TimeSpan.FromSeconds(1), cluster.System.Shutdown);
            _clock.Start();
        }
Ejemplo n.º 6
0
        public void ThrottlesEfficiently()
        {
            const int maxEvents      = 2;
            var       triggered      = 0;
            var       shouldThrottle = Throttle.Create(maxEvents, TimeSpan.FromSeconds(1));

            for (var i = 0; i < 10000; i++)
            {
                if (shouldThrottle().IsOpen())
                {
                    triggered++;
                }
            }

            triggered.Should().Be(maxEvents);
        }