Clustered

Wednesday, July 31, 2013

I forgot to post to the blog again. For nearly a month.

I have been seriously poop-socking with Rust. I've been establishing a better way to handle the server, inventory and save data. The way it works right now is that user data like the inventory etc is sent to our webserver in a json form, where it's stored and retrieved the next time you play. But we want multiple servers. So I started making the web system so it could partition that stuff based on server. I got about three days into that before I realised that it was stupid as fuck. We don't need that data, why store it on our servers - as a single point of failure? It's not a very good gameplan.

The simple solution would be to make the server just save all this stuff to disk, and load it whenever it wants to. But our long term plan involves multiple servers (and be able to travel between them with your persistent character). So saving to disk on a single server was out.

So I made a sockets library and made a cluster server. When the rust server starts it connects to the cluster server. When someone joins the rust server it contacts the cluster server to ask if they're allowed to join etc and retrieves their inventory. This works in the shortterm because we can automatically spawn a cluster server when the rust server is started. So for our single server situation we don't have to change anything.. and we gain the fact that people don't lose their inventory - because it's saved near instantly and doesn't rely on a website 5,000 miles away being only. And in the long term all we have to do is add a command line to connect to an independent cluster server.. and we have multiple servers in a cluster!

This also allowed us to get rid of JSON. I love JSON, it's awesome for a lot of things.. but in a single threaded Unity3D server it is not. We moved to protobuffers. They're small, fast and have a hard format. They can be generated and read for c# and c++ too - which has huge advantages for us.