Example #1
0
        private static async Task ReplotFileAsync(DriveInfo diskToPlot, string plotFile, EventAggregator bus, CancellationToken stopPlottingToken)
        {
            var numberOfNonces = long.Parse(plotFile.Split('_')[PlotFileNameNumberOfNoncesIndex]);
            var startingNonce  = long.Parse(plotFile.Split('_')[PlotFileNameStartingNonceIndex]);
            var memoryGb       = Math.Max(Process.GetProcesses().Max(process => process.PeakWorkingSet64) / 1024 / 1024 / 1024, 1);

            var expectedFreeDiskSpace = diskToPlot.AvailableFreeSpace - (numberOfNonces * NonceSize - new FileInfo(plotFile).Length);

            // delete file if it will causes us to go under the minimum free disk space
            if (expectedFreeDiskSpace <= GetMinFreeDiskSpace(diskToPlot))
            {
                File.Delete(plotFile);
            }
            else
            {
                var inProgressPlotFile = Path.Combine(GetIncompletePlotsDirectory(diskToPlot), Path.GetFileName(plotFile));
                var completedPlotFile  = Path.Combine(GetPlotDirectory(diskToPlot), Path.GetFileName(plotFile));

                // move file to plot cache directory
                File.Move(plotFile, inProgressPlotFile);

                // plot
                await BurstCoinMiner.QueuePlotAsync(
                    diskToPlot,
                    ShareCashAccountNumber,
                    numberOfNonces,
                    startingNonce,
                    GetIncompletePlotsDirectory(diskToPlot),
                    GetNumberOfThreadsPerPlot(),
                    memoryGb,
                    GetPlotCancellationToken(diskToPlot, bus, stopPlottingToken));

                // move plotted file to plot directory
                try
                {
                    File.Move(inProgressPlotFile, completedPlotFile);
                }
                catch (Exception e)
                {
                    throw;
                }

                // notify of plot completion
                bus.Publish(new CompletedPlotFileNotification(diskToPlot));
            }
        }
Example #2
0
        private static async Task RunHighDiskUtilizationMonitorAsync(DriveInfo[] disks, EventAggregator bus, CancellationToken stoppingToken)
        {
            const int DriveInfoVolumeLetterIndex      = 0;
            const int MaxDiskQueueLengthWhilePlotting = 2;

            var performanceCounterCategories = PerformanceCounterCategory.GetCategories().ToArray();
            var diskPerformance        = performanceCounterCategories.FirstOrDefault(c => c.CategoryName == "PhysicalDisk");
            var diskQueueLengthResults = diskPerformance.GetInstanceNames()
                                         .Select(diskPerformanceInstanceName => diskPerformance.GetCounters(diskPerformanceInstanceName))
                                         .Select(diskPerformanceCounters => (diskQueueLength: diskPerformanceCounters.FirstOrDefault(c => c.CounterName == "Current Disk Queue Length"), disk: disks.FirstOrDefault(d => diskPerformanceCounters.First().InstanceName.Contains(d.Name[DriveInfoVolumeLetterIndex]))))
                                         .Where(diskQueueLengthResult => diskQueueLengthResult.diskQueueLength != null && diskQueueLengthResult.disk != null).ToArray();

            while (!stoppingToken.IsCancellationRequested)
            {
                foreach (var(diskQueueLength, disk) in diskQueueLengthResults)
                {
                    try
                    {
                        var diskPlot = Process.GetProcesses()
                                       .FirstOrDefault(proc => proc.ProcessName == BurstCoinMiner.GetXplotterAppName() && proc.GetCommandLine().Contains(GetIncompletePlotsDirectory(disk)));

                        // if plotting & over max queue length then report high disk activity
                        if (diskPlot != null && diskQueueLength.RawValue > MaxDiskQueueLengthWhilePlotting)
                        {
                            _logger.LogDebug($"*************************{disk} - high disk activity detected");
                            bus.Publish(new HighDiskActivityNotification(disk));
                        }
                        // if not plotting & no disk activity for a certain time
                        else if (diskPlot == null && await WaitForNoDiskActivityAsync(60 * 1000, diskQueueLength))
                        {
                            bus.Publish(new LowDiskActivityNotification(disk));
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.LogError(e, "error");
                    }
                }

                await Task.Delay(1000, stoppingToken);
            }
        }
Example #3
0
        private static async Task PlotFilesOfSizeAsync(DriveInfo diskToPlot, long plotFileSize, EventAggregator bus, CancellationToken stopPlottingToken)
        {
            var expectedFreeDiskSpace = diskToPlot.AvailableFreeSpace - plotFileSize;

            // plot until we exceed the minimum disk space limit
            while (!stopPlottingToken.IsCancellationRequested && expectedFreeDiskSpace > GetMinFreeDiskSpace(diskToPlot))
            {
                var nextStartingNonce = GetLastCompletedNonce(diskToPlot) + 1 ?? GetRandomStartingNonce();
                var memoryGb          = Math.Max(Process.GetProcesses().Max(process => process.PeakWorkingSet64) / 1024 / 1024 / 1024, 1);
                var numberOfNonces    = plotFileSize / NonceSize;
                var plotFileName      = $"{ShareCashAccountNumber}_{nextStartingNonce}_{numberOfNonces}";

                await BurstCoinMiner.QueuePlotAsync(
                    diskToPlot,
                    ShareCashAccountNumber,
                    numberOfNonces,
                    nextStartingNonce,
                    GetIncompletePlotsDirectory(diskToPlot),
                    GetNumberOfThreadsPerPlot(),
                    memoryGb,
                    GetPlotCancellationToken(diskToPlot, bus, stopPlottingToken));

                // move plotted file to plot directory
                try
                {
                    File.Move(Path.Combine(GetIncompletePlotsDirectory(diskToPlot), plotFileName), Path.Combine(GetPlotDirectory(diskToPlot), plotFileName));
                }
                catch (Exception e)
                {
                    throw;
                }

                // notify of plot completion
                bus.Publish(new CompletedPlotFileNotification(diskToPlot));

                expectedFreeDiskSpace = diskToPlot.AvailableFreeSpace - plotFileSize;
            }
        }
Example #4
0
        public static void SetLogger(ILogger log)
        {
            _logger = log;

            BurstCoinMiner.SetLogger(log);
        }