<commit_before>// poolc.go 连接池为 backend 存放来自 frontend 之间的连接

package trafcacc

import (
	"encoding/gob"
	"sync"

	log "github.com/Sirupsen/logrus"
)

// poole holds connections from frontend for backend
type poole struct {
	cond *sync.Cond
	pl   []*gob.Encoder
	id   int
}

func newPoole() *poole {
	return &poole{cond: sync.NewCond(&sync.Mutex{})}
}

func (p *poole) add(c *gob.Encoder) {
	p.cond.L.Lock()
	p.pl = append(p.pl, c)
	p.cond.L.Unlock()
	p.cond.Broadcast()
}

func (p *poole) next() *gob.Encoder {
	p.cond.L.Lock()
	for len(p.pl) == 0 {
		log.WithFields(log.Fields{
			"poolen": len(p.pl),
		}).Debugln("wait for connections from frontend")
		p.cond.Wait()
	}
	defer p.cond.L.Unlock()
	p.id++
	return p.pl[p.id%len(p.pl)]<commit_msg>Update poole.go<commit_after>// poolc.go 连接池为 backend 存放来自 frontend 之间的连接

package trafcacc

import (
	"encoding/gob"
	"math/rand"
	"sync"
	
	log "github.com/Sirupsen/logrus"
)

// poole holds connections from frontend for backend
type poole struct {
	cond *sync.Cond
	pl   []*gob.Encoder
	id   int
}

func newPoole() *poole {
	return &poole{cond: sync.NewCond(&sync.Mutex{})}
}

func (p *poole) add(c *gob.Encoder) {
	p.cond.L.Lock()
	p.pl = append(p.pl, c)
	p.cond.L.Unlock()
	p.cond.Broadcast()
}

func (p *poole) next() *gob.Encoder {
	p.cond.L.Lock()
	for len(p.pl) == 0 {
		log.WithFields(log.Fields{
			"poolen": len(p.pl),
		}).Debugln("wait for connections from frontend")
		p.cond.Wait()
	}
	defer p.cond.L.Unlock()
	p.id += uint32(rand.Intn(int(p.end)))
	return p.pl[p.id%len(p.pl)]
{'fraction_non_alphanumeric': 0.17803768680961662, 'fraction_numerical': 0.002599090318388564, 'mean_word_length': 3.5970149253731343, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7338628', 'n_tokens_mistral': 704, 'n_tokens_neox': 693, 'n_words': 142}