AJAX - The Complete Reference

(avery) #1

PART II


Chapter 6: Networking Considerations 245


Value data: 10
Base: Decimal

(Of course you don’t have to use 10 here, it is just for illustration.)


  1. Quit Registry Editor.


After upgrading the number of requests possible, you may see some performance boost
in whatever browser you do this to. You may also find yourself blocked from some sites if
you overload them. There is certainly much mischief to make if you can spawn many
requests at once, so don’t do it unless you know what you are doing.

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.

Request Queues


Most likely your application doesn’t suffer too much from the two-request restriction, and
you may decide to live with this limitation rather than find a workaround as previously
discussed. To more effectively manage the two-at-a-time situation, you might want to
explore queuing requests. The big question here is if only two requests can be sent at a time,
what order do they go out in? The good news is that the requests are picked in the order
they were requested. The native queue example (http://ajaxref.com/ch6/nativequeue.
html) presented earlier clearly shows this. In Figure 6-8 you see that once request 1 returns
and the browser is free to start sending more requests, it starts with request 3 and works
through the rest sequentially.
Free download pdf