The postings on this site are the contributor's and don’t necessarily represent IBM’s positions, strategies or opinions.
July 22nd, 2008 Alex Moffat Posted in EffectiveGWT, GWT | 1 Comment »
When we use RPC to retrieve suggestions it’s best if we limit the number of requests we make. This is to avoid overloading the server and because of the two connection limit that some browsers have. This restricts you to two open connections from the browser to each different server. I’m going to show what this looks like in terms of the pattern of requests made to the server and how this impacts the RPC SuggestOracle.
To demonstrate the limit I modified the requestSuggestions method in the SuggestOracle to make a call to an RPC service.
public void requestSuggestions(final Request request, final Callback callback) {
namesService.suggestions(request.getQuery(), request.getLimit(), new AsyncCallback() {
public void onFailure(Throwable caught) {
// Do nothing for now.
}
public void onSuccess(Object result) {
List<SuggestOracle.Suggestion> suggestions = (List<SuggestOracle.Suggestion>) result;
Response resp = new Response(suggestions);
callback.onSuggestionsReady(request, resp);
}
});
}
On the server side I implemented a simple RemoteServiceServlet that returns suggestions after a half second delay, to simulate some processing and transmission time for a remote server. It writes to stdout when it receives a request and when it responds to the request, and includes the number of requests in progress with the response. Running the application and typing “alexander” into the SuggestBox on different browsers gave interesting results. IE6, IE7 and Firefox 2 gave effectively the same pattern, allowing for a little variation caused by typing speed. Below are the results from IE6.
suggestions(a) suggestions(al) suggestions for a returning. inProgress=2 suggestions(ale) suggestions for al returning. inProgress=2 suggestions(alex) suggestions for ale returning. inProgress=2 suggestions(alexa) suggestions for alex returning. inProgress=2 suggestions(alexan) suggestions for alexa returning. inProgress=2 suggestions(alexand) suggestions for alexan returning. inProgress=2 suggestions(alexander) suggestions for alexand returning. inProgress=2 suggestions for alexander returning. inProgress=1
You can see a maximum of two connections in progress at once. Trying the same experiment with Firefox 3 and Safari 3 gives a different pattern of results. Both browsers were similar, this is what I saw for Firefox 3.
suggestions(a) suggestions(al) suggestions(ale) suggestions for a returning. inProgress=3 suggestions(alex) suggestions for al returning. inProgress=3 suggestions for ale returning. inProgress=2 suggestions(alexa) suggestions(alexan) suggestions(alexand) suggestions for alex returning. inProgress=4 suggestions for alexa returning. inProgress=3 suggestions for alexan returning. inProgress=2 suggestions(alexander) suggestions for alexand returning. inProgress=2 suggestions for alexander returning. inProgress=1
The limit here is at least four, apparently it’s actually eight. IE8 will allow six connections per host but I didn’t test that.
For the SuggestOracle I think it makes sense to limit the number of simultaneous connections to one. This leaves one available for other RPC calls on IE6 and IE7 and conserves server resources in all cases. My plan is to request from the server more results than the client immediately requires when making the first call. If the user types “al” and the SuggestBox is configured to request 10 results it’s wasteful to ask the server for 10 results for “al” and then another 10 for “ale”. Instead we could request 50 for “al” and then filter on the client to satisfy “ale”.
Of course whether or not this works depends on the practicality of filtering the results of one query to the server and using this to satisfy later client requests. If “al” actually produces 75 suggestions on the server and we only return 50 then filtering those 50 on the client to produce the “ale” suggestions is likely to give the wrong results. I’ll try an actual implementation of this approach next time.
December 20th, 2008 at 3:43 pm
[...] – bookmarked by 2 members originally found by iachan918 on 2008-11-17 Using the GWT SuggestBox with RPC – Part Two http://development.lombardi.com/?p=44 – bookmarked by 1 members originally found by infreemation [...]