3 ms·
That's an easy solution in any language, frankly; have a shared queue of the requests, and the servers simply pull from the queue whenever they aren't processin
by rybosome 13y ago
That's an easy solution in any language, frankly; have a shared queue of the requests, and the servers simply pull from the queue whenever they aren't processing a request. I'm sure that this is easier to implement in Go than a lot of other languages, but I think this actually defeats the purpose of the question. The hard part of the question is how to assign work to the servers rather than letting the servers pick the work themselves.
- JulianMorrison 13y agoYeah, I just picked Go because it's one I know well and it's a 5 second solution that handles the question as asked. It would be just as easy to do in ruby for example, with EM::Queue. I actually intended this as a way to "assign work" rather than having the servers pull. Each goroutine "owns" a server and forwards all requests to it, but it's just part of the one load balancer process, and the load balancer does nothing but balance. IMO, defeating the purpose of a question is how you solve problems in real life. Now if you wanted a harder question, you could follow that with: OK, that solution will give the servers time to do their thing, but there's no guarantee it won't just end up dumping all the load on a few servers, straining infrastructure and under-using the other machines, because there's no guarantee Go's scheduler is fair. So please develop two competing solutions. First, a fair scheduler that spreads the load evenly. Second, as an alternative, an unfair scheduler that always fills 100% of the time on the first machine before moving on to the second, and so on, and reports how many machines it's using so we can take the others out of the pool and repurpose them.