benchmarks

package
v0.11.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Configuration constants
	BenchmarkMaxTimeout    = 150 * time.Second // detect resource timeout
	BenchmarkMaxTries      = 3                 // maximum number of attempts
	BenchmarkDetectTimeout = 30 * time.Second  // for select fast mirror
)
View Source
const DefaultCacheTTL = 24 * time.Hour

DefaultCacheTTL is the default time-to-live for cached benchmark results.

Variables

This section is empty.

Functions

func Benchmark

func Benchmark(ctx context.Context, base, query string, times int) (time.Duration, error)

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

func GetDefaultMirror(mirrors []string) string

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

func GetTheFastestMirror(mirrors []string, testURL string) (string, error)

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.

func GetTheFastestMirrorWithCache

func GetTheFastestMirrorWithCache(distType int, mirrors []string, testURL string) (string, error)

GetTheFastestMirrorWithCache finds the fastest mirror, using cache if available. This is the preferred method for production use as it avoids repeated benchmarking.

Types

type AsyncBenchmarkCallback

type AsyncBenchmarkCallback func(result AsyncBenchmarkResult)

AsyncBenchmarkCallback is called when an async benchmark completes.

type AsyncBenchmarkResult

type AsyncBenchmarkResult struct {
	DistType      int
	FastestMirror string
	Error         error
}

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

type CachedResult struct {
	FastestMirror string
	CachedAt      time.Time
	TTL           time.Duration
}

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.

type Result

type Result struct {
	URL      string
	Duration time.Duration
}

Result stores benchmark results for a URL

type Results

type Results []Result

Results implements sort.Interface for []Result based on Duration

func (Results) Len

func (r Results) Len() int

func (Results) Less

func (r Results) Less(i, j int) bool

func (Results) Swap

func (r Results) Swap(i, j int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL