Ejemplo n.º 1
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            // determine benchmark time
            // settup times
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                30, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var commandLine       = $"--benchmark 200 {_cudaDevices} {_openCLDevices} {_extraLaunchParameters}";
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            var benchHashes     = 0d;
            var benchIters      = 0;
            var benchHashResult = 0d;  // Not too sure what this is..

            var lookFor = _miningPairs.Any(mp => mp.Device.DeviceType == DeviceType.AMD) ? "cl0" : "cu0";

            bp.CheckData = (string data) =>
            {
                double hashrate = 0d;
                bool   found    = false;
                for (int i = 0; i < 10; i++)
                {
                    var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, $"A{i}");
                    hashrate = hashrateFoundPair.Item1;
                    found    = hashrateFoundPair.Item2;
                    if (found)
                    {
                        break;
                    }
                }

                if (hashrate > 0 && found && data.Contains(lookFor))
                {
                    benchHashes += hashrate;
                    benchIters++;

                    benchHashResult = (benchHashes / benchIters);
                }

                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = false
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 10);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 2
0
        public override async Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                20, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var algo              = AlgorithmName(_algorithmType);
            var commandLine       = $"--algo {algo} --devices {_devices} --benchmark --time-limit {benchmarkTime} {_extraLaunchParameters}";
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            var benchHashes     = 0d;
            var counter         = 0;
            var benchHashResult = 0d;

            bp.CheckData = (string data) =>
            {
                var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, "Total");
                var hashrate          = hashrateFoundPair.Item1;
                var found             = hashrateFoundPair.Item2;

                if (!found)
                {
                    return new BenchmarkResult {
                               AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                                   new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                               }, Success = false
                    }
                }
                ;

                benchHashes += hashrate;
                counter++;

                benchHashResult = (benchHashes / counter) * (1 - DevFee * 0.01);

                if (_algorithmType == AlgorithmType.X16R)
                {
                    // Quick adjustment, x16r speeds are overestimated by around 3.5
                    benchHashResult /= 3.5;
                }

                return(new BenchmarkResult {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    }, Success = false
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 3
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            // determine benchmark time
            // settup times
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                20, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            // use demo user and disable the watchdog
            var commandLine       = CreateCommandLine(MinerToolkit.DemoUserBTC);
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            double benchHashesSum   = 0;
            double benchHashResult  = 0;
            int    benchIters       = 0;
            int    targetBenchIters = Math.Max(1, (int)Math.Floor(benchmarkTime / 30d));

            // TODO implement fallback average, final benchmark
            bp.CheckData = (string data) => {
                var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, "Total Speed:");
                var hashrate          = hashrateFoundPair.Item1;
                var found             = hashrateFoundPair.Item2;
                if (!found)
                {
                    return new BenchmarkResult {
                               AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                                   new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                               }, Success = false
                    }
                }
                ;

                // sum and return
                benchHashesSum += hashrate;
                benchIters++;

                benchHashResult = (benchHashesSum / benchIters) * (1 - DevFee * 0.01);

                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = benchIters >= targetBenchIters
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 4
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            // determine benchmark time
            // settup times
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                30, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var urlWithPort = GetLocationUrl(_algorithmType, _miningLocation, NhmConectionType.STRATUM_TCP);
            var split       = urlWithPort.Split(':');
            var url         = split[1].Substring(2, split[1].Length - 2);
            var port        = split[2];
            var algo        = AlgorithmName(_algorithmType);

            var commandLine       = $"-uri {algo}://{_username}@{url}:{port} {_devices} -watchdog=false {_extraLaunchParameters}";
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            var benchHashes      = 0d;
            var benchIters       = 0;
            var benchHashResult  = 0d; // Not too sure what this is..
            var targetBenchIters = Math.Max(1, (int)Math.Floor(benchmarkTime / 20d));

            bp.CheckData = (string data) =>
            {
                var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, "Total");
                var hashrate          = hashrateFoundPair.Item1;
                var found             = hashrateFoundPair.Item2;

                if (found)
                {
                    benchHashes += hashrate;
                    benchIters++;

                    benchHashResult = (benchHashes / benchIters) * (1 - DevFee * 0.01);
                }

                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = benchIters >= targetBenchIters
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 10);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 5
0
        public override async Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                20, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var commandLine       = CreateCommandLine(MinerToolkit.DemoUserBTC);
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());
            var id = _mappedIDs[_miningPairs.First().Device.UUID];

            var benchHashes      = 0d;
            var benchIters       = 0;
            var benchHashResult  = 0d; // Not too sure what this is..
            var targetBenchIters = Math.Max(1, (int)Math.Floor(benchmarkTime / 20d));

            bp.CheckData = (data) =>
            {
                var hashrateFoundPair = data.TryGetHashrateAfter($" - {id}: ");
                var hashrate          = hashrateFoundPair.Item1;
                var found             = hashrateFoundPair.Item2;

                if (!found)
                {
                    return new BenchmarkResult {
                               AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                                   new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                               }, Success = false
                    }
                }
                ;

                benchHashes += hashrate;
                benchIters++;

                benchHashResult = (benchHashes / benchIters) * (1 - DevFee * 0.01);

                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = benchIters >= targetBenchIters
                });
            };

            var timeout   = TimeSpan.FromSeconds(benchmarkTime + 5);
            var benchWait = TimeSpan.FromMilliseconds(500);
            var t         = MinerToolkit.WaitBenchmarkResult(bp, timeout, benchWait, stop);

            return(await t);
        }
