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

XPUB/XSUB appears to take a lot of CPU time when idle #284

Open
jonmandrell opened this issue Sep 23, 2020 · 0 comments
Open

XPUB/XSUB appears to take a lot of CPU time when idle #284

jonmandrell opened this issue Sep 23, 2020 · 0 comments

Comments

@jonmandrell
Copy link

I have created a simple xpub/xsub server to support my system, but it appears to be running at a high CPU load even when there is no traffic going on. I am building with go 1.14.4, and I'm running on a smaller gumstix processor, but I wouldn't expect the server to take 45% of the CPU with no traffic at all.

// this is the main file for the XPUB/XSUB implementation for
// ZeroMQ. This is the main message broker that handles routing
// publications and subscriptions and the corresponding messages

package main

import (
"fmt"
"time"

    zmq "github.com/zeromq/goczmq"

)

const (
PUBLICATION_PORT = 10000
SUBSCRIPTION_PORT = 10001
)

func main() {
fmt.Printf("Starting up XPUBSUB for ports pub:%d and sub:%d\n", PUBLICATION_PORT, SUBSCRIPTION_PORT)
// all of the work here is done via the proxy class
proxy := zmq.NewProxy()
var err error
// set up the subscription port
connection := fmt.Sprintf(">tcp://localhost:%d", SUBSCRIPTION_PORT)
err = proxy.SetFrontend(zmq.XSub, connection)
if err != nil {
fmt.Println("Cannot set front-end:", err)
}
// set up the publication port
connection = fmt.Sprintf("@tcp://*:%d", PUBLICATION_PORT)
err = proxy.SetBackend(zmq.XPub, connection)
if err != nil {
fmt.Println("Cannot set back-end:", err)
}
// the proxy runs in a separate thread handling all of the
// work. Our main thread just needs to hang around to keep
// the application alive.
for {
time.Sleep(1)
}
}

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

1 participant