Load balancing

Explanation

Sometimes processing requests on one box is not enough. Single box has limited processing power and when transaction volume is high, you would like to distribute the requests between two or more boxes in a fair manner.

lb1.png

So, the first message (request) that arrives at the broker goes to box 1, second one goes to box 2, third one goes to box 3, fourth goes to box 1, etc.

To implement load balancing create a single queue for the requests and let all the boxes consume from the queue. If there are several consumers on a single queue, messages are automatically distributed between the consumers in round-robin fashion:

lb2.png

Imagine you are running a helpdesk. You have thousands of clients all over the world posting requests and questions all the time. You have several operators who are receiving those requests. You want to have requests load-balanced so that all the requests don't go to a single operator, rather thay are distributed in a fair manner among all the operators. You would also want the system to adapt dynamically, i.e. if an operator closes his application (say going for lunch) the requests are distributed among remaining operators rather than waiting for the absent operator.

You can find implementation of such a helpdesk here:

To compile and link the files set your environment in the same way as you do to build OpenAMQ server and do the following:

$ c -l helpdesk_client.c
Compiling helpdesk_client...
Linking helpdesk_client...
$ c -l helpdesk_operator.c
Compiling helpdesk_operator...
Linking helpdesk_operator...

To run the helpdesk, you have to start OpenAMQ server first:

$ amq_server

Once the server is running you can run the operator terminal this way:

$ ./helpdesk_operator <broker-address>

For example:

$ ./helpdesk_operator server001

Clients can connect to the helpdesk in the following way:

$ ./helpdesk_client <broker-address>

For example:

$ ./helpdesk_client server001

Comments

Add a New Comment

Edit | Files | Tags | Source | Print

rating: 0+x

Author

Martin Sustrik <moc.xitami|kirtsus#moc.xitami|kirtsus>

All tutorials

Performance Tests: This tutorial explains how to do OpenAMQ performance tests using 0MQ performance testing framework.

Broker federation: How to setup a geographically distributed federation of OpenAMQ brokers and how to define dataflows between individual geographical locations.

The ESB cookbook: How to implement your own Enterprise Service Bus, step by step, using OpenAMQ.

Publishing contents: How to publish contents at high speed without bizarre memory issues.

Tuning OpenAMQ for low latency: How to tune your operating system and hardware to get the lowest latency, i.e. the best response times, from your OpenAMQ broker.

The mandatory and immediate flags: How to use the 'mandatory' and 'immediate' flags on the Basic.Publish method.

Load balancing: How to use OpenAMQ to distribute work between multiple applications, a technique called "load balancing".

Content based routing: How to route messages based on their header properties. It is a fast and simple way to do 'content based routing' without needing to inspect entire messages. We explain the principles and provide worked examples.

Transient or durable subscriptions: How to make subscriptions that are transient (come and go with their consuming applications) or durable (stay around).

The AMQ model: How the AMQ model works: this is a basic backgrounder for anyone starting to use OpenAMQ in their applications.

Developing on Windows: How to build OpenAMQ client applications using MSVC on Windows

Handling Ctrl-C in applications: How to properly detect an interrupt (Ctrl-C) and shut-down gracefully in C/C++ WireAPI applications.