Ejemplo n.º 6
0
        public override async Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            // dagger takes a long time
            // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            // AVEMORE needs time to build kernels for each platform and this takes quite a while
            // avemore takes REALLY LONG TIME TO BUILD KERNELS!!!! ADD kernel build checks
            // determine benchmark time
            // settup times
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                60, 90, 180
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            // use demo user and disable colorts so we can read from stdout
            var stopAt            = DateTime.Now.AddSeconds(benchmarkTime).ToString("HH:mm");
            var commandLine       = $"--sched-stop {stopAt} -T " + CreateCommandLine(MinerToolkit.DemoUserBTC);
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            var          device        = _miningPairs.Select(kvp => kvp.Device).FirstOrDefault();
            string       currentGPU    = $"GPU{device.ID}";
            const string hashrateAfter = "(avg):";

            bp.CheckData = (string data) =>
            {
                var containsHashRate = data.Contains(currentGPU) && data.Contains(hashrateAfter);
                if (containsHashRate == false)
                {
                    return new BenchmarkResult {
                               Success = false
                    }
                }
                ;

                var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, hashrateAfter);
                var hashrate          = hashrateFoundPair.Item1;
                var found             = hashrateFoundPair.Item2;
                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, hashrate)
                    },
                    Success = found
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 7
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                20, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var commandLine       = $"--benchmark {AlgorithmName(_algorithmType)} --longstats {benchmarkTime} --devices {_devices} {_extraLaunchParameters}";
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            var benchHashes      = 0d;
            var benchIters       = 0;
            var benchHashResult  = 0d; // Not too sure what this is..
            var targetBenchIters = Math.Max(1, (int)Math.Floor(benchmarkTime / 20d));

            bp.CheckData = (string data) =>
            {
                // data => Average speed (60s): 0.40 g/s
                var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, "s):");
                var hashrate          = hashrateFoundPair.Item1;
                var found             = hashrateFoundPair.Item2 && data.Contains("Average speed");

                if (!found)
                {
                    return new BenchmarkResult {
                               Success = false
                    }
                }
                ;

                benchHashes += hashrate;
                benchIters++;

                benchHashResult = (benchHashes / benchIters) * (1 - DevFee * 0.01);

                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = benchIters >= targetBenchIters
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 10);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 8
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                60, 90, 180
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var deviceType = _miningPairs.FirstOrDefault().Device.DeviceType == DeviceType.AMD ? "-amd" : "-nvidia";

            // local benchmark
            // TODO hardcoded epoch
            var commandLine       = $"-gpus {_devices} -gbase 0 -bench 200 -wdog 0 {deviceType} {_extraLaunchParameters}";
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            var benchHashes      = 0d;
            var benchIters       = 0;
            var benchHashResult  = 0d;
            var targetBenchIters = Math.Max(1, (int)Math.Floor(benchmarkTime / 20d));

            bp.CheckData = (string data) =>
            {
                var hashrateFoundPairFirst = data.TryGetHashrateAfter("Eth speed:");
                var hashrateFirst          = hashrateFoundPairFirst.Item1;
                var foundFirst             = hashrateFoundPairFirst.Item2;

                if (foundFirst)
                {
                    benchHashes += hashrateFirst;
                    benchIters++;

                    benchHashResult = (benchHashes / benchIters) * (1 - DevFee * 0.01);
                }


                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    }
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 10);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 9
0
        // TODO account AMD kernel building
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            // END prepare config block

            // determine benchmark time
            // settup times
            var openCLCodeGenerationWait = _miningDeviceTypes.Contains(DeviceType.AMD) ? 20 : 0;
            var benchWait     = 5;
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                30, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds


            var url  = StratumServiceHelpers.GetLocationUrl(_algorithmType, _miningLocation, NhmConectionType.STRATUM_TCP);
            var algo = AlgorithmName(_algorithmType);

            // this one here might block
            string deviceConfigParams = "";

            try
            {
                deviceConfigParams = await PrepareDeviceConfigs(stop);
            }
            catch (Exception e)
            {
                return(new BenchmarkResult
                {
                    ErrorMessage = e.Message
                });
            }

            var disableDeviceTypes = CommandLineHelpers.DisableDevCmd(_miningDeviceTypes);
            var binPathBinCwdPair  = GetBinAndCwdPaths();
            var binPath            = binPathBinCwdPair.Item1;
            var binCwd             = binPathBinCwdPair.Item2;
            // API port function might be blocking
            var apiPort     = GetAvaliablePort();
            var commandLine = $"-o {url} -u {MinerToolkit.DemoUserBTC} --currency {algo} -i {apiPort} --use-nicehash -p x -r x --benchmark 10 --benchwork {benchmarkTime} --benchwait {benchWait} {deviceConfigParams} {disableDeviceTypes}";

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            var benchHashes     = 0d;
            var benchIters      = 0;
            var benchHashResult = 0d;  // Not too sure what this is..

            bp.CheckData = (string data) =>
            {
                var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, "Benchmark Total:");
                var hashrate          = hashrateFoundPair.Item1;
                var found             = hashrateFoundPair.Item2;

                if (found)
                {
                    benchHashes += hashrate;
                    benchIters++;

                    benchHashResult = (benchHashes / benchIters) * (1 - DevFee * 0.01);
                }

                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = found
                });
            };

            // always add 10second extra
            var benchmarkTimeout = TimeSpan.FromSeconds(10 + (2 * benchmarkTime) + benchWait + openCLCodeGenerationWait);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 10
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                60, 90, 180
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var deviceIDs         = string.Join("", _miningPairs.Select(pair => $"{pair.Device.DeviceType.ToString()}{pair.Device.ID}"));
            var algoID            = IsDual() ? $"{SingleAlgoName}{DualAlgoName}" : SingleAlgoName;
            var logfileName       = $"noappend_{deviceIDs}_{algoID}_bench.txt";
            var commandLine       = CreateCommandLine(MinerToolkit.DemoUserBTC) + " -dbg 1 -logfile " + logfileName;
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            bp.CheckData = (string data) =>
            {
                // we can't read from stdout or stderr, read from logs later
                return(new BenchmarkResult());
            };


            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 10);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = await MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            // look for log file and parse that
            try
            {
                var benchHashesFirstSum  = 0d;
                var benchItersFirst      = 0;
                var benchHashesSecondSum = 0d;
                var benchItersSecond     = 0;

                //var afterSingle = $"{SingleAlgoName.ToUpper()} - Total Speed:";
                var firstAlgoLineMustContain  = SingleAlgoName.ToUpper();
                var secondAlgoLineMustContain = DualAlgoName.ToUpper();
                var singleLineMustContain     = SingleAlgoName.ToUpper();
                var gpuAfter  = $"GPU0"; // for single device we always have GPU0
                var afterDual = $"{DualAlgoName.ToUpper()}: {DualAlgoName.ToUpper()} - Total Speed:";

                var logFullPath = Path.Combine(binCwd, logfileName);
                var lines       = File.ReadLines(logFullPath);
                foreach (var line in lines)
                {
                    var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(line, gpuAfter);
                    var hashrate          = hashrateFoundPair.Item1;
                    var found             = hashrateFoundPair.Item2;
                    if (!found || hashrate == 0)
                    {
                        continue;
                    }

                    if (line.Contains(firstAlgoLineMustContain))
                    {
                        benchHashesFirstSum += hashrate;
                        benchItersFirst++;
                    }
                    else if (line.Contains(secondAlgoLineMustContain))
                    {
                        benchHashesSecondSum += hashrate;
                        benchItersSecond++;
                    }
                }
                var benchHashResultFirst  = benchItersFirst == 0 ? 0d : benchHashesFirstSum / benchItersFirst;
                var benchHashResultSecond = benchItersSecond == 0 ? 0d : benchHashesSecondSum / benchItersSecond;
                var success = benchHashResultFirst > 0d;
                var speeds  = new List <AlgorithmTypeSpeedPair> {
                    new AlgorithmTypeSpeedPair(_algorithmType, benchHashResultFirst * (1 - DevFee * 0.01))
                };
                if (IsDual())
                {
                    speeds.Add(new AlgorithmTypeSpeedPair(_algorithmSecondType, benchHashResultSecond * (1 - DualDevFee * 0.01)));
                }
                // return
                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = speeds,
                    Success = success
                });
            }
            catch (Exception e)
            {
                Logger.Error(_logGroup, $"Benchmarking failed: {e.Message}");
            }
            return(t);
        }
