A lengthy survey is a great technique, but as with any solution, efficiency depends on many variables, including hardware tuning, and therefore there are no absolute solutions.
Keep in mind that the lengthy survey that you maintain on the connection can cause problems with many clients.
You must consider: -
- Do I need to be practically in real time (for example, for an exchange trader).
- How often ajax data / output changes (chat and new comment)
- How often an event occurs that causes changes in ajax I / O triggers. This will determine how the cache is generated.
You have to be humble when it comes to ajax. The request and response should be based on needs. The success of ajax implementation will not be complete without a well-designed caching solution, which is based on events rather than requests.
The following is a simplified version of one of those methods that we found useful in the project: -
- Each Ajax polling request made will contain output_hash , which is a digest of data previously returned by the server.
- The server checks this output_hash for a recent hash of the output that it generated from a data source, preferably cached.
- If it is different, it will serve the new content along with the new output_hash . Another small answer / Not modified to indicate that there is no new content.
In our solution, we also performed a dynamic calculation of the interval of the next survey. Saving interval dynamics allows the server to control the request. For example, suppose that most comments / responses occur within the first 1 hour, except that there is no time with an interval of 1 second, so the server can increase this to 2.3 or even 5 seconds dynamically with increasing time, but rather tough 2 sec interval encoding Similarly, the interval time can be reduced if a flurry of activity occurs in the old column.
We also checked for non-working customers and more.
source share