views:

235

answers:

4

Hi guys, I'm setting up a project and one of the main questions is how to implement a simple message queueing system (something along the line of a messenger chat system). I would like to avoid polling, but there will most likely be a lot of concurrent connections (tens of thousands). These will be HTTP+SSL connections, started from an application not a browser.

One solution I found would be DNS Load Balancing: distribute these persistent connections across a bunch of nginx webservers.

What do you think? Any other possible solutions?

A: 

DNS load balancing will allow you to distribute queries between multiple IP addresses, which could be multiple servers. Keep in mind that your clients could get different servers from one request to another, so your applicaiton can't use local state management. Your applicaiton will have to store its state in a centralized location such as a database.

Dave Swersky
A: 

Have you considered peer-to-peer? The state of the art in punching through firewalls is actually very effective especially since you're running your own client software in each instance, and you have servers to start the connection.

More work, but significantly less server resources.

Also, write your own server software - make sure it can handle a lot of connections and is extraordinarily lightweight and you should be able to handle thousands of connections per server before you do load balancing.

Adam Davis
+3  A: 

For load balancing, keeping the application server stateless will open up the field significantly. Once you've got that, you're free to use almost any generic load balancer. From something protocol specific like HTTP load balancers to the generic TCP level load balancers.

Keep it stateless, the rest will be trivial in comparison.

Ryan Graham
Thanks for your reply Ryan. My question is, if I use multiple distributed load-balanced databases, won't there be a problem with the "eventual consistency" model? Maybe a sharding algorithm that always points my requests to the same database?
idevelop
I am trying to avoid polling, that's why I wanted to keep the connections alive.
idevelop
I was thinking more along the lines of something like blind layer 4 load balancing based on client IP. I may be completely off on my assumptions though.
Ryan Graham
+1  A: 

If you are planning on using web services (XML message passing ), you can use gsoap, which has an included web server sample application, which uses thread pools. I've run a server using this and mysql ( for persistent state ). I agree with Ryan on reducing/eliminating the statefulness of the application.

sfossen