Fix: it's not slow as shit anymore

This commit is contained in:
kayos@tcp.direct 2021-09-20 00:49:40 -07:00
parent 25f4048e70
commit 9540518c84
4 changed files with 14 additions and 3 deletions

View File

@ -12,6 +12,9 @@ func (s *Swamp) Start() error {
// tossUp feeds jobs to pond continuously
go s.jobSpawner()
s.started = true
s.mu.Lock()
s.Status = Running
s.mu.Unlock()
return nil
}

View File

@ -165,6 +165,7 @@ func NewDefaultSwamp() *Swamp {
quit: make(chan bool),
mu: &sync.RWMutex{},
Status: Paused,
}
s.swampmap = swampMap{

View File

@ -54,5 +54,10 @@ func (s *Swamp) GetRecyclingStatus() bool {
return s.swampopt.recycle
}
// TODO: Implement ways to access worker pool (pond) statistics
// GetWorkers retrieves pond worker statistics:
// * return MaxWorkers, RunningWorkers, IdleWorkers
func (s *Swamp) GetWorkers() (int, int, int) {
s.mu.RLock()
defer s.mu.RUnlock()
return s.pool.MaxWorkers(), s.pool.RunningWorkers(), s.pool.IdleWorkers()
}

View File

@ -53,10 +53,12 @@ func (s *Swamp) SetValidationTimeout(newtimeout int) {
// SetMaxWorkers set the maximum workers for proxy checking, this must be set before calling LoadProxyTXT for the first time.
func (s *Swamp) SetMaxWorkers(num int) error {
s.mu.Lock()
defer s.mu.Unlock()
if s.Status == Running {
return errors.New("can't change max workers during proxypool operation, try pausing first")
}
s.pool.Stop()
s.pool.StopAndWait()
s.swampopt.maxWorkers = num
s.pool = pond.New(s.swampopt.maxWorkers, 1000000, pond.PanicHandler(func(p interface{}) {
fmt.Println("WORKER PANIC! ", p)