Attempt to address CPU load
This commit is contained in:
parent
2461423589
commit
cb4f28f162
|
@ -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 ")
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue