From 4cbdd41b7c35923dafdf0019d5b1e1bb4ab33a95 Mon Sep 17 00:00:00 2001 From: AnthonyAxenov Date: Sat, 10 May 2025 18:35:02 +0800 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=20=D1=80=D0=B0=D1=81?= =?UTF-8?q?=D1=87=D1=91=D1=82=20=D0=BD=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=B2=20=D1=81=D1=82=D0=BE=D1=80=D0=BE=D0=BD=D1=83=20?= =?UTF-8?q?=D1=83=D0=B2=D0=B5=D0=BB=D0=B8=D1=87=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/checker/checker.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/app/checker/checker.go b/app/checker/checker.go index 0cb241d..60a5801 100644 --- a/app/checker/checker.go +++ b/app/checker/checker.go @@ -18,6 +18,7 @@ import ( "io" "log" "maps" + "math" "math/rand" "net/http" "os" @@ -322,26 +323,27 @@ func CheckChannels(pls playlist.Playlist) playlist.Playlist { // calcParameters вычисляет оптимальное количество горутин и таймаут запроса func calcParameters(count int) (time.Duration, int) { - var routines int - var percentage float32 - - if count <= 100 { - routines = count - } else { - percentage = float32(runtime.NumCPU()) * 0.075 - for percentage >= 1 { - percentage *= 0.5 - } - routines = int(float32(count) * percentage) + percentage := float32(runtime.NumCPU()) / 10 + for percentage >= 1 { + percentage *= 0.5 } - if routines > 500 { - routines = 500 + + routines := int(float32(count) * percentage) + if routines > 1500 { + routines = 1500 } if routines < 1 { routines = 1 } - timeout := 10 / float32(count) * 150 + var digits int + x := count + for x >= 10 { + digits++ + x /= 10 + } + + timeout := int(math.Ceil(math.Pow(10, float64(digits)) / float64(count) * 15)) if timeout > 10 { timeout = 10 }