Ejemplo n.º 11
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                60, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var commandLine       = $"-a {AlgoName} --benchmark -d {_devices} --multiple-instance {_extraLaunchParameters}";
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            var benchHashResult = 0d;

            bp.CheckData = (string data) =>
            {
                if (!data.Contains("hashrate:"))
                {
                    return(new BenchmarkResult {
                        AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                            new AlgorithmTypeSpeedPair(_algorithmType, 0d)
                        }, Success = false
                    });
                }
                var hashrateFoundPair = BenchmarkHelpers.TryGetHashrateAfter(data, "60s:");
                var hashrate          = hashrateFoundPair.Item1;

                // TODO temporary fix for N/A speeds at 60s mark... will be fixed when developer fixes benchmarking
                if (hashrate == 0)
                {
                    hashrateFoundPair = BenchmarkHelpers.TryGetHashrateAfter(data, "10s:");
                }
                hashrate = hashrateFoundPair.Item1;
                var found = hashrateFoundPair.Item2;

                if (!found)
                {
                    return new BenchmarkResult {
                               AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                                   new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                               }, Success = false
                    }
                }
                ;

                benchHashResult = hashrate * (1 - DevFee * 0.01);

                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = found
                });
            };

            // always add 10second extra
            var benchmarkTimeout = TimeSpan.FromSeconds(10 + benchmarkTime);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 12
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            // determine benchmark time
            // settup times
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                20, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            // use demo user and disable the watchdog
            var commandLine       = CreateCommandLine(MinerToolkit.DemoUserBTC);
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            // disable line readings and read speeds from API
            bp.CheckData = null;

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            double benchHashesSum = 0;
            int    benchIters     = 0;
            var    ticks          = benchmarkTime / 10; // on each 10 seconds tick
            var    result         = new BenchmarkResult();

            for (var tick = 0; tick < ticks; tick++)
            {
                if (t.IsCompleted || t.IsCanceled || stop.IsCancellationRequested)
                {
                    break;
                }
                await Task.Delay(10 * 1000, stop); // 10 seconds delay

                if (t.IsCompleted || t.IsCanceled || stop.IsCancellationRequested)
                {
                    break;
                }

                var ad = await GetMinerStatsDataAsync();

                if (ad.AlgorithmSpeedsPerDevice.Count == 1)
                {
                    // all single GPUs and single speeds
                    try
                    {
                        var gpuSpeed = ad.AlgorithmSpeedsPerDevice.Values.FirstOrDefault().FirstOrDefault().Speed;
                        benchHashesSum += gpuSpeed;
                        benchIters++;
                        double benchHashResult = (benchHashesSum / benchIters); // fee is subtracted from API readings
                        // save each result step
                        result = new BenchmarkResult
                        {
                            AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                                new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                            },
                            Success = benchIters >= (ticks - 1) // allow 1 tick to fail and still consider this benchmark as success
                        };
                    }
                    catch (Exception e)
                    {
                        if (t.IsCompleted || t.IsCanceled || stop.IsCancellationRequested)
                        {
                            break;
                        }
                        Logger.Error(_logGroup, $"benchmarking error: {e.Message}");
                    }
                }
            }
            // await benchmark task
            await t;

            if (stop.IsCancellationRequested)
            {
                return(t.Result);
            }

            // return API result
            return(result);
        }
