mirror of
https://github.com/kvazar-network/keva-stratum.git
synced 2025-01-13 08:37:57 +00:00
parent
acb710f532
commit
8ea446f333
@ -4,9 +4,7 @@ import (
|
||||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"../util"
|
||||
)
|
||||
@ -108,34 +106,24 @@ func (s *StratumServer) broadcastNewJobs() {
|
||||
defer s.sessionsMu.RUnlock()
|
||||
count := len(s.sessions)
|
||||
log.Printf("Broadcasting new jobs to %d miners", count)
|
||||
start := time.Now()
|
||||
slots := make(chan bool, 1024*16)
|
||||
var ok, fails int64
|
||||
var wg sync.WaitGroup
|
||||
bcast := make(chan int, 1024*16)
|
||||
n := 0
|
||||
|
||||
for m := range s.sessions {
|
||||
wg.Add(1)
|
||||
slots <- true
|
||||
|
||||
n++
|
||||
bcast <- n
|
||||
go func(cs *Session) {
|
||||
reply := cs.getJob(t)
|
||||
err := cs.pushMessage("job", &reply)
|
||||
<-slots
|
||||
|
||||
<-bcast
|
||||
if err != nil {
|
||||
log.Printf("Job transmit error to %s: %v", cs.ip, err)
|
||||
atomic.AddInt64(&fails, 1)
|
||||
wg.Done()
|
||||
s.removeSession(cs)
|
||||
} else {
|
||||
atomic.AddInt64(&ok, 1)
|
||||
s.setDeadline(cs.conn)
|
||||
wg.Done()
|
||||
}
|
||||
}(m)
|
||||
}
|
||||
wg.Wait()
|
||||
log.Printf("Done jobs broadcast in %s for %d/%d/%d miners", time.Since(start), count, ok, fails)
|
||||
}
|
||||
|
||||
func (s *StratumServer) refreshBlockTemplate(bcast bool) {
|
||||
|
Loading…
Reference in New Issue
Block a user