Merge pull request #89 from chihaya/gc-rate

config: make reaping configurable
This commit is contained in:
Jimmy Zelinskie 2015-09-24 23:30:49 -04:00
commit 86a77b663f
4 changed files with 11 additions and 13 deletions

View file

@ -81,6 +81,8 @@ type TrackerConfig struct {
PurgeInactiveTorrents bool `json:"purge_inactive_torrents"`
Announce Duration `json:"announce"`
MinAnnounce Duration `json:"min_announce"`
ReapInterval Duration `json:"reap_interval"`
ReapRatio float64 `json:"reap_ratio"`
NumWantFallback int `json:"default_num_want"`
TorrentMapShards int `json:"torrent_map_shards"`
@ -121,6 +123,8 @@ var DefaultConfig = Config{
PurgeInactiveTorrents: true,
Announce: Duration{30 * time.Minute},
MinAnnounce: Duration{15 * time.Minute},
ReapInterval: Duration{60 * time.Second},
ReapRatio: 1.25,
NumWantFallback: 50,
TorrentMapShards: 1,

View file

@ -5,6 +5,8 @@
"purge_inactive_torrents": true,
"announce": "30m",
"min_announce": "15m",
"reap_interval": "60s",
"reap_ratio": "1.25",
"default_num_want": 50,
"torrent_map_shards": 1,
"allow_ip_spoofing": true,

View file

@ -84,9 +84,8 @@ func TestTorrentPurging(t *testing.T) {
func TestStalePeerPurging(t *testing.T) {
cfg := config.DefaultConfig
cfg.Announce = config.Duration{
Duration: 10 * time.Millisecond,
}
cfg.MinAnnounce = config.Duration{10 * time.Millisecond}
cfg.ReapInterval = config.Duration{10 * time.Millisecond}
srv, err := setupTracker(&cfg)
if err != nil {
@ -110,7 +109,7 @@ func TestStalePeerPurging(t *testing.T) {
// Add a leecher.
peer2 := makePeerParams("peer2", false)
expected := makeResponse(1, 1, peer1)
expected["interval"] = int64(0)
expected["min interval"] = int64(0)
checkAnnounce(peer2, expected, srv, t)
// Let them both expire.

View file

@ -49,8 +49,8 @@ func New(cfg *config.Config) (*Tracker, error) {
go tkr.purgeInactivePeers(
cfg.PurgeInactiveTorrents,
cfg.Announce.Duration*2,
cfg.Announce.Duration,
time.Duration(float64(cfg.MinAnnounce.Duration)*cfg.ReapRatio),
cfg.ReapInterval.Duration,
)
if cfg.ClientWhitelistEnabled {
@ -86,13 +86,6 @@ type Writer interface {
// purgeInactivePeers periodically walks the torrent database and removes
// peers that haven't announced recently.
//
// The default threshold is 2x the announce interval, which gives delayed
// peers a chance to stay alive, while ensuring the majority of responses
// contain active peers.
//
// The default interval is equal to the announce interval, since this is a
// relatively expensive operation.
func (tkr *Tracker) purgeInactivePeers(purgeEmptyTorrents bool, threshold, interval time.Duration) {
for _ = range time.NewTicker(interval).C {
before := time.Now().Add(-threshold)