Browse Source

Add broadcast stats

pool
Sammy Libre 8 years ago
parent
commit
8b096dbeb8
  1. 22
      go-pool/stratum/handlers.go

22
go-pool/stratum/handlers.go

@ -4,7 +4,9 @@ import (
"log" "log"
"regexp" "regexp"
"strings" "strings"
"sync"
"sync/atomic" "sync/atomic"
"time"
"../util" "../util"
) )
@ -106,24 +108,34 @@ func (s *StratumServer) broadcastNewJobs() {
defer s.sessionsMu.RUnlock() defer s.sessionsMu.RUnlock()
count := len(s.sessions) count := len(s.sessions)
log.Printf("Broadcasting new jobs to %d miners", count) log.Printf("Broadcasting new jobs to %d miners", count)
bcast := make(chan int, 1024*16) start := time.Now()
n := 0 slots := make(chan bool, 1024*16)
var ok, fails int64
var wg sync.WaitGroup
for m := range s.sessions { for m := range s.sessions {
n++ wg.Add(1)
bcast <- n slots <- true
go func(cs *Session) { go func(cs *Session) {
reply := cs.getJob(t) reply := cs.getJob(t)
err := cs.pushMessage("job", &reply) err := cs.pushMessage("job", &reply)
<-bcast <-slots
if err != nil { if err != nil {
log.Printf("Job transmit error to %s: %v", cs.ip, err) log.Printf("Job transmit error to %s: %v", cs.ip, err)
atomic.AddInt64(&fails, 1)
wg.Done()
s.removeSession(cs) s.removeSession(cs)
} else { } else {
atomic.AddInt64(&ok, 1)
s.setDeadline(cs.conn) s.setDeadline(cs.conn)
wg.Done()
} }
}(m) }(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) { func (s *StratumServer) refreshBlockTemplate(bcast bool) {

Loading…
Cancel
Save