2016-04-01 2 views
11

Nous avons un problème avec signalR. Nous avons un site d'enchères qui fonctionne sur signalr pour les enchères en temps réel. Nous avons corrigé certains problèmes avec le navigateur et tout semblait fonctionner correctement. Ensuite, nous avons installé une nouvelle relique sur notre serveur et avons remarqué que chaque minute, nous obtenons le code d'erreur http 400 sur signalr, se reconnecter et abandonner. Voici une capture d'écran:SignalR provoquant une mauvaise demande 400 vu sur le serveur

New Relic Data

SignalR connecter et reconnectez sont les plus de temps les opérations du site selon une nouvelle relique.

est ici code backend SignalR (Nous utilisons le serveur SQL en tant que fond de panier signalr):

public class SignalRHub : Hub 
{ 
    public void BroadCastMessage(String msg) 
    { 
     var hubContext = GlobalHost.ConnectionManager.GetHubContext<SignalRHub>(); 

     hubContext.Clients.All.receiveMessage(msg); 
    } 
} 

public partial class Startup 
{ 
    public void Configuration(IAppBuilder app) 
    { 
     string appString=string.Empty; 

     //Gets the connection string. 
     if (System.Configuration.ConfigurationSettings.AppSettings["SignaRScaleoutConn"] != null) 
     { 
      appString = System.Configuration.ConfigurationSettings.AppSettings["SignaRScaleoutConn"].ToString(); 
     } 

     GlobalHost.DependencyResolver.UseSqlServer(appString); 
     GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromMinutes(15); //I added this timeout, but it is not required. 
     app.MapSignalR(); 
    } 
} 

Le client javascript ressemble à ceci, il est long, mais la plupart est jQuery d'affecter les DOM, je l'inclus tout au cas où quelque chose pourrait mal se passer à l'intérieur.

