benmanns / goworker

goworker is a Go-based background worker that runs 10 to 100,000* times faster than Ruby-based workers.
https://www.goworker.org
Other
2.79k stars 241 forks source link

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

Open chaos0108 opened 3 years ago

chaos0108 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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