goworker icon indicating copy to clipboard operation
goworker copied to clipboard

It's graceful, but how to optimize cpu usage?

Open chaos0108 opened this issue 3 years ago • 2 comments

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
489 chaosii 20 0 1110252 17164 12524 S 54.2 0.1 1:38.45 background_work

chaos0108 avatar Oct 09 '20 09:10 chaos0108

I had try change the parameters, but wasn't work.

package main

import (
	"fmt"
	"github.com/benmanns/goworker"
	"log"
	"sso-api/config"
	"strconv"
)

//func myFunc(queue string, args ...interface{}) error {
//	log.Printf("From %s, %v\n", queue, args)
//	return nil
//}

func callbackUrl(queue string, args ...interface{}) error {
	log.Printf("From %s, %v\n", queue, args)
	return nil
}

func init() {
	_ = goworker.Init()
	settings := goworker.WorkerSettings{
		URI:            config.Goworker.GoworkerRedisUri,
		Connections:    50,
		Queues:         []string{config.Goworker.GoworkerQueueName},
		UseNumber:      true,
		ExitOnComplete: false,
		Concurrency:    2,
		Namespace:      config.Goworker.GoworkerNamespace,
		Interval:       1000000000,
	}
	goworker.SetSettings(settings)
	//goworker.Register("MyClass", myFunc)
	goworker.Register("Callback", callbackUrl)
}

func main() {
	if err := goworker.Work(); err != nil {
		fmt.Println("Error:", err)
	}
}

chaos0108 avatar Oct 09 '20 09:10 chaos0108

@chaos0108 Please use IntervalFloat instead of Interval, because it set Interval by IntervalFloat in Init(). And the unit of IntervalFloat is Second.

angus258963 avatar Oct 30 '20 10:10 angus258963