What is the proper refres开发者_如何学编程h rate to balance quality and not crashing the server?
Don't poll for new messages (any refresh rate will become unaffordable when scaling), just make the server push new messages to the AJAX client.
Have a look at Comet (long held http request)
This depends on a large range of factors, e.g. response time, server size, expected capacity, bandwidth. I'd say once every 500ms on completion of a request would feel comfortable.
Make sure to start the timer after the last request completed, otherwise they'll queue up and overlap due to latency.
I'd suggest when doing this, pass a datetime back and forth, push the time of the last message to the client when sending, and when requesting send that time back to the server, so you're only returning messages after that time, the minimum amount of chat data.
精彩评论