Hello,

The first thing I would suggest is this is one of those cases where the X in AJAX probably isn't appropriate. Remember that there is NO requirement to use XML when doing AJAX (although I suppose it isn't AJAX then strictly speaking).

Take Google Suggests for example. They are not passing back XML, they are actually passing back, if memory serves, a chunk of Javascript that they execute. I seem to recall it being just a Javascript array that is used to populate the dropdown, but I may not have all the details right. The point though is that it isn't XML.

Aside from that, one thing Google does too is they actually throttle the requests. I don't have all the details, I just heard it explained once at a user group meeting, but basically, the faster a person types, the LESS requests go across, and that is dynamically calculated.

Another thing you can do is write the code such that the request will only fire X number of milliseconds after the last keyUp is received. Maybe wait half a second after keyUp, and if a keyDown fires in the mean time, you reset the counter. You would have to balance things so that the delay doesn't lead to a poor user experience, but I think that can be done. (I just saw Rick's reply as I was typing this, he makes the same basic suggestion).

On the server-side, if possible, implement some sort of caching. Without knowing what kind of data you are using in your autocomplete, I can't make any specific suggestions. But basically, if you can cache a subset of the most frequently used data on the server, then you won't have to hit the database as often. Maybe its even possible to cache the entire database contents on the app server?

At the end of the day there are two considerations: how many requests you make of the server, and what the server actually has to do to service the request. If this is a LAN/WAN application, you will find the greater bottleneck is almost certainly what the server has to do. If it's Internet-based, the opposite may be true. One bit of advice is to not assume you have a problem at all! In this case you may, but do some basic testing first. I've seen people assume that AJAX is horrible for network traffic when just the opposite wound up being true. Then again, I've seen people who assumed just the opposite and got burned :)

Frank

Joel Alejandro Espinosa Carra wrote:
Hello all,

I'm coding a simple action that retrieves some data from the database in order to create an xml object for an ajax-based autocomplete field, I'm worried about the load of the database beacuse this action is called from a javascript event "onkeyup()" this means that the action will be executed every time when user press a key in the field, is there an other way to do this in order to increase the performance?

pd. this is not a must-have requirement but I want to know what is the best way to do this.

Best regards.


--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: [EMAIL PROTECTED]
Java Web Parts -
http://javawebparts.sourceforge.net
Supplying the wheel, so you don't have to reinvent it!

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to