当前位置: 首页>>代码示例>>C#>>正文


C# Stat.Sum方法代码示例

本文整理汇总了C#中Stat.Sum方法的典型用法代码示例。如果您正苦于以下问题:C# Stat.Sum方法的具体用法?C# Stat.Sum怎么用?C# Stat.Sum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stat的用法示例。


在下文中一共展示了Stat.Sum方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        public bool Execute(CommandProcessorContext context, CancellationToken token, string[] args)
        {
            var batchCount = 15;
            var batchSize = 10000;
            var projectionCount = 10;
            var readerCount = 10;

            if (args.Length > 0)
                int.TryParse(args[0], out batchCount);
            if (args.Length > 1)
                int.TryParse(args[1], out batchSize);
            if (args.Length > 2)
                int.TryParse(args[2], out projectionCount);
            if (args.Length > 3)
                int.TryParse(args[3], out readerCount);

            context.Log.Debug("batchCount: {0}", batchCount);
            context.Log.Debug("batchSize: {0}", batchSize);
            context.Log.Debug("projectionCount: {0}", projectionCount);
            context.Log.Debug("readerCount: {0}", readerCount);

            var startEvt = new ManualResetEventSlim(false);
            _failures = 0;

            var streamId = "SmartAppTest-" + Guid.NewGuid();

            var totalSw = Stopwatch.StartNew();

            // write half of data to the stream
            var writeStat = new Stat();
            WriteEvents(streamId, batchCount / 2, batchSize, context, writeStat);
            var wrBytesPerSec = writeStat.ElapsedMsec > 0 ? (writeStat.Count * 1000D / writeStat.ElapsedMsec) : 0;
            context.Log.Debug("Events write throughput: {0}", FormatEvil.SpeedInBytes(wrBytesPerSec));

            var threads = new List<Thread>();

            using (var cts = new CancellationTokenSource())
            using (var linked = CancellationTokenSource.CreateLinkedTokenSource(token, cts.Token))
            {
                // Upload some random data to an event stream in batches (a thread and large batches)
                writeStat = new Stat();
                var writerThread = CreateEventWriterThread(streamId, batchCount / 2, batchSize, context, writeStat, startEvt, linked.Token);
                writerThread.Start();

                // run a set of projections in parallel for this event stream (1 thread per projection)
                var projStat = new Stat[projectionCount];
                for (var i = 0; i < projectionCount; i++)
                {
                    projStat[i] = new Stat();
                    threads.Add(CreateProjectionThread(streamId, i, context, startEvt, linked.Token, projStat[i]));
                    threads.Last().Start();
                }

                // poll projected views with multiple concurrent readers
                var projectionIndex = 0;
                var readerStat = new Stat[readerCount];
                for (var i = 0; i < readerCount; i++)
                {
                    readerStat[i] = new Stat();
                    threads.Add(CreateViewReaderThread(i, projectionIndex, context, startEvt, linked.Token, readerStat[i]));
                    threads.Last().Start();

                    projectionIndex++;
                    if (projectionIndex >= projectionCount)
                        projectionIndex = 0;
                }

                // Start all thread
                startEvt.Set();

                // Wait until second half of data will be written
                writerThread.Join();

                // Cancel rest threads
                cts.Cancel();
                foreach (var thread in threads)
                    thread.Join();

                totalSw.Stop();

                // Projections stat
                wrBytesPerSec = writeStat.ElapsedMsec > 0 ? (writeStat.Count * 1000D / writeStat.ElapsedMsec) : 0;
                context.Log.Debug("Events write throughput under load: {0}", FormatEvil.SpeedInBytes(wrBytesPerSec));

                var elapsedMsec = projStat.Max(s => s.ElapsedMsec);
                var totalBytes = projStat.Sum(s => s.Count);
                var bytesPerSec = elapsedMsec > 0 ? (totalBytes * 1000D / elapsedMsec) : 0;
                context.Log.Debug("Events read throughput: {0}", FormatEvil.SpeedInBytes(bytesPerSec));

                elapsedMsec = readerStat.Max(s => s.ElapsedMsec);
                var totalReads = readerStat.Sum(s => s.Count);
                var readsPerSec = elapsedMsec > 0 ? (totalReads * 1000D / elapsedMsec) : 0;
                context.Log.Debug("Views object read rate: {0} instance/sec", FormatEvil.ToHumanReadable(readsPerSec));

                context.Log.Info("Total time: {0}", totalSw.Elapsed);

                var key = string.Format("SAB-WR-{0}-{1}-bytesPerSec", batchCount, batchSize);
                PerfUtils.LogTeamCityGraphData(key, (int) wrBytesPerSec);
                PerfUtils.LogTeamCityGraphData("SAB-RE-bytesPerSec", (int) bytesPerSec);
                PerfUtils.LogTeamCityGraphData("SAB-RV-objectsPerSec", (int) readsPerSec);
//.........这里部分代码省略.........
开发者ID:Lokad,项目名称:lokad-data-platform,代码行数:101,代码来源:SmartAppBenchmarkProcessor.cs


注:本文中的Stat.Sum方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。