timeutil

package
v2.14.8 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddJitter added in v2.11.3

func AddJitter(duration time.Duration, jitter float64) time.Duration

AddJitter adds random jitter to a duration.

It adds or subtracts time from the duration within a given jitter fraction. For example for 10s and jitter 0.1, it returns a duration within [9s, 11s).

func Backoff added in v2.11.3

func Backoff(duration, max time.Duration, jitter float64) (double, withJitter time.Duration)

Backoff doubles the given duration. If max_ is given larger than 0 and the doubled value is greater than max_, it will be limited to max_. The param jitter can be used to add random jitter to the doubled duration.

Types

type LatencyRecorder

type LatencyRecorder struct {
	// contains filtered or unexported fields
}

LatencyRecorder helps to record operation latencies.

func NewLatencyRecorder

func NewLatencyRecorder() *LatencyRecorder

NewLatencyRecorder creates a new LatencyRecorder.

func (*LatencyRecorder) Format

func (p *LatencyRecorder) Format() string

Format formats the recorded latencies into a string, which can be sent to log by a logger.

func (*LatencyRecorder) GetLatencyMap

func (p *LatencyRecorder) GetLatencyMap() map[string]time.Duration

GetLatencyMap returns a map of all recorded latencies.

func (*LatencyRecorder) Mark

func (p *LatencyRecorder) Mark(name string)

Mark records latency of an operation, from the previous operation, or from the startTime if this is the first calling. It is designed to record each operation latency one by one in synchronous operations.

func (*LatencyRecorder) MarkFromStartTime

func (p *LatencyRecorder) MarkFromStartTime(name string)

MarkFromStartTime records latency of an operation, from the startTime, it does not affect recording of calling Mark.

func (*LatencyRecorder) MarkWithStartTime

func (p *LatencyRecorder) MarkWithStartTime(name string, start time.Time)

MarkWithStartTime records latency of an operation, from the given time, it does not affect recording of calling Mark.

func (*LatencyRecorder) Reset

func (p *LatencyRecorder) Reset()

Reset resets the recorder to initial state, which is ready to be reused.

func (*LatencyRecorder) WriteTo

func (p *LatencyRecorder) WriteTo(w io.Writer) (n int64, err error)

WriteTo formats and writes the recorded latencies to the given io.Writer. It implements the interface io.WriterTo,

Jump to

Keyboard shortcuts

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