I'm a Rust bro now...

The day every Gopher fears as arrived. But why?

Yep, it's happened. I'm a Rustacean now. In the last project update, I mentioned that I wanted to stick with Go, despite the high CPU usage due to Cgo.

Well, that's gone now. Over the last couple weeks, I've started learning Rust, and recreating the game server yet again.

But the question is, why?

While I was developing the Go server, I noticed some warnings about thread starvation and a lock being held for too long. This is due to how Valve's GameNetworkingSockets ( GNS ) library works.

When the library is initialized and messages are sent/received/connections happen, a lock gets acquired.

When there are so many connections and messages incoming/outgoing, the library struggles to take the lock and performance starts to degrade.

So, I had the brilliant idea to introduce sharding, which should help by splitting the singular server in multiple smaller server instances, reducing how many messages needs processing per tick per server, and how many total connections the overall game server needs to handle.

So, what's the problem?

Well, if I were to implement sharding, I would effectively introduce another network thread, and another game loop thread, which means, more calls to Cgo, which means, more CPU usage.

This lead me to my decision to switch to Rust. While C++ is perfectly fine, I'm seriously just tired of CMake and how painful package management is.

Performance increase!

The result? Massive increase in performance. We're down from that 115-195% CPU usage to ~70-90% CPU usage when we receive massive bursts of messages and connections.

So now, on to implementing movement. Once basic movement is introduced, I'll work on sharding the server. Since I also refactored the way the game server works, I also introduced the groundwork for the server sharding.

See you in the next update!

Last updated

Was this helpful?