Optimizing Game Server Efficiency with Photon Fusion 2 and Hathora
Learn about server cost optimization by leveraging multiple matches per server
Over the past few months we’ve paired with the team at Photon to give studios a simple way to get dedicated servers setup on Hathora while leveraging the improvements recently rolled out with Photon’s Fusion 2.
In this write-up, we’ll cover:
- Why an optimized networking solution can help cost-conscious teams improve their game
- How teams can enable multiple matches per server while using Hathora
- An out-of-the-box way to try this concept out with Fusion 2’s Simple FPS integrated with Hathora
Cost optimization is at the top of the list for most multiplayer games hoping to achieve a large scale player base. Server costs tend to be 2nd largest line-item for multiplayer games after payroll, so the more you optimize your server costs - the more profitable your game will be (and more restful your nights will be).
The first and most straightforward optimization for your servers is to tune the CPU utilization, bandwidth egress, and memory pressure. To help you achieve this, picking a networking solution, like Photon Fusion 2, that is well-optimized out-of-the-box can go a long way in limiting costs by drastically reducing bandwidth usage. You should also use a scalable server hosting solution that allows you to easily monitor and configure your servers. With those metrics available, you can tune your server’s CPU, memory, and egress to maximize usage efficiency without sacrificing performance.
That is just the first layer of optimization, next you can further reduce server costs by running multiple matches or rooms on a single server instance. Each server instance will have some constant CPU & memory overhead cost — and even more-so with servers running headless engines (common for Unity and Unreal multiplayer games).
Enabling multiple matches per server
Web games (like Bullet Mania) can easily support this architecture because the server needs are often less intensive and networking libraries like Socket.io support the use case easily with first-class features like Socket.io Rooms. It’s no surprise because web technologies are driven by non-gaming needs that hinge on lightweight web servers handling thousands of concurrent user connections.
Server architectures for popular RTS and MOBA games using deterministic netcode have some similarities - a single server can house dozens—even hundreds—of matches simultaneously because the bulk of the work is handled via deterministic client-side simulations. This allows for incredible cost savings when it comes to server hosting due to minimal bandwidth usage and efficient server utilization.
FPS, shooters, and other multiplayer games that require pinpoint precision mixed with dynamic gameplay can’t afford the key trade-offs that come with the deterministic netcode design. These games instead usually run physic simulations in servers running headless game engines and then sync object states across all players, this prioritizes crisp gameplay and heightened cheat protection.
To achieve multiple matches per server for these games, you’ll first need to check that your networking layer is able to support this paradigm, then you’ll also need to make sure your server orchestration layer can schedule servers appropriately as well (Hathora supports this via roomsPerProcess configuration). It’s not nearly as straightforward to pull this off, but with the right tooling it can be surprisingly simple.
Unity sample game with Photon Fusion 2 and Hathora
Photon Fusion 2 officially launched earlier this year and is the latest version of Photon’s powerful state-sync networking solution. In our testing we’ve found it to be performant and feature-rich while also balancing simplicity and flexibility. Impressively, Photon Fusion 2 allows teams to seamlessly use it for P2P, relay, and dedicated server use cases based on your game’s needs.
Using Photon Fusion 2 with dedicated servers makes a lot of sense for competitive PvP games like first-person shooters. We were excited to work with the Photon team on Simple FPS, a fully featured Unity shooter game, to release a fully-integrated version of it deployed on Hathora.
One of key reasons we partnered with Photon on Simple FPS is that both Photon Fusion 2 and Hathora have built-in support for multiple matches per server. Photon Fusion 2 handles it with their Multi-Peer feature and is one of the few networking solutions we found that handle it natively. Hathora, similarly, is one of the very few server hosting platforms to support multiple matches per server (via Hathora’s roomsPerProcess
configuration).
Simple FPS Hathora Integration overview
Link to GitHub repo for Simple FPS integrated with Hathora (with full docs)
The integration between Hathora and Photon Fusion 2 takes part over a few areas:
- Install tooling: both Hathora and Photon Fusion should be installed via their official SDKs and plugins.
↳ Check out Hathora’s Unity Plugin and Photon Fusion’s SDK installation guides - Server startup: when your dedicated server instances starts up, it should get its connection info from Hathora and register itself with Photon Cloud (which acts as middleware for managing active sessions and connecting players).
↳ See how server startup is handled in the Simple FPS sample - Determining best region: when one of your players requests a match, your client needs to figure out what the best region(s) are.
↳ Simple FPS includes scripts to calculate best pings and has logic to easily map between Photon Cloud regions and Hathora regions. - Request a new match from Hathora: once you have player demand for a match, you can request a new server to spin up with a single
CreateRoom
call via Hathora’s API
↳ In Simple FPS, we utilize Hathora’s lightweight lobby service middeware to facilitate this, but in most cases you should make this call from your matchmaking middleware
Setting up Photon Fusion’s Multi-Peer mode with Hathora
We were delighted when we found that Photon Fusion’s Multi-Peer mode would work nicely with Hathora’s multiple roomsPerProcess feature. From Photon Fusion 2’s docs:
Multi-Peer mode allows Fusion to instantiate multiple completely independent NetworkRunner instances with their own associated Fusion Simulation, Physics scene, Network Connection, and Scenes inside of a single Unity Editor instance.
Photon is able to essentially create isolated simulation scopes via NetworkRunner
instances, which is significant because it gets around the Unity’s limitation of a single physics simulation per server. Pretty cool stuff.
When it comes to supporting multiple matches per server, the breakdown of responsibilities:
- Hathora handles scheduling the correct number matches into servers, spinning up new servers when all servers are at max number matches
- Photon handles keeping track of active matches, facilitate clients connecting to server
Now to get the Multi-Peer integration working we need to do the following:
- Set
roomsPerProcess
to equal the max number of matches (n) a single server process can handle. Then add n additional ports via Hathora configuration (Photon requires a unique port to be mapped to an active match)
↳ Note: depending on your netcode, adding additional ports won’t always be needed; for example, in Bullet Mania the match id is encoded as part of the request messages sent to server) - Server logic to handle when new matches have been assigned to a server and map it to an open port and register the session with Photon Cloud
↳ Check out how this is done for our Simple FPS integration - Enable Multi-Peer mode in your Photon Fusion configuration (via Fusion’s
NetworkProjectConfig
)
Flexible, and powerful game server hosting
At Hathora, we pride ourselves on the flexibility of our platform - we work with any game engine and tech stack, while also supporting advanced features like multiple matches per server. We also work closely with studios to ensure their games transition smoothly from development & testing to launch - learn how we helped Frost Giant scale test Stormgate to 1M CCU.
If you have a multiplayer game and you want try it out on Hathora, please reach out to us at hello@hathora.dev or on our Discord server. We would love to work with you to help make your game an efficient and cost effective success.