$(function() { 

      var chatProxy = $.connection.signalRHub; 

      $.connection.hub.start(); 

      chatProxy.client.receiveMessage = function (msg) { 

       var all = $(".soon").map(function() { 

        var hiddenModelId = $("#hiddenListingId"); 

        if (msg == hiddenModelId.val()) { 

         $.ajax({ 
          async: "true", 
          url: "/Listing/AuctionRemainingTime", 
          type: "POST", 
          dataType: 'json', 
          data: '{ "listingID": "' + msg + '"}', 
          contentType: "application/json; charset=utf-8", 
          success: function (data) { 
           if (data != null) { 

            SoonSettings.HasReloadedThisTick = false; 

            var element = document.getElementById(msg); 

            var obj = JSON.parse(data) 

            // For Clock Counter End Date Time Interval 
            // Adds 2 minutes to the soon clock when bid is close to finishing. 
            var hdID = "hdn" + obj.ListingId; 
            var hdValue = $("#" + hdID); 
            if (obj.EndDate != hdValue.val()) { 

             SoonSettings.HasUpdated = false; //Allows clock to change color once it gets under two minutes. 

             $('#' + hdID).val(obj.EndDate); 
             Soon.destroy(element); 
             Soon.create(element, { //Recreates clock with the before 2 minute tick event. 
              'due': 'in ' + obj.Seconds + ' seconds', 
              'layout':'group label-uppercase', 
              'visual':'ring cap-round progressgradient-00fff6_075fff ring-width-custom gap-0', 
              'face':'text', 
              'eventTick': 'tick' 
             }); 
            } 

            var highbid = obj.HighBidderURL; 

            // For Date Ends Info. 
            var ListingEndDate = $("#tdAuctionListingEndDate"); 

            if (obj.EndDate != ListingEndDate.val()) { 
             $('#' + hdID).val(obj.EndDate); 
             ListingEndDate.text(obj.EndDate + " Eastern"); 
             ListingEndDate.effect("pulsate", { times: 5 }, 5000); 
            } 
            else 
            { 
             $(".Bidding_Current_Price").stop(true, true); ///Removes the pulsating effect. 
             $(".Bidding_Current_Price").removeAttr("style"); //Removes unnecessary attribute from HTML. 
            } 

            //Bid div notification. 
            if (obj.AcceptedActionCount.replace(/[^:]+:*/, "") > 0) { 

             if (obj.Disposition != '' && obj.Disposition != null) { 
              if (obj.Disposition == "Neutral") { 
               $("#spanNeutralBid").show(); 
               $("#divOutbidNotification").hide(); 
               $("#spanPositiveBid").hide(); 
               $("#divProxyBidNotification").hide(); 
              } 
              else if (obj.Disposition == "Positive") { 
               $("#spanPositiveBid").show(); 
               $("#divOutbidNotification").hide(); 
               $("#spanNeutralBid").hide(); 
               $("#divProxyBidNotification").hide(); 
              } 
              else if (obj.Disposition == "Negative") { 
               $("#divOutbidNotification").show(); 
               $("#spanNeutralBid").hide(); 
               $("#spanPositiveBid").hide(); 
               $("#divProxyBidNotification").hide(); 
              } 
              else { 
               $("#divOutbidNotification").hide(); 
               $("#spanNeutralBid").hide(); 
               $("#divProxyBidNotification").hide(); 
               $("#spanPositiveBid").hide();  
              } 

             } 
            } 

            // For Highlight Current Price when it is Updated 
            var hdCurrentPrice = $("#hdnCurrentPrice"); 

            if (obj.CurrentPrice != hdCurrentPrice.val()) { 

             $(".Bidding_Current_Price").text(obj.CurrentPrice); 
             $(".Bidding_Current_Price").effect("pulsate", { times: 5 }, 5000); 
             $("#hdnCurrentPrice").val(obj.CurrentPrice); 
            } 
            else { 
             $(".Bidding_Current_Price").stop(true, true); 
             $(".Bidding_Current_Price").removeAttr("style"); 
            } 

            // For ReservePrice Status 
            $("#spanReservePriceStatus").html(obj.ReservePriceStatus); 
            $("#smallReservePriceStatus").html(obj.ReservePriceStatus); 

            // For Bid Count 

            var spanBidCounter = $("#spanBidCount"); 

            $(spanBidCounter).text(obj.AcceptedActionCount); 


            var stringAppend = "<tr id='trhHighBidder'><td><strong>HighBidder</strong></td>"; 
            stringAppend += "<td>"; 
            if (obj.isAdmin == true) { 
             stringAppend += "<a id='anchorHighBid' href=" + obj.HighBidderURL + ">"; 
             stringAppend += "<span id='spanHighBidder'>" + obj.CurrentListingActionUserName + "</span>" 
             stringAppend += "</a>"; 
            } 
            else { 
             stringAppend += "<span id='spanHighBidderAnonymous'>" + obj.CurrentListingActionUserName + "</span>"; 
            } 
            stringAppend += "</td></tr>"; 

            if (obj.AcceptedActionCount.replace(/[^:]+:*/, "") > 0) { 
             if ($("#tblAuctionDetail").find("#rowHighBidder").length > 0) { 

              if ($("#tblAuctionDetail").find("#trhHighBidder").length > 0) { 
               $("#trhHighBidder").remove(); 
              } 
             } 
             else { 

              //add tr to table 
              if (!$("#tblAuctionDetail").find("#trhHighBidder").length > 0) { 
               $('#tblAuctionDetail > tbody > tr:eq(6)').after(stringAppend); 
              } 
             } 
            } 

            // For High Bidder 

            if (obj.isAdmin) { 

             var anchorElement = $("#anchorHighBid"); 
             $(anchorElement).attr("href", obj.HighBidderURL); 

             var spanHighBidder = $("#spanHighBidder"); 
             $(spanHighBidder).text(obj.CurrentListingActionUserName); 
            } 
            else { 
             var spanAdminHighBid = $("#spanHighBidderAnonymous"); 
             $(spanAdminHighBid).text(obj.CurrentListingActionUserName) 
            } 

           } 
          }, 
          error: function (xhr, textStatus, errorThrown) { 

          } 
         }); 
        } 
       }); 
      }; 

     }); 

Y at-il un problème avec le client ou le code du signal du serveur qui doit être modifié pour éviter que ces erreurs se produisent si souvent? Le code 400 a tendance à apparaître presque chaque minute. Je suis très nouveau pour signalerR et je sais très peu de comment faire du code efficace avec.

Les enchères en temps réel sur le site fonctionnent, c'est juste pour trouver un moyen d'éviter ces erreurs constantes. Toute aide expliquant quoi que ce soit du fonctionnement de signalR est appréciée.

Merci,

+2

Nous obtenons également les mêmes erreurs parfois. Nous utilisons le bus de service comme fond de panier. Je pense que c'est lié à backplane et loadbalancer. Avez-vous loadbalancer ou autoscaling? –

+0

Nous avons un équilibreur de charge intéressant. Je n'avais pas pensé à cela à l'origine de ce problème. –

+0

qu'est-ce qu'il y a dans le corps de la réponse "Bad Request"? –

Répondre