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 }