Attempt to address CPU load

This commit is contained in:
kayos@tcp.direct 2022-09-23 15:57:46 -07:00
parent 2461423589
commit cb4f28f162
Signed by: kayos
GPG Key ID: 4B841471B4BEE979
2 changed files with 9 additions and 6 deletions

View File

@ -95,6 +95,7 @@ func (p5 *Swamp) mapBuilder() {
p5.Pending <- p
}
default:
time.Sleep(500 * time.Millisecond)
p5.recycling()
}
}
@ -153,7 +154,7 @@ func (p5 *Swamp) jobSpawner() {
}
default:
time.Sleep(25 * time.Millisecond)
time.Sleep(500 * time.Millisecond)
count := p5.recycling()
buf := pools.CopABuffer.Get().(*strings.Builder)
buf.WriteString("recycled ")

View File

@ -2,6 +2,7 @@ package prox5
import (
"bufio"
"fmt"
"io"
"os"
"strings"
@ -63,13 +64,13 @@ func (p5 *Swamp) LoadSingleProxy(sock string) (ok bool) {
return
}
func (p5 *Swamp) loadSingleProxy(sock string) {
func (p5 *Swamp) loadSingleProxy(sock string) error {
for {
select {
case inChan <- sock:
return
return nil
default:
time.Sleep(1 * time.Second)
return fmt.Errorf("cannot load %s, channel is full", sock)
}
}
}
@ -86,9 +87,10 @@ func (p5 *Swamp) LoadMultiLineString(socks string) int {
var count int
scan := bufio.NewScanner(strings.NewReader(socks))
for scan.Scan() {
if p5.LoadSingleProxy(scan.Text()) {
count++
if err := p5.loadSingleProxy(scan.Text()); err != nil {
continue
}
count++
}
return count
}