github.com/uber/kraken@v0.1.4/lib/torrent/scheduler/config.go (about)

     1  // Copyright (c) 2016-2019 Uber Technologies, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  package scheduler
    15  
    16  import (
    17  	"time"
    18  
    19  	"github.com/uber/kraken/lib/torrent/scheduler/conn"
    20  	"github.com/uber/kraken/lib/torrent/scheduler/connstate"
    21  	"github.com/uber/kraken/lib/torrent/scheduler/dispatch"
    22  	"github.com/uber/kraken/utils/log"
    23  )
    24  
    25  // Config is the Scheduler configuration.
    26  type Config struct {
    27  
    28  	// SeederTTI is the duration a seeding torrent will exist without being
    29  	// read from before being cancelled.
    30  	SeederTTI time.Duration `yaml:"seeder_tti"`
    31  
    32  	// LeecherTTI is the duration a leeching torrent will exist without being
    33  	// written to before being cancelled.
    34  	LeecherTTI time.Duration `yaml:"leecher_tti"`
    35  
    36  	// ConnTTI is the duration a connection will exist without transmitting any
    37  	// needed pieces or requesting any pieces.
    38  	ConnTTI time.Duration `yaml:"conn_tti"`
    39  
    40  	// ConnTTL is the max duration a connection may exist regardless of liveness.
    41  	ConnTTL time.Duration `yaml:"conn_ttl"`
    42  
    43  	// PreemptionInterval is the interval in which the Scheduler analyzes the
    44  	// status of existing conns and determines whether to preempt them.
    45  	PreemptionInterval time.Duration `yaml:"preemption_interval"`
    46  
    47  	// EmitStatsInterval is the interval introspective stats are emitted from
    48  	// the Scheduler.
    49  	EmitStatsInterval time.Duration `yaml:"emit_stats_interval"`
    50  
    51  	// DisablePreemption disables resource preemption. Should only be used for
    52  	// testing purposes.
    53  	DisablePreemption bool `yaml:"disable_preemption"`
    54  
    55  	ProbeTimeout time.Duration `yaml:"probe_timeout"`
    56  
    57  	ConnState connstate.Config `yaml:"connstate"`
    58  
    59  	Conn conn.Config `yaml:"conn"`
    60  
    61  	Dispatch dispatch.Config `yaml:"dispatch"`
    62  
    63  	TorrentLog log.Config `yaml:"torrentlog"`
    64  	Log        log.Config `yaml:"log"`
    65  }
    66  
    67  func (c Config) applyDefaults() Config {
    68  	if c.SeederTTI == 0 {
    69  		c.SeederTTI = 5 * time.Minute
    70  	}
    71  	if c.LeecherTTI == 0 {
    72  		c.LeecherTTI = 5 * time.Minute
    73  	}
    74  	if c.ConnTTI == 0 {
    75  		c.ConnTTI = 30 * time.Second
    76  	}
    77  	if c.ConnTTL == 0 {
    78  		c.ConnTTL = time.Hour
    79  	}
    80  	if c.PreemptionInterval == 0 {
    81  		c.PreemptionInterval = 30 * time.Second
    82  	}
    83  	if c.EmitStatsInterval == 0 {
    84  		c.EmitStatsInterval = 1 * time.Second
    85  	}
    86  	if c.ProbeTimeout == 0 {
    87  		c.ProbeTimeout = 3 * time.Second
    88  	}
    89  	return c
    90  }