Ejemplo n.º 13
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            // determine benchmark time
            // settup times
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                20, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var commandLine = MiningCreateCommandLine();

            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            double benchHashesSum  = 0;
            double benchHashResult = 0;
            int    benchIters      = 0;

            bp.CheckData = (string data) =>
            {
                if (!data.Contains("Accepted"))
                {
                    return new BenchmarkResult {
                               AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                                   new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                               }, Success = false
                    }
                }
                ;

                var hashrateFoundPair = BenchmarkHelpers.TryGetHashrate(data);
                var hashrate          = hashrateFoundPair.Item1;
                var found             = hashrateFoundPair.Item2;
                if (!found)
                {
                    return new BenchmarkResult {
                               AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                                   new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                               }, Success = false
                    }
                }
                ;

                // sum and return
                benchHashesSum += hashrate;
                benchIters++;

                benchHashResult = (benchHashesSum / benchIters) * (1 - DevFee * 0.01);

                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = false //TODO not sure what to set here
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 14
0
        public override async Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            // determine benchmark time
            // settup times
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                20, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var algo        = AlgorithmName(_algorithmType);
            var timeLimit   = _noTimeLimitOption ? "" : $"--time-limit {benchmarkTime}";
            var commandLine = $"--algo={algo} --benchmark {timeLimit} --devices {_devices} {_extraLaunchParameters}";

            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine);


            var errorList = new List <string> {
                "Unknown algo parameter", "Cuda error", "Non-existant CUDA device"
            };
            var errorFound = false;
            var errorMsg   = "";

            var benchHashes     = 0d;
            var benchIters      = 0;
            var benchHashResult = 0d;  // Not too sure what this is..
            // TODO fix this tick based system
            var targetBenchIters = Math.Max(1, (int)Math.Floor(benchmarkTime / 20d));

            // TODO implement fallback average, final benchmark
            bp.CheckData = (string data) => {
                // check if error
                foreach (var err in errorList)
                {
                    if (data.Contains(err))
                    {
                        bp.TryExit();
                        errorFound = true;
                        errorMsg   = data;
                        return(new BenchmarkResult {
                            Success = false, ErrorMessage = errorMsg
                        });
                    }
                }

                //return MinerToolkit.TryGetHashrateAfter(data, "Benchmark:"); // TODO add option to read totals
                var hashrateFinalFoundPair = MinerToolkit.TryGetHashrateAfter(data, "Benchmark:"); // TODO add option to read totals
                var hashrateFinal          = hashrateFinalFoundPair.Item1;
                var finalFound             = hashrateFinalFoundPair.Item2;

                if (finalFound)
                {
                    return(new BenchmarkResult
                    {
                        AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                            new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                        },
                        Success = true
                    });
                }
                // no final calculate avg speed
                var hashrateTotalFoundPair = MinerToolkit.TryGetHashrateAfter(data, "Total:"); // TODO add option to read totals
                var hashrateTotal          = hashrateTotalFoundPair.Item1;
                var totalFound             = hashrateTotalFoundPair.Item2;
                if (totalFound)
                {
                    benchHashes += hashrateTotal;
                    benchIters++;
                    benchHashResult = (benchHashes / benchIters); // * (1 - DevFee * 0.01);
                }

                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = benchIters >= targetBenchIters
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 15
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            var numOfGpus = 2; //MUST BE SET CORRECTLY OTHERWISE BENCHMARKING WON't WORK (all cards are combined currently)
            var avgRet    = 0.0;
            var counter   = 0;
            var maxCheck  = 0;
            var after     = "Avr";

            // determine benchmark time
            // settup times
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                20, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var url  = GetLocationUrl(_algorithmType, _miningLocation, NhmConectionType.STRATUM_TCP);
            var algo = AlgorithmName(_algorithmType);

            var commandLine = $"--algo {algo} --url {url} --user {MinerToolkit.DemoUserBTC} --api-bind 0 --no-watchdog --device {_devices} {_extraLaunchParameters}";

            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            bp.CheckData = (string data) =>
            {
                var s   = data;
                var ret = new HashFound();
                ret.hashrate = default(double);
                ret.found    = false;

                if (s.Contains(after))
                {
                    var afterString      = s.GetStringAfter(after).ToLower();
                    var afterStringArray = afterString.Split(' ');
                    var hashRate         = afterStringArray[1];
                    var numString        = new string(hashRate
                                                      .ToCharArray()
                                                      .SkipWhile(c => !char.IsDigit(c))
                                                      .TakeWhile(c => char.IsDigit(c) || c == ',')
                                                      .ToArray());

                    numString.Replace(',', '.');
                    if (!double.TryParse(numString, NumberStyles.Float, CultureInfo.InvariantCulture, out var hash))
                    {
                        return(new BenchmarkResult {
                            AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                                new AlgorithmTypeSpeedPair(_algorithmType, ret.hashrate)
                            }, Success = ret.found
                        });
                    }

                    counter++;
                    if (hashRate.Contains("kh"))
                    {
                        avgRet += hash * 1000;
                    }
                    else if (hashRate.Contains("mh"))
                    {
                        avgRet += hash * 1000000;
                    }
                    else if (hashRate.Contains("gh"))
                    {
                        avgRet += hash * 1000000000;
                    }
                    else
                    {
                        avgRet += hash;
                    }

                    maxCheck--;
                    if (maxCheck == 0)
                    {
                        ret.hashrate = avgRet / counter;
                        ret.found    = true;
                    }
                }
                return(new BenchmarkResult {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, ret.hashrate)
                    }, Success = ret.found
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(300);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 16
0
        public override async Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            using (var tickCancelSource = new CancellationTokenSource())
            {
                var workers      = string.Join(",", _miningPairs.Select((_, i) => $@"""{i}"""));
                var workersReset = @"{""id"":1,""method"":"" workers.reset"",""params"":[__WORKERS__]}".Replace("__WORKERS__", workers);

                // determine benchmark time
                // settup times
                var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                    20, 40, 60
                }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                              // in seconds
                var maxTicks = MinerBenchmarkTimeSettings.ParseBenchmarkTicks(new List <int> {
                    1, 3, 9
                }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);
                var maxTicksEnabled = MinerBenchmarkTimeSettings.MaxTicksEnabled;

                //// use demo user and disable the watchdog
                var commandLine = MiningCreateCommandLine();
                var(binPath, binCwd) = GetBinAndCwdPaths();
                Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
                Logger.Info(_logGroup, $"Benchmarking settings: time={benchmarkTime} ticks={maxTicks} ticksEnabled={maxTicksEnabled}");
                var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());
                // disable line readings and read speeds from API
                bp.CheckData = null;

                var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5);
                var benchmarkWait    = TimeSpan.FromMilliseconds(500);
                var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop, tickCancelSource.Token);


                var stoppedAfterTicks = false;
                var validTicks        = 0;
                var ticks             = benchmarkTime / 10; // on each 10 seconds tick
                var result            = new BenchmarkResult();
                var benchmarkApiData  = new List <ApiData>();
                for (var tick = 0; tick < ticks; tick++)
                {
                    if (t.IsCompleted || t.IsCanceled || stop.IsCancellationRequested)
                    {
                        break;
                    }
                    _ = await ExecuteCommand(workersReset, stop);

                    await ExcavatorTaskHelpers.TryDelay(TimeSpan.FromSeconds(10), stop);

                    if (t.IsCompleted || t.IsCanceled || stop.IsCancellationRequested)
                    {
                        break;
                    }

                    // get speeds
                    var ad = await GetMinerStatsDataAsyncPrivate(stop);

                    var adTotal     = ad.AlgorithmSpeedsTotal();
                    var isTickValid = adTotal.Count > 0 && adTotal.All(pair => pair.speed > 0);
                    benchmarkApiData.Add(ad);
                    if (isTickValid)
                    {
                        ++validTicks;
                    }
                    if (maxTicksEnabled && validTicks >= maxTicks)
                    {
                        stoppedAfterTicks = true;
                        break;
                    }
                }
                // await benchmark task
                if (stoppedAfterTicks)
                {
                    try
                    {
                        tickCancelSource.Cancel();
                    }
                    catch
                    { }
                }
                await t;
                if (stop.IsCancellationRequested)
                {
                    return(t.Result);
                }

                // calc speeds
                // TODO calc std deviaton to reduce invalid benches
                try
                {
                    var nonZeroSpeeds = benchmarkApiData.Where(ad => ad.AlgorithmSpeedsTotal().Count > 0 && ad.AlgorithmSpeedsTotal().All(pair => pair.speed > 0))
                                        .Select(ad => (ad, ad.AlgorithmSpeedsTotal().Count)).ToList();
                    var speedsFromTotals = new List <(AlgorithmType type, double speed)>();
                    if (nonZeroSpeeds.Count > 0)
                    {
                        var maxAlgoPiarsCount = nonZeroSpeeds.Select(adCount => adCount.Count).Max();
                        var sameCountApiDatas = nonZeroSpeeds.Where(adCount => adCount.Count == maxAlgoPiarsCount).Select(adCount => adCount.ad).ToList();
                        var firstPair         = sameCountApiDatas.FirstOrDefault();
                        var speedSums         = firstPair.AlgorithmSpeedsTotal().Select(pair => new KeyValuePair <AlgorithmType, double>(pair.type, 0.0)).ToDictionary(x => x.Key, x => x.Value);
                        // sum
                        foreach (var ad in sameCountApiDatas)
                        {
                            foreach (var pair in ad.AlgorithmSpeedsTotal())
                            {
                                speedSums[pair.type] += pair.speed;
                            }
                        }
                        // average
                        foreach (var algoId in speedSums.Keys.ToArray())
                        {
                            speedSums[algoId] /= sameCountApiDatas.Count;
                        }
                        result = new BenchmarkResult
                        {
                            AlgorithmTypeSpeeds = firstPair.AlgorithmSpeedsTotal().Select(pair => (pair.type, speedSums[pair.type])).ToList(),
                            Success             = true
                        };
                    }
                }
                catch (Exception e)
                {
                    Logger.Warn(_logGroup, $"benchmarking AlgorithmSpeedsTotal error {e.Message}");
                }

                // return API result
                return(result);
            }
        }
