Documentation
¶
Index ¶
- Constants
- func Benchmark(ctx context.Context, base, query string, times int) (time.Duration, error)
- func ClearBenchmarkCache()
- func GetDefaultMirror(mirrors []string) string
- func GetTheFastestMirror(mirrors []string, testURL string) (string, error)
- func GetTheFastestMirrorAsync(distType int, mirrors []string, testURL string, ...)
- func GetTheFastestMirrorWithCache(distType int, mirrors []string, testURL string) (string, error)
- type AsyncBenchmarkCallback
- type AsyncBenchmarkResult
- type BenchmarkCache
- type CachedResult
- type Result
- type Results
Constants ¶
const ( // Configuration constants BenchmarkMaxTimeout = 150 * time.Second // detect resource timeout BenchmarkMaxTries = 3 // maximum number of attempts BenchmarkDetectTimeout = 30 * time.Second // for select fast mirror )
const DefaultCacheTTL = 24 * time.Hour
DefaultCacheTTL is the default time-to-live for cached benchmark results.
Variables ¶
This section is empty.
Functions ¶
func Benchmark ¶
Benchmark performs HTTP GET requests and measures response time. It uses a shared HTTP client with connection pooling for better performance.
func ClearBenchmarkCache ¶
func ClearBenchmarkCache()
ClearBenchmarkCache clears all cached benchmark results. This is useful when forcing a re-benchmark, e.g., on SIGHUP reload.
func GetDefaultMirror ¶
GetDefaultMirror returns the first mirror from the list as a fallback. This is used when async benchmark is in progress or when benchmark fails.
func GetTheFastestMirror ¶
GetTheFastestMirror finds the fastest responding mirror from the provided list
func GetTheFastestMirrorAsync ¶
func GetTheFastestMirrorAsync(distType int, mirrors []string, testURL string, callback AsyncBenchmarkCallback)
GetTheFastestMirrorAsync runs benchmark in the background and calls the callback when complete. This allows the application to start immediately with a default mirror while benchmarking runs. The callback will be called with the result when the benchmark completes.
Types ¶
type AsyncBenchmarkCallback ¶
type AsyncBenchmarkCallback func(result AsyncBenchmarkResult)
AsyncBenchmarkCallback is called when an async benchmark completes.
type AsyncBenchmarkResult ¶
AsyncBenchmarkResult represents the result of an async benchmark operation.
type BenchmarkCache ¶
type BenchmarkCache struct {
// contains filtered or unexported fields
}
BenchmarkCache stores cached benchmark results to avoid repeated testing. Results are cached per distribution type with TTL-based expiration.
func GetBenchmarkCache ¶
func GetBenchmarkCache() *BenchmarkCache
GetBenchmarkCache returns the global benchmark cache instance. This can be used for testing or advanced cache management.
func (*BenchmarkCache) ClearCache ¶
func (bc *BenchmarkCache) ClearCache()
ClearCache clears all cached benchmark results.
func (*BenchmarkCache) GetCachedResult ¶
func (bc *BenchmarkCache) GetCachedResult(distType int) (string, bool)
GetCachedResult returns a cached benchmark result if available and not expired.
func (*BenchmarkCache) SetCachedResult ¶
func (bc *BenchmarkCache) SetCachedResult(distType int, fastestMirror string, ttl time.Duration)
SetCachedResult stores a benchmark result in the cache.
type CachedResult ¶
CachedResult represents a cached benchmark result with expiration.
func (CachedResult) IsExpired ¶
func (c CachedResult) IsExpired() bool
IsExpired returns true if the cached result has expired.