Beispiel #1
0
 public int GetHashCode(AggregatorSettings obj)
 {
     unchecked
     {
         int result = (CounterCategoryFilter != null ? CounterCategoryFilter.GetHashCode() : 0);
         result = (result * 397) ^ (AggregationType != null ? AggregationType.GetHashCode() : 0);
         result = (result * 397) ^ (AggregationParameters != null ? AggregationParameters.GetHashCode() : 0);
         result = (result * 397) ^ (ValuesDataType != null ? ValuesDataType.GetHashCode() : 0);
         result = (result * 397) ^ (CounterNameFilter != null ? CounterNameFilter.GetHashCode() : 0);
         return(result);
     }
 }
Beispiel #2
0
        public Program(IConfiguration config)
        {
#if !COREFX
            ServicePointManager.DefaultConnectionLimit = 500;
            ServicePointManager.Expect100Continue      = false;
            ServicePointManager.UseNagleAlgorithm      = false;
#endif

            var ats   = config.GetSection("AtsStorage");
            var sql   = config.GetSection("SqlStorage");
            var redis = config.GetSection("RedisCache");

            var startTime = DateTime.UtcNow;

            _dataSources = new List <DataSource>();
            for (int i = 0; i < 80; i++)
            {
                _dataSources.Add(new DataSource(new BasicKey {
                    Id = Guid.NewGuid(), Sampling = Sampling.Daily
                }, startTime, TimeSpan.FromMilliseconds(10)));
            }

            var dats = new AtsStorage <BasicKey, BasicEntry>(
                "DatsTables13",
                ats.GetSection("ConnectionString").Value,
                new ConcurrencyControl(AtsStorage <BasicKey, BasicEntry> .DefaultReadParallelism, AtsStorage <BasicKey, BasicEntry> .DefaultWriteParallelism),
                new YearlyPartitioningProvider <BasicKey>(),
                new YearlyTableProvider(),
                this);

            var dsql = new SqlStorage <BasicKey, BasicEntry>(
                "SqlTable3",
                sql.GetSection("ConnectionString").Value,
                new ConcurrencyControl(5, 5),
                this);

            var switchDate = new DateTime(2016, 10, 20, 18, 25, 0, DateTimeKind.Utc);

            var selector = new TestStorageSelector(new StorageSelection <BasicKey, BasicEntry, IStorage <BasicKey, BasicEntry> >[]
            {
                new StorageSelection <BasicKey, BasicEntry, IStorage <BasicKey, BasicEntry> >(dsql, switchDate, null),
                new StorageSelection <BasicKey, BasicEntry, IStorage <BasicKey, BasicEntry> >(dats, null, switchDate),
            });

            var vats = new AtsVolumeStorage <BasicKey, BasicEntry>(
                "VatsTable1",
                ats.GetSection("ConnectionString").Value,
                new ConcurrencyControl(AtsVolumeStorage <BasicKey, BasicEntry> .DefaultReadParallelism, AtsVolumeStorage <BasicKey, BasicEntry> .DefaultWriteParallelism),
                new YearlyPartitioningProvider <BasicKey>(),
                this);

            var tfs = new TemporaryFileStorage <BasicKey, BasicEntry>(
                @"C:\tsdb\cache",
                TemporaryFileStorage <BasicKey, BasicEntry> .DefaultMaxFileSize,
                TemporaryFileStorage <BasicKey, BasicEntry> .DefaultMaxStorageSize,
                this);

            //var client = new TsdbClient<BasicKey, BasicEntry>( selector, vats, tfs, this );

            //var batcher = new TsdbWriteBatcher<BasicKey, BasicEntry>( client, PublicationType.None, TimeSpan.FromSeconds( 5 ), 20000, this );

            //ThreadPool.QueueUserWorkItem( obj => batcher.Handle() );

            ////var engine = new TsdbEngine<BasicKey, BasicEntry>( this, client );
            ////engine.StartAsync().Wait();

            //Console.WriteLine( $"Info: Writing entries..." );
            //while( true )
            //{
            //   var now = DateTime.UtcNow;
            //   foreach( var ds in _dataSources )
            //   {
            //      var serie = ds.GetEntries( now );

            //      batcher.Write( serie );
            //   }

            //   Thread.Sleep( 1000 );
            //}



            var typeStorage          = new TestTypedKeyStorage(_dataSources.Select(x => x.Id));
            var client               = new TsdbClient <BasicKey, BasicEntry>(dats, tfs, this);
            var aggregationFunctions = new AggregationTsdbClient <BasicKey, BasicEntry, MeasureType>(dats, typeStorage, this);

            var batcher = new TsdbWriteBatcher <BasicKey, BasicEntry>(client, PublicationType.None, Publish.Locally, false, TimeSpan.FromSeconds(5), 20000, this);

            ThreadPool.QueueUserWorkItem(obj => batcher.Handle());

            var from = DateTime.UtcNow;

            Console.WriteLine($"Info: Writing entries...");
            for (int i = 0; i < 5; i++)
            {
                var now = DateTime.UtcNow;
                foreach (var ds in _dataSources)
                {
                    var serie = ds.GetEntries(now);

                    batcher.Write(serie);
                }

                Thread.Sleep(1000);
            }

            var to = DateTime.UtcNow;


            Thread.Sleep(30000);
            Console.WriteLine($"Info: Reading groupings...");

            // make optional or nullable...
            //var result = client.ReadLatestAsync( _dataSources.Select( x => x.Id ), 10 ).Result;
            var fields = AggregationParameters.Fields(new AggregatedField("Value", AggregationFunction.Average));
            var result = aggregationFunctions.ReadGroupsAsync("Temperature", fields, from, to, AggregationParameters.NoTagRequirements, new[] { "Placement" }).Result;
            Console.WriteLine(result.Sum(x => x.Entries.Count));

            result = aggregationFunctions.ReadGroupsAsync("Temperature", fields, from, to, AggregationParameters.NoTagRequirements, AggregationParameters.NoGroupings).Result;
            Console.WriteLine(result.Sum(x => x.Entries.Count));
        }