Скорректирован расчёт нагрузки в сторону увеличения
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"maps"
|
"maps"
|
||||||
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -322,26 +323,27 @@ func CheckChannels(pls playlist.Playlist) playlist.Playlist {
|
|||||||
|
|
||||||
// calcParameters вычисляет оптимальное количество горутин и таймаут запроса
|
// calcParameters вычисляет оптимальное количество горутин и таймаут запроса
|
||||||
func calcParameters(count int) (time.Duration, int) {
|
func calcParameters(count int) (time.Duration, int) {
|
||||||
var routines int
|
percentage := float32(runtime.NumCPU()) / 10
|
||||||
var percentage float32
|
for percentage >= 1 {
|
||||||
|
percentage *= 0.5
|
||||||
if count <= 100 {
|
|
||||||
routines = count
|
|
||||||
} else {
|
|
||||||
percentage = float32(runtime.NumCPU()) * 0.075
|
|
||||||
for percentage >= 1 {
|
|
||||||
percentage *= 0.5
|
|
||||||
}
|
|
||||||
routines = int(float32(count) * percentage)
|
|
||||||
}
|
}
|
||||||
if routines > 500 {
|
|
||||||
routines = 500
|
routines := int(float32(count) * percentage)
|
||||||
|
if routines > 1500 {
|
||||||
|
routines = 1500
|
||||||
}
|
}
|
||||||
if routines < 1 {
|
if routines < 1 {
|
||||||
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 {
|
if timeout > 10 {
|
||||||
timeout = 10
|
timeout = 10
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user