Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workers, isBlocking and queue size to listen config #208

Merged
merged 3 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions cmd/goflow2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,36 @@ func main() {
numSockets = 1
}

numWorkers := 0
if listenAddrUrl.Query().Has("workers") {
if numWorkersTmp, err := strconv.ParseUint(listenAddrUrl.Query().Get("workers"), 10, 64); err != nil {
log.Fatal(err)
} else {
numWorkers = int(numWorkersTmp)
}
}
if numWorkers == 0 {
numWorkers = numSockets * 2
}

isBlocking := false
if listenAddrUrl.Query().Has("blocking") {
if isBlocking, err = strconv.ParseBool(listenAddrUrl.Query().Get("blocking")); err != nil {
log.Fatal(err)
}
}

queueSize := 0
mieczkowski marked this conversation as resolved.
Show resolved Hide resolved
if listenAddrUrl.Query().Has("queue_size") {
if queueSizeTmp, err := strconv.ParseUint(listenAddrUrl.Query().Get("queue_size"), 10, 64); err != nil {
log.Fatal(err)
} else {
queueSize = int(queueSizeTmp)
}
} else if !isBlocking {
queueSize = 1000000
}

hostname := listenAddrUrl.Hostname()
port, err := strconv.ParseUint(listenAddrUrl.Port(), 10, 64)
if err != nil {
Expand All @@ -201,17 +231,23 @@ func main() {
}

logFields := log.Fields{
"scheme": listenAddrUrl.Scheme,
"hostname": hostname,
"port": port,
"count": numSockets,
"scheme": listenAddrUrl.Scheme,
"hostname": hostname,
"port": port,
"count": numSockets,
"workers": numWorkers,
"blocking": isBlocking,
"queue_size": queueSize,
}
l := log.WithFields(logFields)

l.Info("starting collection")

cfg := &utils.UDPReceiverConfig{
Sockets: numSockets,
Sockets: numSockets,
Workers: numWorkers,
QueueSize: queueSize,
Blocking: isBlocking,
}
recv, err := utils.NewUDPReceiver(cfg)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion utils/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func NewUDPReceiver(cfg *UDPReceiverConfig) (*UDPReceiver, error) {
}

if cfg.Workers <= 0 {
cfg.Workers = cfg.Sockets
cfg.Workers = cfg.Sockets * 2
mieczkowski marked this conversation as resolved.
Show resolved Hide resolved
}

r.sockets = cfg.Sockets
Expand Down