Ejemplo n.º 17
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            // determine benchmark time
            // settup times
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                30, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var algoName    = AlgorithmName(_algorithmType);
            var logfileName = $"{_devices}_{algoName}_bench.txt";

            var commandLine       = CreateCommandLine(DemoUser.BTC) + $" --nocolor --logfile {logfileName}";
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            //first delete benchmark file if it exists
            File.Delete(Path.Combine(binCwd, logfileName));

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            bp.CheckData = (string data) =>
            {
                // we can't read from stdout or stderr, read from logs later
                return(new BenchmarkResult());
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5);
            var benchmarkWait    = TimeSpan.FromMilliseconds(1000);
            var t = await MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            // look for log file and parse that
            try
            {
                var benchHashes      = 0d;
                var benchIters       = 0;
                var benchHashResult  = 0d;
                var targetBenchIters = Math.Max(1, (int)Math.Floor(benchmarkTime / 10d));

                var logFullPath = Path.Combine(binCwd, logfileName);
                var lines       = File.ReadLines(logFullPath);
                foreach (var line in lines)
                {
                    var hashrateFoundPair = BenchmarkHelpers.TryGetHashrateAfter(line, "I/s");
                    var hashrate          = hashrateFoundPair.Item1;
                    var found             = hashrateFoundPair.Item2;

                    if (found)
                    {
                        benchHashes += hashrate;
                        benchIters++;

                        benchHashResult = (benchHashes / benchIters) * (1 - DevFee * 0.01);
                    }
                }

                var success = benchHashResult > 0d;
                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = success
                });
            }
            catch (Exception e)
            {
                Logger.Error(_logGroup, $"Benchmarking failed: {e.Message}");
            }
            return(t);
        }
