Go application using too much CPU, Please help!

omkarajagundeHOBBY

8 months ago

I'm building a chat app in Go using Go Fiber and MongoDB. I use WebSockets to receive messages, and APIs for sending/getting messages. MongoDB stores the messages, and I use Mongo change streams to listen for new ones and push them to clients via WebSockets.

Previously, I used Node.js, but switched to Go for better performance, lower memory use, and improved concurrency. I deployed the app to Railway using Docker, and it works fine except for one issue. My plan gives me 8 GB RAM and 8 vCPUs, but during testing, Go uses 4-8 vCPUs even with GOMAXPROCS set to 4. Lowering GOMAXPROCS makes the app slower, and I'm worried it’ll spike CPU usage and cost a lot as users grow. Node.js used way less CPU. Any tips on what I might be missing?

Moreover im not even able to setup a http pprof, it gives me operation timed out if I do go tool <host-ip.com>:6060/debug/pprof/profile

Code here: https://github.com/omkarajagunde/Blablah-live/tree/master/server

Closed

1 Replies

8 months ago

You need to expose pprof on another domain using target ports.

As for the CPU usage, we don't have any way to tell you why, we are simply running your app as-is and reporting on the resources it uses, aka we have no observability into what your code does, similarly to how your power company can't tell you what you where doing with the power you used.


Status changed to Closed brody 8 months ago