Sign in to follow this  
Hnry

Design for scalability

Recommended Posts

I currently have simple server using select() but I can't think of any nice and clean way to allow scalability and load balancing if I needed it later. Letting other servers know about new one, transferring info between them and stuff seems a bit complicated but I guess a in-depth explanation would open it for me.

So do you know good article(s) about scalability or can you explain it a bit more than "share the load between two servers if needed"?

Share this post


Link to post
Share on other sites
There are many ways of achieving scalability, some are harder, some easier.

In my opinion Erlang is the easiest way.

In short, to achieve scalability in Erlang you share some data across several computers using the Mnesia database.
Mochiweb does this: http://stackoverflow.com/questions/2903355/mochiwebs-scalability-features
Since Erlang has strong location transparency features, it is not important which of the servers that actually does the job (if you design your program correctly).

For example I can take my own MMO server, it is divided into area servers, one area is a geographically unique part the world.
Let say I have 4 servers assigned to handle that area, all four servers shares an objects registry which stores all id's and processed id's of the game objects located in that area.
If an game object on server 1 wants to send an event to another game object, it doesn't need to care on what server the target game object is located.
Since process id's are transparent to location you just lookup the process id in the object registry and fires away the event, Erlang will make sure the message arrives.

And here is an very simple example how to write a bank server running on two computers:
http://www.sics.se/~joe/tutorials/robust_server/robust_server.html

Share this post


Link to post
Share on other sites
Even if you're using Erlang, you'll still be accepting TCP connections on only one host.

Generally, what you do for scalability, is to build your service such that it can accept clients on many front-end servers, which in turn are identical and replaceable. The data you mutate then lives on back end servers. You can use Sun-RPC, or DCOM, or Erlang, or carrier pigeons to talk between the front-end presentation servers and the back-end data servers; it doesn't matter at a high level.

Then, you put either DNS load balancing (many A records for a given name), or a load balancer device (reverse NAT, typically), at the front of your network. This mechanism will spread incoming connections reasonably evenly across available front-end servers.

At some point, the data itself will become a bottleneck. Being able to shard the data (by customer ID, or game instance, or whatever) is key to being able to scale really large.

Note that all of this is application-level architecture -- whether you use select() or boost::asio or thread-per-client doesn't matter, because the important bit is being able to accept connections on more than one host. (although which mechanism you use DOES matter in how many clients you can serve per accepting host)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this