util

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateRunning uint32 = 0
	StateStopped uint32 = 1
)

Variables

View Source
var (
	GlobalTimerWheel  *goetty.TimeoutWheel // the global timer wheel
	GlobalParsingPool *WorkerPool          // for all tasks' parsing, cpu intensive
	GlobalWritingPool *WorkerPool          // the all tasks' writing ClickHouse, cpu-net balance
	Logger            *zap.Logger
)
View Source
var (
	// ErrStopped when stopped
	ErrStopped = errors.New("WorkerPool already stopped")
)

Functions

func EnvBoolVar

func EnvBoolVar(value *bool, key string)

func EnvIntVar

func EnvIntVar(value *int, key string)

func EnvStringVar

func EnvStringVar(value *string, key string)

func GetIP4Byname

func GetIP4Byname(host string) (ips []string, err error)

func GetOutboundIP

func GetOutboundIP() (ip net.IP, err error)

GetOutboundIP get preferred outbound ip of this machine https://stackoverflow.com/questions/23558425/how-do-i-get-the-local-ip-address-in-go.

func GetShift

func GetShift(s int) (shift uint)

GetShift returns the smallest `shift` which 1<<shift is no smaller than s

func GetSourceName

func GetSourceName(name string) (sourcename string)

GetSourceName returns the field name in message for the given ClickHouse column

func GetSpareTCPPort

func GetSpareTCPPort(portBegin int) int

GetSpareTCPPort finds a spare TCP port.

func InitGlobalParsingPool

func InitGlobalParsingPool()

InitGlobalParsingPool initialize GlobalParsingPool

func InitGlobalTimerWheel

func InitGlobalTimerWheel()

InitGlobalTimerWheel initialize the global timer wheel

func InitGlobalWritingPool

func InitGlobalWritingPool(maxWorkers int)

InitGlobalWritingPool initialize GlobalWritingPool

func InitLogger

func InitLogger(newLogPaths []string)

func JksToPem

func JksToPem(jksPath, jksPassword string, overwrite bool) (certPemPath, keyPemPath string, err error)

JksToPem converts JKS to PEM Refers to: https://serverfault.com/questions/715827/how-to-generate-key-and-crt-file-from-jks-file-for-httpd-apache-server

func Run

func Run(appName string, initFunc, jobFunc, cleanupFunc func() error)

func SetLogLevel

func SetLogLevel(newLogLevel string)

func StringContains

func StringContains(arr []string, str string) bool

StringContains check if contains string in array

func WaitForExitSign

func WaitForExitSign()

Types

type WorkerPool

type WorkerPool struct {
	sync.Mutex
	// contains filtered or unexported fields
}

WorkerPool is a blocked worker pool inspired by https://github.com/gammazero/workerpool/

func NewWorkerPool

func NewWorkerPool(maxWorkers int, queueSize int) *WorkerPool

New creates and starts a pool of worker goroutines.

func (*WorkerPool) Resize

func (w *WorkerPool) Resize(maxWorkers int)

Resize ensures worker number match the expected one.

func (*WorkerPool) Restart

func (w *WorkerPool) Restart()

func (*WorkerPool) StopWait

func (w *WorkerPool) StopWait()

StopWait stops the worker pool and waits for all queued tasks tasks to complete.

func (*WorkerPool) Submit

func (w *WorkerPool) Submit(fn func()) (err error)

Submit enqueues a function for a worker to execute. Submit will block regardless if there is no free workers.

Jump to

Keyboard shortcuts

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