Ejemplo n.º 18
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            // determine benchmark time
            // settup times
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                40, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var urlWithPort = GetLocationUrl(_algorithmType, _miningLocation, NhmConectionType.STRATUM_TCP);
            var algo        = AlgorithmName(_algorithmType);

            var commandLine       = $"--algo {algo} --url={urlWithPort} --user {MinerToolkit.DemoUserBTC} --devices {_devices} {_extraLaunchParameters}";
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            var benchHashes      = 0d;
            var benchIters       = 0;
            var benchHashResult  = 0d;      // Not too sure what this is..
            var after            = $"GPU#"; //if multiple benchmark add gpu cuda id
            var targetBenchIters = Math.Max(1, (int)Math.Floor(benchmarkTime / 20d));

            bp.CheckData = (string data) =>
            {
                var hasHashRate = data.Contains(after) && data.Contains("-");

                if (!hasHashRate)
                {
                    return new BenchmarkResult {
                               AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                                   new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                               }, Success = false
                    }
                }
                ;

                var hashrateFoundPair = data.TryGetHashrateAfter("-");
                var hashrate          = hashrateFoundPair.Item1;
                var found             = hashrateFoundPair.Item2;

                benchHashes += hashrate;
                benchIters++;

                benchHashResult = (benchHashes / benchIters) * (1 - DevFee * 0.01);

                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = benchIters >= targetBenchIters
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 10);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 19
0
        public override async Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            using (var tickCancelSource = new CancellationTokenSource())
            {
                // determine benchmark time
                // settup times
                int benchmarkTime;
                var isDaggerNvidia = _miningPairs.Any(mp => mp.Algorithm.FirstAlgorithmType == AlgorithmType.DaggerHashimoto) && _miningPairs.Any(mp => mp.Device.DeviceType == DeviceType.NVIDIA);
                if (isDaggerNvidia || _miningPairs.Any(mp => mp.Algorithm.FirstAlgorithmType == AlgorithmType.KAWPOW))
                {
                    benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                        180, 240, 300
                    }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);
                }
                else
                {
                    benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                        60, 120, 180
                    }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);
                }
                var maxTicks = MinerBenchmarkTimeSettings.ParseBenchmarkTicks(new List <int> {
                    1, 3, 9
                }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);
                var maxTicksEnabled = MinerBenchmarkTimeSettings.MaxTicksEnabled && !isDaggerNvidia;

                //// use demo user and disable the watchdog
                var commandLine = MiningCreateCommandLine();
                var(binPath, binCwd) = GetBinAndCwdPaths();
                Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
                Logger.Info(_logGroup, $"Benchmarking settings: time={benchmarkTime} ticks={maxTicks} ticksEnabled={maxTicksEnabled}");
                Logger.Info(_logGroup, $"Benchmarking is Dagger NVIDIA LHR {isDaggerNvidia}");
                var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());
                // disable line readings and read speeds from API
                bp.CheckData = null;

                var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5);
                var benchmarkWait    = TimeSpan.FromMilliseconds(500);
                var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop, tickCancelSource.Token);

                var stoppedAfterTicks = false;
                var validTicks        = 0;
                var ticks             = benchmarkTime / 10; // on each 10 seconds tick
                var result            = new BenchmarkResult();
                var benchmarkApiData  = new List <ApiData>();
                int delay             = maxTicksEnabled ? (benchmarkTime / maxTicks) * 1000 : 10 * 1000;


                for (var tick = 0; tick < ticks; tick++)
                {
                    if (t.IsCompleted || t.IsCanceled || stop.IsCancellationRequested)
                    {
                        break;
                    }
                    await Task.Delay(delay, stop); // 10 seconds delay

                    if (t.IsCompleted || t.IsCanceled || stop.IsCancellationRequested)
                    {
                        break;
                    }

                    var ad = await GetMinerStatsDataAsync();

                    var adTotal     = ad.AlgorithmSpeedsTotal();
                    var isTickValid = adTotal.Count > 0 && adTotal.All(pair => pair.speed > 0);
                    benchmarkApiData.Add(ad);
                    if (isTickValid)
                    {
                        ++validTicks;
                    }
                    if (maxTicksEnabled && validTicks >= maxTicks)
                    {
                        stoppedAfterTicks = true;
                        break;
                    }
                }
                // await benchmark task
                if (stoppedAfterTicks)
                {
                    try
                    {
                        tickCancelSource.Cancel();
                    }
                    catch
                    { Logger.Error(_logGroup, "tickCancelSource error"); }
                }
                await t;
                if (stop.IsCancellationRequested)
                {
                    return(t.Result);
                }

                // calc speeds
                // TODO calc std deviaton to reduce invalid benches
                try
                {
                    var nonZeroSpeeds = benchmarkApiData.Where(ad => ad.AlgorithmSpeedsTotal().Count > 0 && ad.AlgorithmSpeedsTotal().All(pair => pair.speed > 0))
                                        .Select(ad => (ad, ad.AlgorithmSpeedsTotal().Count)).ToList();
                    var speedsFromTotals = new List <(AlgorithmType type, double speed)>();
                    if (nonZeroSpeeds.Count > 0)
                    {
                        var maxAlgoPiarsCount = nonZeroSpeeds.Select(adCount => adCount.Count).Max();
                        var sameCountApiDatas = nonZeroSpeeds.Where(adCount => adCount.Count == maxAlgoPiarsCount).Select(adCount => adCount.ad).ToList();
                        var firstPair         = sameCountApiDatas.FirstOrDefault();
                        var speedSums         = firstPair.AlgorithmSpeedsTotal().Select(pair => new KeyValuePair <AlgorithmType, double>(pair.type, 0.0)).ToDictionary(x => x.Key, x => x.Value);
                        // sum
                        foreach (var ad in sameCountApiDatas)
                        {
                            foreach (var pair in ad.AlgorithmSpeedsTotal())
                            {
                                speedSums[pair.type] += pair.speed;
                            }
                        }
                        // average
                        foreach (var algoId in speedSums.Keys.ToArray())
                        {
                            speedSums[algoId] /= sameCountApiDatas.Count;
                        }
                        result = new BenchmarkResult
                        {
                            AlgorithmTypeSpeeds = firstPair.AlgorithmSpeedsTotal().Select(pair => (pair.type, speedSums[pair.type])).ToList(),
                            Success             = true
                        };
                    }
                }
                catch (Exception e)
                {
                    Logger.Warn(_logGroup, $"benchmarking AlgorithmSpeedsTotal error {e.Message}");
                }

                // return API result
                return(result);
            }
        }