Multiplexing Requests
Instead of fighting with the connection limit, it may be better to consider sending the requests in batches. Yes, you read that right: we are promoting a batch concept here. Take three or four requests, put them into one Ajax request, and send it on its way to the server. This is just the simple idea of multiplexing applied to Ajax.
Now, you should doubt this approach as it would seem to be a return to the old style. However, what is being suggested is not waiting around for a batch request, but instead passing requests in bundles if they get backed up. For example, consider if there are two requests out and they are taking quite some time to come back. In the meantime, a few more requests have stacked up ready to go. Eventually, one finishes and that may release the log jam, but the rest of the requests still have to be sent one at a time. Instead, try keeping an outstanding requests count and then, as new requests stack up, put them in a "request bundle." As soon as a free connection is open, send the whole bundle to the server to a special dispatch program. The dispatch program sends off each request locally and bundles back the responses. The whole thing comes back and the various callbacks are fired.
If this method is implemented correctly, two connections might service many, many requests at a time with bundles. However, understand that this idea would suffer from the same idea presented at the start of a section; one slow request in the bundle would affect all the rest. Therefore, it is questionable if these ideas are really needed. So far the two-connection limit doesn't seem to bother enough people to influence Ajax library developers to implement queue and bundle ideas that can certainly introduce problems of their own. However, if you were to go down this path of thinking, you certainly would be quite familiar with a request queue, which is the next topic.
Post a comment