예제 #1
0
        private static void Core()
        {
            var complete = Bench(() =>
            {
                using (var node = Node.Connect(Network.Main, "192.168.0.7", new NodeConnectionParameters()
                {
                    IsTrusted = true,
                    IsRelay = false
                }))
                {
                    var originalNode = node;
                    node.VersionHandshake();
                    var chain           = node.GetChain();
                    List <ulong> speeds = new List <ulong>();

                    Stopwatch watch = new Stopwatch();
                    watch.Start();
                    PerformanceSnapshot snap = null;
                    foreach (var block in originalNode.GetBlocks(chain.Tip.EnumerateToGenesis()))
                    {
                        if (watch.Elapsed > TimeSpan.FromSeconds(10.0))
                        {
                            var newSnap = originalNode.Counter.Snapshot();
                            if (snap != null)
                            {
                                var perf = newSnap - snap;
                                speeds.Add(perf.ReadenBytesPerSecond / 1024);
                            }
                            snap = newSnap;
                            watch.Restart();
                        }
                    }
                }
            });
        }
예제 #2
0
        public void process()
        {
            Console.WriteLine("Rezultatai:");
            foreach (PerformanceSnapshot entry in entries.Values)
            {
                Console.WriteLine("\t" + entry.name + ": " + entry.exucutionTime + "ms | " + Math.Round((double)entry.memoryFootprint / 1024.0, 3) + "KB");
            }

            List <PerformanceSnapshot> list = entries.Values.ToList();

            list.Sort((PerformanceSnapshot o, PerformanceSnapshot t) => o.exucutionTime.CompareTo(t.exucutionTime));

            PerformanceSnapshot baseline = list.First();

            Console.WriteLine("Surusiuoti rezultatai:");
            int index = 1;

            foreach (PerformanceSnapshot entry in list)
            {
                long   executionTimeDiff    = entry.exucutionTime - baseline.exucutionTime;
                double executionTimeDiffPer = Math.Round((((double)Math.Abs(entry.exucutionTime - baseline.exucutionTime)) / ((double)(baseline.exucutionTime + entry.exucutionTime) / 2.0)) * 100.0, 2);

                double memDiff     = Math.Round((entry.memoryFootprint - baseline.memoryFootprint) / 1024.0, 3);
                double entryMem    = Math.Round((double)entry.memoryFootprint / 1024.0, 3);
                double baselineMem = Math.Round((double)baseline.memoryFootprint / 1024.0, 3);
                double memDiffPer  = Math.Round((((double)Math.Abs(entryMem - baselineMem)) / ((double)(baselineMem + entryMem) / 2.0)) * 100.0, 2);

                Console.WriteLine("\t" + index++ + ". " + entry.name + ": " + entry.exucutionTime + "ms [" + executionTimeDiff + "ms] [" + executionTimeDiffPer + "%] | " + Math.Round((double)entry.memoryFootprint / 1024.0, 3) + "KB [" + memDiff + "KB] [" + memDiffPer + "%]");
            }
        }
        public void UpdateSpeed()
        {
            var snap = _Node.Counter.Snapshot();

            if (_Snap != null)
            {
                Speed = (snap - _Snap).ToString();
            }
            _Snap = snap;
            var behavior = _Node.Behaviors.Find <PingPongBehavior>();

            if (behavior != null)
            {
                Latency = (int)behavior.Latency.TotalMilliseconds;
                behavior.Probe();
            }

            LastSeen = _Node.LastSeen.LocalDateTime;

            var tracker = _Node.Behaviors.Find <TrackerBehavior>();
            var chain   = _Node.Behaviors.Find <ChainBehavior>();

            if (tracker.CurrentProgress != null)
            {
                CurrentProgress = chain.Chain.FindFork(tracker.CurrentProgress).Height;
            }
        }
예제 #4
0
        public void end(string id)
        {
            PerformanceSnapshot entry = entries[id];

            entry.stopwatch.Stop();
            entry.exucutionTime   = entries[id].stopwatch.ElapsedMilliseconds;
            entry.memoryFootprint = GC.GetTotalMemory(true) - entries[id].memoryFootprint;
        }
예제 #5
0
        public void begin(string id)
        {
            PerformanceSnapshot snapshot = new PerformanceSnapshot();

            snapshot.stopwatch       = new Stopwatch();
            snapshot.name            = id;
            snapshot.exucutionTime   = 0;
            snapshot.memoryFootprint = GC.GetTotalMemory(true);

            entries.Add(id, snapshot);

            snapshot.stopwatch.Start();
        }
예제 #6
0
        public string GetStats()
        {
            StringBuilder builder = new StringBuilder();

            lock (this.downloads)
            {
                PerformanceSnapshot diffTotal = new PerformanceSnapshot(0, 0);
                builder.AppendLine("=======Connections=======");
                foreach (INetworkPeer peer in this.ConnectedPeers)
                {
                    PerformanceSnapshot newSnapshot  = peer.Counter.Snapshot();
                    PerformanceSnapshot lastSnapshot = null;
                    if (this.downloads.TryGetValue(peer, out lastSnapshot))
                    {
                        BlockPullerBehavior behavior = peer.Behaviors.OfType <BlockPullerBehavior>()
                                                       .FirstOrDefault(b => b.Puller.GetType() == typeof(LookaheadBlockPuller));

                        PerformanceSnapshot diff = newSnapshot - lastSnapshot;
                        diffTotal = new PerformanceSnapshot(diff.TotalReadBytes + diffTotal.TotalReadBytes, diff.TotalWrittenBytes + diffTotal.TotalWrittenBytes)
                        {
                            Start = diff.Start, Taken = diff.Taken
                        };
                        builder.Append((peer.RemoteSocketAddress + ":" + peer.RemoteSocketPort).PadRight(LoggingConfiguration.ColumnLength * 2) + "R:" + this.ToKBSec(diff.ReadenBytesPerSecond) + "\tW:" + this.ToKBSec(diff.WrittenBytesPerSecond));
                        if (behavior != null)
                        {
                            int intQuality = (int)behavior.QualityScore;
                            builder.Append("\tQualityScore: " + intQuality + (intQuality < 10 ? "\t" : "") + "\tPendingBlocks: " + behavior.PendingDownloadsCount);
                        }

                        builder.AppendLine();
                    }

                    this.downloads.AddOrReplace(peer, newSnapshot);
                }

                builder.AppendLine("=================");
                builder.AppendLine("Total".PadRight(LoggingConfiguration.ColumnLength * 2) + "R:" + this.ToKBSec(diffTotal.ReadenBytesPerSecond) + "\tW:" + this.ToKBSec(diffTotal.WrittenBytesPerSecond));
                builder.AppendLine("==========================");

                //TODO: Hack, we should just clean nodes that are not connect anymore.
                if (this.downloads.Count > 1000)
                {
                    this.downloads.Clear();
                }
            }

            return(builder.ToString());
        }
        public string GetStats()
        {
            StringBuilder builder = new StringBuilder();

            lock (_Downloads)
            {
                PerformanceSnapshot diffTotal = new PerformanceSnapshot(0, 0);
                builder.AppendLine("=======Connections=======");
                foreach (var node in ConnectedNodes)
                {
                    var newSnapshot = node.Counter.Snapshot();
                    PerformanceSnapshot lastSnapshot = null;
                    if (_Downloads.TryGetValue(node, out lastSnapshot))
                    {
                        var behavior = node.Behaviors.OfType <BlockPuller.BlockPullerBehavior>()
                                       .FirstOrDefault(b => b.Puller.GetType() == typeof(LookaheadBlockPuller));
                        var diff = newSnapshot - lastSnapshot;
                        diffTotal = new PerformanceSnapshot(diff.TotalReadenBytes + diffTotal.TotalReadenBytes, diff.TotalWrittenBytes + diffTotal.TotalWrittenBytes)
                        {
                            Start = diff.Start, Taken = diff.Taken
                        };
                        builder.Append((node.RemoteSocketAddress + ":" + node.RemoteSocketPort).PadRight(Logs.ColumnLength * 2) + "R:" + ToKBSec(diff.ReadenBytesPerSecond) + "\tW:" + ToKBSec(diff.WrittenBytesPerSecond));
                        if (behavior != null)
                        {
                            builder.Append("\tQualityScore: " + behavior.QualityScore + (behavior.QualityScore < 10 ? "\t" : "") + "\tPendingBlocks: " + behavior.PendingDownloads.Count);
                        }
                        builder.AppendLine();
                    }
                    _Downloads.AddOrReplace(node, newSnapshot);
                }
                builder.AppendLine("=================");
                builder.AppendLine("Total".PadRight(Logs.ColumnLength * 2) + "R:" + ToKBSec(diffTotal.ReadenBytesPerSecond) + "\tW:" + ToKBSec(diffTotal.WrittenBytesPerSecond));
                builder.AppendLine("==========================");

                //TODO: Hack, we should just clean nodes that are not connect anymore
                if (_Downloads.Count > 1000)
                {
                    _Downloads.Clear();
                }
            }
            return(builder.ToString());
        }