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