util

package
v2.1.1+incompatible Latest Latest
Warning

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

Go to latest
Published: May 30, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinAddrFormat min addr format
	MinAddrFormat = "000000000000000000000"
	// MaxAddrFormat max addr format
	MaxAddrFormat = "255.255.255.255:99999"
)

Variables

View Source
var (
	GitCommit = ""
	BuildTime = ""
	GoVersion = ""
)

set on build time

Functions

func GetAddrFormat

func GetAddrFormat(addr string) string

GetAddrFormat returns addr format for sort, padding left by 0

func GetAddrNextFormat

func GetAddrNextFormat(addr string) string

GetAddrNextFormat returns next addr format for sort, padding left by 0

func PrintVersion

func PrintVersion() bool

PrintVersion 输出版本信息

Types

type Analysis

type Analysis struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Analysis analysis struct

func NewAnalysis

func NewAnalysis(tw *goetty.TimeoutWheel) *Analysis

NewAnalysis returns a Analysis

func (*Analysis) AddTarget

func (a *Analysis) AddTarget(key uint64, interval time.Duration)

AddTarget add analysis point on a key

func (*Analysis) Failure

func (a *Analysis) Failure(key uint64)

Failure incr failure count

func (*Analysis) GetContinuousFailureCount

func (a *Analysis) GetContinuousFailureCount(server uint64) int

GetContinuousFailureCount return Continuous failure request count in spec secs

func (*Analysis) GetQPS

func (a *Analysis) GetQPS(server uint64, interval time.Duration) int

GetQPS return qps in spec duration

func (*Analysis) GetRecentlyAvg

func (a *Analysis) GetRecentlyAvg(server uint64, interval time.Duration) int

GetRecentlyAvg return avg latency in spec secs

func (*Analysis) GetRecentlyMax

func (a *Analysis) GetRecentlyMax(server uint64, interval time.Duration) int

GetRecentlyMax return max latency in spec secs

func (*Analysis) GetRecentlyMin

func (a *Analysis) GetRecentlyMin(server uint64, interval time.Duration) int

GetRecentlyMin return min latency in spec duration

func (*Analysis) GetRecentlyRejectCount

func (a *Analysis) GetRecentlyRejectCount(server uint64, interval time.Duration) int

GetRecentlyRejectCount return reject count in spec duration

func (*Analysis) GetRecentlyRequestCount

func (a *Analysis) GetRecentlyRequestCount(server uint64, interval time.Duration) int

GetRecentlyRequestCount return the server request count in spec duration

func (*Analysis) GetRecentlyRequestFailureCount

func (a *Analysis) GetRecentlyRequestFailureCount(server uint64, interval time.Duration) int

GetRecentlyRequestFailureCount return failure request count in spec duration

func (*Analysis) GetRecentlyRequestFailureRate

func (a *Analysis) GetRecentlyRequestFailureRate(server uint64, interval time.Duration) int

GetRecentlyRequestFailureRate return failure rate in spec secs

func (*Analysis) GetRecentlyRequestSuccessedCount

func (a *Analysis) GetRecentlyRequestSuccessedCount(server uint64, interval time.Duration) int

GetRecentlyRequestSuccessedCount return successed request count in spec secs

func (*Analysis) GetRecentlyRequestSuccessedRate

func (a *Analysis) GetRecentlyRequestSuccessedRate(server uint64, interval time.Duration) int

GetRecentlyRequestSuccessedRate return successed rate in spec secs

func (*Analysis) Reject

func (a *Analysis) Reject(key uint64)

Reject incr reject count

func (*Analysis) RemoveTarget

func (a *Analysis) RemoveTarget(key uint64)

RemoveTarget remove analysis point on a key

func (*Analysis) Request

func (a *Analysis) Request(key uint64)

Request incr request count

func (*Analysis) Response

func (a *Analysis) Response(key uint64, cost int64)

Response incr successed count

type Cache

type Cache struct {
	sync.RWMutex

	// MaxBytes is the maximum bytes of cache entries before
	// an item is evicted. Zero means no limit.
	MaxBytes uint64

	// OnEvicted optionally specificies a callback function to be
	// executed when an entry is purged from the cache.
	OnEvicted func(key Key, value interface{})
	// contains filtered or unexported fields
}

Cache is an LRU cache. It is not safe for concurrent access.

func NewLRUCache

func NewLRUCache(maxBytes uint64) *Cache

NewLRUCache creates a new Cache. If maxBytes is zero, the cache has no limit and it's assumed that eviction is done by the caller.

func (*Cache) Add

func (c *Cache) Add(key Key, value []byte)

Add adds a value to the cache.

func (*Cache) Clear

func (c *Cache) Clear()

Clear purges all stored items from the cache.

func (*Cache) Get

func (c *Cache) Get(key Key) (value []byte, ok bool)

Get looks up a key's value from the cache.

func (*Cache) Len

func (c *Cache) Len() int

Len returns the number of items in the cache.

func (*Cache) Remove

func (c *Cache) Remove(key Key)

Remove removes the provided key from the cache.

type FastHTTPClient

type FastHTTPClient struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

FastHTTPClient fast http client

func NewFastHTTPClient

func NewFastHTTPClient() *FastHTTPClient

NewFastHTTPClient create FastHTTPClient instance

func NewFastHTTPClientOption

func NewFastHTTPClientOption(defaultOption *HTTPOption) *FastHTTPClient

NewFastHTTPClientOption create FastHTTPClient instance with default option

func (*FastHTTPClient) Do

func (c *FastHTTPClient) Do(req *fasthttp.Request, addr string, option *HTTPOption) (*fasthttp.Response, error)

Do do a http request

type HTTPOption

type HTTPOption struct {
	// Maximum number of connections which may be established to server
	MaxConns int
	// MaxConnDuration Keep-alive connections are closed after this duration.
	MaxConnDuration time.Duration
	// MaxIdleConnDuration Idle keep-alive connections are closed after this duration.
	MaxIdleConnDuration time.Duration
	// ReadBufferSize Per-connection buffer size for responses' reading.
	ReadBufferSize int
	// WriteBufferSize Per-connection buffer size for requests' writing.
	WriteBufferSize int
	// ReadTimeout Maximum duration for full response reading (including body).
	ReadTimeout time.Duration
	// WriteTimeout Maximum duration for full request writing (including body).
	WriteTimeout time.Duration
	// MaxResponseBodySize Maximum response body size.
	MaxResponseBodySize int
}

HTTPOption http client option

func DefaultHTTPOption

func DefaultHTTPOption() *HTTPOption

DefaultHTTPOption returns a HTTP Option

type Key

type Key interface{}

A Key may be any value that is comparable. See http://golang.org/ref/spec#Comparison_operators

type Recently

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

Recently recently point data

Jump to

Keyboard shortcuts

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