Move stats buffer size to the regular config
This commit is contained in:
parent
d5da5daa88
commit
d47cf7d4bc
3 changed files with 14 additions and 19 deletions
|
@ -14,6 +14,7 @@ import (
|
|||
|
||||
"github.com/chihaya/chihaya/config"
|
||||
"github.com/chihaya/chihaya/http"
|
||||
"github.com/chihaya/chihaya/stats"
|
||||
"github.com/chihaya/chihaya/tracker"
|
||||
|
||||
// See the README for how to import custom drivers.
|
||||
|
@ -70,6 +71,8 @@ func Boot() {
|
|||
glog.V(1).Infof("Loaded config file: %s", configPath)
|
||||
}
|
||||
|
||||
stats.DefaultBufferSize = cfg.StatsBufferSize
|
||||
|
||||
tkr, err := tracker.New(cfg)
|
||||
if err != nil {
|
||||
glog.Fatal("New: ", err)
|
||||
|
|
|
@ -66,6 +66,7 @@ type Config struct {
|
|||
MinAnnounce Duration `json:"min_announce"`
|
||||
RequestTimeout Duration `json:"request_timeout"`
|
||||
NumWantFallback int `json:"default_num_want"`
|
||||
StatsBufferSize int `json:"stats_buffer_size"`
|
||||
|
||||
NetConfig
|
||||
}
|
||||
|
@ -91,6 +92,7 @@ var DefaultConfig = Config{
|
|||
MinAnnounce: Duration{15 * time.Minute},
|
||||
RequestTimeout: Duration{10 * time.Second},
|
||||
NumWantFallback: 50,
|
||||
StatsBufferSize: 0,
|
||||
|
||||
NetConfig: NetConfig{
|
||||
AllowIPSpoofing: true,
|
||||
|
@ -120,10 +122,7 @@ func Open(path string) (*Config, error) {
|
|||
|
||||
// Decode casts an io.Reader into a JSONDecoder and decodes it into a *Config.
|
||||
func Decode(r io.Reader) (*Config, error) {
|
||||
conf := &Config{}
|
||||
err := json.NewDecoder(r).Decode(conf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return conf, nil
|
||||
conf := DefaultConfig
|
||||
err := json.NewDecoder(r).Decode(&conf)
|
||||
return &conf, err
|
||||
}
|
||||
|
|
|
@ -6,10 +6,7 @@
|
|||
// BitTorrent tracker.
|
||||
package stats
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"time"
|
||||
)
|
||||
import "time"
|
||||
|
||||
const (
|
||||
Announce = iota
|
||||
|
@ -40,14 +37,10 @@ const (
|
|||
// channel for broadcasting events unless specified otherwise via a command
|
||||
// line flag.
|
||||
var (
|
||||
DefaultStats *Stats
|
||||
DefaultChanSizes int
|
||||
DefaultStats *Stats
|
||||
DefaultBufferSize int
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.IntVar(&DefaultChanSizes, "stats_chan_sizes", 0, "specifies the size of chans used to collect stats")
|
||||
}
|
||||
|
||||
type PeerStats struct {
|
||||
// Stats for all peers.
|
||||
Current uint64 `json:"current"` // Current total peer count.
|
||||
|
@ -246,7 +239,7 @@ func (s *Stats) handlePeerEvent(ps *PeerStats, event int) {
|
|||
// RecordEvent broadcasts an event to the default stats queue.
|
||||
func RecordEvent(event int) {
|
||||
if DefaultStats == nil {
|
||||
DefaultStats = New(DefaultChanSizes)
|
||||
DefaultStats = New(DefaultBufferSize)
|
||||
}
|
||||
|
||||
DefaultStats.RecordEvent(event)
|
||||
|
@ -255,7 +248,7 @@ func RecordEvent(event int) {
|
|||
// RecordPeerEvent broadcasts a peer event to the default stats queue.
|
||||
func RecordPeerEvent(event int, ipv6 bool) {
|
||||
if DefaultStats == nil {
|
||||
DefaultStats = New(DefaultChanSizes)
|
||||
DefaultStats = New(DefaultBufferSize)
|
||||
}
|
||||
|
||||
DefaultStats.RecordPeerEvent(event, ipv6)
|
||||
|
@ -264,7 +257,7 @@ func RecordPeerEvent(event int, ipv6 bool) {
|
|||
// RecordTiming broadcasts a timing event to the default stats queue.
|
||||
func RecordTiming(event int, duration time.Duration) {
|
||||
if DefaultStats == nil {
|
||||
DefaultStats = New(DefaultChanSizes)
|
||||
DefaultStats = New(DefaultBufferSize)
|
||||
}
|
||||
|
||||
DefaultStats.RecordTiming(event, duration)
|
||||
|
|
Loading…
Reference in a new issue