utils

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BIG_M = 0xc6a4a7935bd1e995
	BIG_R = 47
	SEED  = 0x1234ABCD
)

Variables

This section is empty.

Functions

func CreateDir

func CreateDir(path string) error

func GetHostName

func GetHostName() (string, error)

func GetNowMs

func GetNowMs() int64

timestamp in ms

func IsNil

func IsNil(i interface{}) bool

func MurmurHash64A

func MurmurHash64A(data []byte) (h uint64)

murmur hash function. When the number of unique elements is 10000000, the hash distribution is as follows: |--------------------||--------------------| | bucket | num || bucket | num | |--------------------||--------------------| | 0 | 1000095 || 5 | 999697 | |--------------------||--------------------| | 1 | 1000449 || 6 | 1000249 | |--------------------||--------------------| | 2 | 999580 || 7 | 1000917 | |--------------------||--------------------| | 3 | 999182 || 8 | 1000388 | |--------------------||--------------------| | 4 | 998817 || 9 | 1000626 | |--------------------||--------------------|

E(X) = 389275.8

func Write

func Write(strs ...string) (string, error)

直接拼接字符串,如果缓冲变得太大,Write会采用错误值 ErrTooLarge 引发panic

Types

type Cell

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

func (*Cell) Reset

func (cell *Cell) Reset()

type SlidingWindow

type SlidingWindow struct {
	Size           int64
	CellIntervalMs int64
	Cells          []*Cell // invariant: len(Cells) == Size.
}

func NewSlidingWindow

func NewSlidingWindow(size int64, cellIntervalMs int64) *SlidingWindow

func (*SlidingWindow) GetActualDurationMs

func (sw *SlidingWindow) GetActualDurationMs(nowMs int64) int64

func (*SlidingWindow) GetHit

func (sw *SlidingWindow) GetHit(nowMs int64, metricName string) int64

func (*SlidingWindow) GetHits

func (sw *SlidingWindow) GetHits(nowMs int64, metricNames ...string) map[string]int64

func (*SlidingWindow) GetNowHits

func (sw *SlidingWindow) GetNowHits(nowMs int64, metricNames ...string) map[string]int64

func (*SlidingWindow) Hit

func (sw *SlidingWindow) Hit(nowMs int64, metricNames ...string)

一次动作(如请求),记为一次 Hit。

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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