gitlab.com/SiaPrime/SiaPrime@v1.4.1/modules/renter/consts.go (about)

     1  package renter
     2  
     3  import (
     4  	"time"
     5  
     6  	"gitlab.com/SiaPrime/SiaPrime/build"
     7  )
     8  
     9  // Version and system parameters.
    10  const (
    11  	// persistVersion defines the Sia version that the persistence was
    12  	// last updated
    13  	persistVersion = "1.4.0"
    14  )
    15  
    16  // Default redundancy parameters.
    17  var (
    18  	// defaultDataPieces is the number of data pieces per erasure-coded chunk
    19  	defaultDataPieces = build.Select(build.Var{
    20  		Dev:      1,
    21  		Standard: 10,
    22  		Testing:  1,
    23  	}).(int)
    24  
    25  	// defaultParityPieces is the number of parity pieces per erasure-coded
    26  	// chunk
    27  	defaultParityPieces = build.Select(build.Var{
    28  		Dev:      1,
    29  		Standard: 20,
    30  		Testing:  8,
    31  	}).(int)
    32  
    33  	// RepairThreshold defines the threshold at which the renter decides to
    34  	// repair a file. The renter will start repairing the file when the health
    35  	// is equal to or greater than this value.
    36  	RepairThreshold = build.Select(build.Var{
    37  		Dev:      0.25,
    38  		Standard: 0.25,
    39  		Testing:  0.25,
    40  	}).(float64)
    41  )
    42  
    43  // Default memory usage parameters.
    44  var (
    45  	// defaultMemory establishes the default amount of memory that the renter
    46  	// will use when performing uploads and downloads. The mapping is currently
    47  	// not perfect due to GC overhead and other places where we don't count all
    48  	// of the memory usage accurately.
    49  	defaultMemory = build.Select(build.Var{
    50  		Dev:      uint64(1 << 28),     // 256 MiB
    51  		Standard: uint64(3 * 1 << 28), // 768 MiB
    52  		Testing:  uint64(1 << 17),     // 128 KiB - 4 KiB sector size, need to test memory exhaustion
    53  	}).(uint64)
    54  
    55  	// initialStreamerCacheSize defines the cache size that each streamer will
    56  	// start using when it is created. A lower initial cache size will mean that
    57  	// it will take more requests / round trips for the cache to grow, however
    58  	// the cache size gets set to at least 2x the minimum read size initially
    59  	// anyway, which means any application doing very large reads is going to
    60  	// automatically have the cache size stepped up without having to do manual
    61  	// growth.
    62  	initialStreamerCacheSize = build.Select(build.Var{
    63  		Dev:      int64(1 << 13), // 8 KiB
    64  		Standard: int64(1 << 18), // 256 KiB
    65  		Testing:  int64(1 << 10), // 1 KiB
    66  	}).(int64)
    67  
    68  	// maxStreamerCacheSize defines the maximum cache size that each streamer
    69  	// will use before it no longer increases its own cache size. The value has
    70  	// been set fairly low because some applications like mpv will request very
    71  	// large buffer sizes, taking as much data as fast as they can. This results
    72  	// in the cache size on Sia's end growing to match the size of the
    73  	// requesting application's buffer, and harms seek times. Maintaining a low
    74  	// maximum ensures that runaway growth is kept under at least a bit of
    75  	// control.
    76  	//
    77  	// This would be best resolved by knowing the actual bitrate of the data
    78  	// being fed to the user instead of trying to guess a bitrate, however as of
    79  	// time of writing we don't have an easy way to get that information.
    80  	maxStreamerCacheSize = build.Select(build.Var{
    81  		Dev:      int64(1 << 20), // 1 MiB
    82  		Standard: int64(1 << 25), // 32 MiB
    83  		Testing:  int64(1 << 13), // 8 KiB
    84  	}).(int64)
    85  )
    86  
    87  // Default bandwidth usage parameters.
    88  const (
    89  	// DefaultMaxDownloadSpeed is set to zero to indicate no limit, the user
    90  	// can set a custom MaxDownloadSpeed through the API
    91  	DefaultMaxDownloadSpeed = 0
    92  
    93  	// DefaultMaxUploadSpeed is set to zero to indicate no limit, the user
    94  	// can set a custom MaxUploadSpeed through the API
    95  	DefaultMaxUploadSpeed = 0
    96  )
    97  
    98  // Naming conventions for code readability.
    99  const (
   100  	// destinationTypeSeekStream is the destination type used for downloads
   101  	// from the /renter/stream endpoint.
   102  	destinationTypeSeekStream = "httpseekstream"
   103  
   104  	// memoryPriorityLow is used to request low priority memory
   105  	memoryPriorityLow = false
   106  
   107  	// memoryPriorityHigh is used to request high priority memory
   108  	memoryPriorityHigh = true
   109  )
   110  
   111  // Constants that tune the health and repair processes.
   112  const (
   113  	// maxStuckChunksInHeap is the maximum number of stuck chunks that the
   114  	// repair code will add to the heap at a time
   115  	maxStuckChunksInHeap = 5
   116  )
   117  
   118  // Constants that tune the health and repair processes.
   119  var (
   120  	// healthCheckInterval defines the maximum amount of time that should pass
   121  	// in between checking the health of a file or directory.
   122  	healthCheckInterval = build.Select(build.Var{
   123  		Dev:      15 * time.Minute,
   124  		Standard: 1 * time.Hour,
   125  		Testing:  5 * time.Second,
   126  	}).(time.Duration)
   127  
   128  	// healthLoopErrorSleepDuration indicates how long the health loop should
   129  	// sleep before retrying if there is an error preventing progress.
   130  	healthLoopErrorSleepDuration = build.Select(build.Var{
   131  		Dev:      10 * time.Second,
   132  		Standard: 30 * time.Second,
   133  		Testing:  3 * time.Second,
   134  	}).(time.Duration)
   135  
   136  	// maxRepairLoopTime indicates the maximum amount of time that the repair
   137  	// loop will spend popping chunks off of the repair heap.
   138  	maxRepairLoopTime = build.Select(build.Var{
   139  		Dev:      1 * time.Minute,
   140  		Standard: 15 * time.Minute,
   141  		Testing:  15 * time.Second,
   142  	}).(time.Duration)
   143  
   144  	// maxSuccessfulStuckRepairFiles is the maximum number of files that the
   145  	// stuck loop will track when there is a successful stuck chunk repair
   146  	maxSuccessfulStuckRepairFiles = build.Select(build.Var{
   147  		Dev:      3,
   148  		Standard: 20,
   149  		Testing:  2,
   150  	}).(int)
   151  
   152  	// maxUploadHeapChunks is the maximum number of chunks that we should add to
   153  	// the upload heap. This also will be used as the target number of chunks to
   154  	// add to the upload heap which which will mean for small directories we
   155  	// will add multiple directories.
   156  	maxUploadHeapChunks = build.Select(build.Var{
   157  		Dev:      25,
   158  		Standard: 250,
   159  		Testing:  5,
   160  	}).(int)
   161  
   162  	// minUploadHeapSize is the minimum number of chunks we want in the upload
   163  	// heap before trying to add more in order to maintain back pressure on the
   164  	// workers, repairs, and uploads.
   165  	minUploadHeapSize = build.Select(build.Var{
   166  		Dev:      5,
   167  		Standard: 20,
   168  		Testing:  1,
   169  	}).(int)
   170  
   171  	// offlineCheckFrequency is how long the renter will wait to check the
   172  	// online status if it is offline.
   173  	offlineCheckFrequency = build.Select(build.Var{
   174  		Dev:      3 * time.Second,
   175  		Standard: 10 * time.Second,
   176  		Testing:  250 * time.Millisecond,
   177  	}).(time.Duration)
   178  
   179  	// repairLoopResetFrequency is the frequency with which the repair loop will
   180  	// reset entirely, pushing the root directory back on top. This is a
   181  	// temporary measure to ensure that even if a user is continuously
   182  	// uploading, the repair heap is occasionally reset to push the root
   183  	// directory on top.
   184  	repairLoopResetFrequency = build.Select(build.Var{
   185  		Dev:      15 * time.Minute,
   186  		Standard: 1 * time.Hour,
   187  		Testing:  40 * time.Second,
   188  	}).(time.Duration)
   189  
   190  	// repairStuckChunkInterval defines how long the renter sleeps between
   191  	// trying to repair a stuck chunk. The uploadHeap prioritizes stuck chunks
   192  	// so this interval is to allow time for unstuck chunks to be repaired.
   193  	// Ideally the uploadHeap is spending 95% of its time repairing unstuck
   194  	// chunks.
   195  	repairStuckChunkInterval = build.Select(build.Var{
   196  		Dev:      90 * time.Second,
   197  		Standard: 10 * time.Minute,
   198  		Testing:  5 * time.Second,
   199  	}).(time.Duration)
   200  
   201  	// stuckLoopErrorSleepDuration indicates how long the stuck loop should
   202  	// sleep before retrying if there is an error preventing progress.
   203  	stuckLoopErrorSleepDuration = build.Select(build.Var{
   204  		Dev:      10 * time.Second,
   205  		Standard: 30 * time.Second,
   206  		Testing:  3 * time.Second,
   207  	}).(time.Duration)
   208  
   209  	// uploadAndRepairErrorSleepDuration indicates how long a repair process
   210  	// should sleep before retrying if there is an error fetching the metadata
   211  	// of the root directory of the renter's filesystem.
   212  	uploadAndRepairErrorSleepDuration = build.Select(build.Var{
   213  		Dev:      20 * time.Second,
   214  		Standard: 15 * time.Minute,
   215  		Testing:  3 * time.Second,
   216  	}).(time.Duration)
   217  
   218  	// uploadPollTimeout defines the maximum amount of time the renter will poll
   219  	// for an upload to complete.
   220  	uploadPollTimeout = build.Select(build.Var{
   221  		Dev:      5 * time.Minute,
   222  		Standard: 60 * time.Minute,
   223  		Testing:  10 * time.Second,
   224  	}).(time.Duration)
   225  
   226  	// uploadPollInterval defines the renter's polling interval when waiting for
   227  	// file to upload.
   228  	uploadPollInterval = build.Select(build.Var{
   229  		Dev:      5 * time.Second,
   230  		Standard: 5 * time.Second,
   231  		Testing:  1 * time.Second,
   232  	}).(time.Duration)
   233  
   234  	// snapshotSyncSleepDuration defines how long the renter sleeps between
   235  	// trying to synchronize snapshots across hosts.
   236  	snapshotSyncSleepDuration = build.Select(build.Var{
   237  		Dev:      10 * time.Second,
   238  		Standard: 5 * time.Minute,
   239  		Testing:  5 * time.Second,
   240  	}).(time.Duration)
   241  )
   242  
   243  // Constants that tune the worker swarm.
   244  var (
   245  	// downloadFailureCooldown defines how long to wait for a worker after a
   246  	// worker has experienced a download failure.
   247  	downloadFailureCooldown = time.Second * 3
   248  
   249  	// maxConsecutivePenalty determines how many times the timeout/cooldown for
   250  	// being a bad host can be doubled before a maximum cooldown is reached.
   251  	maxConsecutivePenalty = build.Select(build.Var{
   252  		Dev:      4,
   253  		Standard: 10,
   254  		Testing:  3,
   255  	}).(int)
   256  
   257  	// uploadFailureCooldown is how long a worker will wait initially if an
   258  	// upload fails. This number is prime to increase the chance to avoid
   259  	// intersecting with regularly occurring events which may cause failures.
   260  	uploadFailureCooldown = build.Select(build.Var{
   261  		Dev:      time.Second * 7,
   262  		Standard: time.Second * 61,
   263  		Testing:  time.Second,
   264  	}).(time.Duration)
   265  
   266  	// workerPoolUpdateTimeout is the amount of time that can pass before the
   267  	// worker pool should be updated.
   268  	workerPoolUpdateTimeout = build.Select(build.Var{
   269  		Dev:      30 * time.Second,
   270  		Standard: 5 * time.Minute,
   271  		Testing:  3 * time.Second,
   272  	}).(time.Duration)
   273  )
   274  
   275  // Constants which don't fit into another category very well.
   276  const (
   277  	// defaultFilePerm defines the default permissions used for a new file if no
   278  	// permissions are supplied.
   279  	defaultFilePerm = 0666
   280  
   281  	// PriceEstimationSafetyFactor is the factor of safety used in the price
   282  	// estimation to account for any missed costs
   283  	PriceEstimationSafetyFactor = 1.2
   284  )
   285  
   286  // Deprecated consts.
   287  //
   288  // TODO: Tear out all related code and drop these consts.
   289  const (
   290  	// DefaultStreamCacheSize is the default cache size of the /renter/stream cache in
   291  	// chunks, the user can set a custom cache size through the API
   292  	DefaultStreamCacheSize = 2
   293  )