Queues are the most important piece of architecture you can put into an application to improve throughput and remove bottlenecks. There are many cases where an application creates contention on certain resources where contention is not necessary. Queues eliminate these points of contention.

For example, a request handler might log every single page view to a log file. Suppose that it takes 50 milliseconds to write a line to a log file. If that is the case, the request handler cannot serve requests any faster than 20 per second, even if the rest of the request handling mechanism is blazingly fast. But writing a line to a log file is not a critical part of the request handling operation, and thus should not be such a limiting factor.

The solution to this problem is to introduce a queue between the request handler and the logging facility. When the request handler wants to log a message, it places the message on the queue then continues handling the rest of the request. A separate thread removes messages from the queue and writes them to the log. This arrangement decouples the request handlers from the loggers, thereby eliminating the bottleneck introduced by the log.

In Oracle ATG Web Commerce, the notion of queues is generalized to all types of JavaBean event listeners. Oracle ATG Web Commerce comes with a utility that generates the Java code needed to create an EventQueue class specialized to a type of EventListener. This queue class implements the same interface as the original EventListener, so to other components it acts the same as the original component. Calls made to the queue class are handled by being placed on a queue. A separate thread then takes the calls from the queue and passes them to the original component.

After you realize that a particular component is a bottleneck, you should be able to create and insert a queue component for that component, without changing any of your other components. The following topics describe how to use queues: