Reputation:
I am working on building an ajax based messaging system. The idea is that client will call server every X number of seconds to get latest messages and some other crucial information. The application depends very heavily on this data being delivered to client. I have tested it on all kinds of connections and everything seems to be working perfectly. During one demo testing run, we observed that some clients were showing "undefined" text at places where the information from server supposed to be shown. That kind of tells me that server response is chopped or things like that which caused java script to choke.
There seems to be only thing common amongst clients who have reported the issue is that they are behind slow connection. And about 20 browsers were open on dozen different machines and all using same switch.
Bottom line is that it seems to be issue with clients with very slow connectivity. I have set the time out for the AJAX call to match the frequency at which these requests are sent. For now this time out and timer for sending calls is 5 seconds. The response payload is only 150-160 bytes.
Assuming that this is issue with slow connection and timeout, what would be best practice and strategy to deal this kind of situation?
Thanks
Upvotes: 1
Views: 1118
Reputation: 13707
It would help to use a tool in your dev environment that can simulate slow connections and simulate high-latency connections. This will let you reproduce the error in your dev environment, and begin to observe the behavior as it happens.
My opensource tool DonsProxy can help with that, but there are other tools, too.
Upvotes: 0
Reputation:
Second request is not sent untill first one completes. That part is already taken care of. I think increasing the time out will be one change that I can make.
Thing that is very strange is that the display will only show "undefined" if the call succeeded and execution reached up to the point of setting text for that HTML element. That is the part I do not get. I have tried returning null strings from server even those get translated into empty string on client side and worst case, they end up causing EMPTY strings to be displayed which is the intended behavior of application that under certain conditions if data does not match some conditions, it should clear the values in display.
Upvotes: 0
Reputation: 401162
Even with a great connection, there is always a risk of failure ; so, you definitly have to deal with the "failure" case ; ie, not displaying "undefined
".
You can imagine a system which would "silently fail" for maybe one minute (data won't be updated on the page, but you don't tell the user).
And if it fails for longer than this, you display a message like "you have a connectivity problem, there might be something wrong ; the application will not work OK without an Internet connection.".
(This case can happen quite often if users are using wifi, or a mobile-based connection)
Upvotes: 1
Reputation: 34711
That timeout sounds too short for that scenario. Increase the timeout to 10-15 seconds and don't send the second request if the first hasn't returned yet. The size of the content may be really small, but it's a latency issue.
Upvotes: 1