AJAX Polling Frequency - To long poll or not to long poll?

后端 未结 2 1787
无人及你
无人及你 2021-02-13 11:16

I\'m building a component of a web page that needs relatively constant database polling. I can see two different approaches for this, and I\'m wondering if one of them is better

2条回答
  •  北恋
    北恋 (楼主)
    2021-02-13 11:30

    Long polling will scale better (i.e. less server load) than polling, while giving much better response times.

    If your recipient polls, the average journey time of a message will be half your poll interval.

    With long polling, its instant - the server only waits if there is nothing to say.

    If you are doing chat messaging, go long poll; its a usability thing.

    The down-side with long polling is it is more complicated to implement; but its not that much more complicated, and it is widely implemented. So if you can't use an off-the-shelf framework for your webserver of choice, you can set about writing one reasonably and you will get it working.

提交回复
热议问题