what's the skinny on long polling with ajax and webapi…is it going to kill my server? and string comparisons

后端 未结 2 718
生来不讨喜
生来不讨喜 2021-02-06 11:11

I have a very simple long polling ajax call like this:

(function poll(){
    $.ajax({ url: \"myserver\", success: function(data){
        //do my stuff here

            


        
2条回答
  •  被撕碎了的回忆
    2021-02-06 12:12

    OK, my two cents:

    1. As others said, SignalR is tried and tested code so I would really consider using that instead of writing my own.
    2. SignalR does change some of the IIS settings to optimise IIS for this sort of work. So if you are looking to implement your own, have a look at IIS setting changes done in SignalR
    3. I suppose you are doing long polling so that your server could implement some form of Server Push. Just bear in mind that this will turn your stateless HTTP machine into a stateful machine which is not good if you want to scale. Long polling behind a load ballancer is not nice :) For me this is the worst thing about server push.
    4. ASP.NET uses ThreadPool for serving requests. A long poll will hog a ThreadPool thread. If you have too many of these threads you might end up in thread starvation (and tears). As a ballpark figure, 100 is not too many but +1000 is.
    5. Even SignalR team say that the IIS box which is optimised for SingalR, probably not optimised for normal ASP.NET and they recommend to separate these boxes. So this means cost and overhead.

    At the end of the day, I recommend to using long polling if you are solving a business problem (and not because it is just cool) because then that will pay its costs and overheads and headaches.

提交回复
热议问题