From 51ac7cc8beb582f5c80d81bfb13e13b09e915c90 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 15 Feb 2025 11:21:35 +0800 Subject: [PATCH] Improved and optimized speedtest --- .../ServiceLib/Services/SpeedtestService.cs | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/v2rayN/ServiceLib/Services/SpeedtestService.cs b/v2rayN/ServiceLib/Services/SpeedtestService.cs index ede19c1e..51d57db9 100644 --- a/v2rayN/ServiceLib/Services/SpeedtestService.cs +++ b/v2rayN/ServiceLib/Services/SpeedtestService.cs @@ -58,11 +58,11 @@ namespace ServiceLib.Services break; case ESpeedActionType.Speedtest: - await RunMixedTestAsync(lstSelected, 1, exitLoopKey); + await RunMixedTestAsync(lstSelected, 1, true, exitLoopKey); break; case ESpeedActionType.Mixedtest: - await RunMixedTestAsync(lstSelected, 6, exitLoopKey); + await RunMixedTestAsync(lstSelected, 6, true, exitLoopKey); break; } } @@ -177,7 +177,15 @@ namespace ServiceLib.Services } UpdateFunc("", string.Format(ResUI.SpeedtestingTestFailedPart, lstFailed.Count)); - await RunRealPingBatchAsync(lstFailed, exitLoopKey, pageSizeNext); + + if (pageSizeNext > 6) + { + await RunRealPingBatchAsync(lstFailed, exitLoopKey, pageSizeNext); + } + else + { + await RunMixedTestAsync(lstSelected, 6, false, exitLoopKey); + } } } @@ -226,7 +234,7 @@ namespace ServiceLib.Services return true; } - private async Task RunMixedTestAsync(List selecteds, int concurrencyCount, string exitLoopKey) + private async Task RunMixedTestAsync(List selecteds, int concurrencyCount, bool blSpeedTest, string exitLoopKey) { using var concurrencySemaphore = new SemaphoreSlim(concurrencyCount); var downloadHandle = new DownloadService(); @@ -252,9 +260,12 @@ namespace ServiceLib.Services pid = await CoreHandler.Instance.LoadCoreConfigSpeedtest(it); if (pid > 0) { - await Task.Delay(1000); + await Task.Delay(500); await DoRealPing(downloadHandle, it); - await DoSpeedTest(downloadHandle, it); + if (blSpeedTest) + { + await DoSpeedTest(downloadHandle, it); + } } else {