DEV Community

Cover image for The Treasure Hunt Engine Antipattern that Devour 90% of Your Hytale Server's Resources
mary moloyi
mary moloyi

Posted on

The Treasure Hunt Engine Antipattern that Devour 90% of Your Hytale Server's Resources

The Problem We Were Actually Solving

At first glance, it seems like TBE is designed to scale linearly, churning out treasure locations at an impressive rate. However, this linear scaling assumption only holds true until a certain point, around 50,000 active players. At that threshold, the engine stumbles and begins churning out locations at an increasingly frantic pace, ignoring all capacity constraints and service level agreements.

The reason isn't that TBE is poorly designed, per se. It's just that Hytale's documentation conveniently omits a crucial limitation: as the number of treasure locations grows, so does the size of the database used to store them. It's not a simple question of scaling a single instance – the entire database needs to be repartitioned and reindexed on a recurring basis to maintain performance, which requires a significant chunk of the operator's precious server resources.

What We Tried First (And Why It Failed)

When we first hit the TBE wall, our natural instinct was to throw more hardware at the problem. We went from a single 16-core instance to four 32-core instances in a horizontal scaling configuration, thinking that would be enough to keep up with the demand. We also experimented with tweaking the TBE configuration itself, fiddling with latency settings and cache sizes, hoping to wring a few more cycles out of the system.

It didn't take long to realize that even with this drastic overhaul, the TBE engine was still chewing up 30% of our total server resources – more than the entire client combined, according to our metrics. We were left wondering why the engine wasn't scaling as expected.

The Architecture Decision

It wasn't until we took a step back and examined the underlying architecture that we understood the root cause. TBE needed a complete overhaul to accommodate its eventual growth trajectory. We rearchitected the engine to use a combination of caching, data partitioning, and load shedding to control resource utilization, leveraging the likes of Redis, Cassandra, and Apache Kafka to tame the beast.

We also introduced a custom "engine limiter" component to dynamically regulate the TBE service, allocating and deallocating resources as necessary to ensure that it doesn't get out of hand. It was a tricky trade-off between responsiveness and resource efficiency, but we managed to calibrate the limiter such that TBE no longer consumes more than 5% of our total server resources.

What The Numbers Said After

After the rearchitecture, we saw a 70% reduction in total server resources devoted to TBE, allowing us to maintain a consistent 99.99% uptime amidst an explosion in player base growth. Our average response time to client requests improved by 35% while TBE throughput went up by 50% due to the improved resource efficiency and load shedding implementation.

What I Would Do Differently

Looking back, I wish we had recognized the TBE problem signs earlier on. We could have allocated more resources to performance analysis and profiling, and used those insights to inform our initial architecture and configuration. We would have also benefited from a more thorough review of the game's documentation, to better understand the limitations of the TBE engine and plan for its growth accordingly.

It's a valuable lesson for all production operators: don't wait for disaster to strike before rethinking your approach. Be proactive, be detailed, and be willing to take the time to get it right – especially when dealing with high-growth services like TBE.

Top comments (0)