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

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

Open
chaos0108 opened this issue Oct 9, 2020 · 2 comments
Open

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

chaos0108 opened this issue Oct 9, 2020 · 2 comments

Comments

@chaos0108
Copy link

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 chaos0108 changed the title It's grateful, but how to optimize cpu usage? It's graceful, but how to optimize cpu usage? Oct 9, 2020
@chaos0108
Copy link
Author

chaos0108 commented Oct 9, 2020

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)
	}
}

@angus258963
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants