github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/util/testutil/latency_config.go (about)

     1  package testutil
     2  
     3  import "time"
     4  
     5  type LatencyConfig struct {
     6  	BlockstoreLatency time.Duration
     7  	NetworkLatency    time.Duration
     8  	RoutingLatency    time.Duration
     9  }
    10  
    11  func (c LatencyConfig) AllInstantaneous() LatencyConfig {
    12  	// Could use a zero value but whatever. Consistency of interface
    13  	c.NetworkLatency = 0
    14  	c.RoutingLatency = 0
    15  	c.BlockstoreLatency = 0
    16  	return c
    17  }
    18  
    19  func (c LatencyConfig) NetworkNYtoSF() LatencyConfig {
    20  	c.NetworkLatency = 20 * time.Millisecond
    21  	return c
    22  }
    23  
    24  func (c LatencyConfig) NetworkIntraDatacenter2014() LatencyConfig {
    25  	c.NetworkLatency = 250 * time.Microsecond
    26  	return c
    27  }
    28  
    29  func (c LatencyConfig) BlockstoreFastSSD2014() LatencyConfig {
    30  	const iops = 100000
    31  	c.BlockstoreLatency = (1 / iops) * time.Second
    32  	return c
    33  }
    34  
    35  func (c LatencyConfig) BlockstoreSlowSSD2014() LatencyConfig {
    36  	c.BlockstoreLatency = 150 * time.Microsecond
    37  	return c
    38  }
    39  
    40  func (c LatencyConfig) Blockstore7200RPM() LatencyConfig {
    41  	c.BlockstoreLatency = 8 * time.Millisecond
    42  	return c
    43  }
    44  
    45  func (c LatencyConfig) RoutingSlow() LatencyConfig {
    46  	c.RoutingLatency = 200 * time.Millisecond
    47  	return c
    48  }