Ejemplo n.º 1
0
        // Note: this class should be used only via the simulation context
        // to ensure that concurrent simulations don't share data
        public RateLimiting(
            IRateLimitingConfig config,
            ILogger log,
            IInstance instance)
        {
            this.log         = log;
            this.clusterSize = 1;
            this.instance    = instance;

            // TODO: these initializations will be moved to Init when SimulationManager is
            //       integrated.
            this.connections = new PerSecondCounter(
                config.ConnectionsPerSecond, "Device connections", this.log);

            this.registryOperations = new PerMinuteCounter(
                config.RegistryOperationsPerMinute, "Registry operations", this.log);

            this.twinReads = new PerSecondCounter(
                config.TwinReadsPerSecond, "Twin reads", this.log);

            this.twinWrites = new PerSecondCounter(
                config.TwinWritesPerSecond, "Twin writes", this.log);

            this.messaging = new PerSecondCounter(
                config.DeviceMessagesPerSecond, "Device msg/sec", this.log);
        }
Ejemplo n.º 2
0
        // TODO: https://github.com/Azure/device-simulation-dotnet/issues/80
        //private readonly PerDayCounter messagingDaily;

        public RateLimiting(
            IRateLimitingConfig config,
            ILogger log)
        {
            this.connections = new PerSecondCounter(
                config.ConnectionsPerSecond, "Device connections", log);

            this.registryOperations = new PerMinuteCounter(
                config.RegistryOperationsPerMinute, "Registry operations", log);

            this.twinReads = new PerSecondCounter(
                config.TwinReadsPerSecond, "Twin reads", log);

            this.twinWrites = new PerSecondCounter(
                config.TwinWritesPerSecond, "Twin writes", log);

            this.messaging = new PerSecondCounter(
                config.DeviceMessagesPerSecond, "Device msg/sec", log);

            //this.messagingDaily = new PerDayCounter(
            //    config.DeviceMessagesPerDay, "Device msg/day", log);

            // The class should be a singleton, if this appears more than once
            // something is not setup correctly and the rating won't work.
            // TODO: enforce the single instance, compatibly with the use of
            //       Parallel.For in the simulation runner.
            //       https://github.com/Azure/device-simulation-dotnet/issues/79
            log.Info("Rate limiting started. This message should appear only once in the logs.", () => { });
        }
Ejemplo n.º 3
0
        public void Init(IRateLimitingConfig config)
        {
            this.instance.InitOnce();

            this.connections = new PerSecondCounter(
                config.ConnectionsPerSecond, "Device connections", this.log);

            this.registryOperations = new PerMinuteCounter(
                config.RegistryOperationsPerMinute, "Registry operations", this.log);

            this.twinReads = new PerSecondCounter(
                config.TwinReadsPerSecond, "Twin reads", this.log);

            this.twinWrites = new PerSecondCounter(
                config.TwinWritesPerSecond, "Twin writes", this.log);

            this.messaging = new PerSecondCounter(
                config.DeviceMessagesPerSecond, "Device msg/sec", this.log);

            this.instance.InitComplete();
        }