背景資料:我使用MVC 4.我打電話服務器上的PersistentConnection SignalR方法,並且延遲20秒調用之前回到客戶端回調方法。在回調方法中,我將url設置爲MVC控制器中的下載方法,以便啓動文件流下載。SignalR PersistentConnection無法調用客戶端回調方法的時候40-50%在Azure上
問題是:這一切工作完全正常與IIS 7.5的本地託管網站,但是當我部署到Azure雲是很不一致。我已經做了Chrome和IE 10試運行:在Chrome,下載失敗踢入的時間和IE 10 40%的下載不會發生時間的50%。所以發生的事情是回調方法不被稱爲40-50%的時間。我知道這是事實,因爲我把JavaScript代碼放在那裏以打印當前頁面的時間,但這並不是很好。這裏使用的是Chrome和IE 10的網絡流量的一些截圖:
Chrome的成功:
鉻失敗:
IE 10次成功:
IE 10失敗:
我真的需要在使用此庫之前,使用Azure的SignalR回調對客戶端來說是100%有效的。這是SignalR的一個已知錯誤嗎?還是在Windows Azure中使用這個信號發生器有不同的方法?
這裏是我的代碼:
SERVER:
public class MultiFileConnection : PersistentConnection
{
protected override Task OnReceived(IRequest request, string connectionId, string data)
{
System.Threading.Thread.Sleep(20000);
return Connection.Send(connectionId, data);
}
}
客戶:
$('#dBtn').click(function() {
var docIds = sceneLayoutService.getSelection();
var href;
var docIdsParam;
if (docIds.length === 0) {
alert("you need to select one");
return false;
}
else if (docIds.length == 1) {
docIdsParam = "docId=" + docIds;
href = window.baseUrl;
var today = new Date();
// Initialize SignalR connection
var connection = $.connection(href + "/multifile");
$("#test-signalr").append("<li>" + today + "</li>");
// SignalR callback method by server
connection.received(function (data) {
today = new Date();
$("#test-signalr").append("<li>" + today + "</li>");
connection.stop();
href = window.baseUrl + '/CloudStorage/Download?' + docIdsParam;
window.location.href = href;
});
// SignalR send data to the server
connection.start()
.done(function() {
connection.send("you need to select one!!");
})
.fail(function() {
alert("Error connecting to signalr realtime service");
});
}
else {
docIdsParam = jQuery.param(docIds.map(function (value) {
return { "name": "docIds", "value": value };
}));
href = window.baseUrl + '/CloudStorage/DownloadZip?' + docIdsParam;
}
return true;
});
LIST包:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Company.CONNECT.Analytics.eFWrapper" version="1.0.0.1" targetFramework="net40" />
<package id="Company.CONNECT.Analytics.Logging" version="1.0.0.11" targetFramework="net40" />
<package id="Company.CONNECT.Web" version="1.1.0.12" targetFramework="net40" />
<package id="Castle.Core" version="2.5.2" targetFramework="net40" />
<package id="Castle.Core-log4net" version="2.5.2" targetFramework="net40" />
<package id="Castle.Windsor" version="2.5.4" targetFramework="net40" />
<package id="Castle.Windsor-log4net" version="2.5.2" targetFramework="net40" />
<package id="CommonServiceLocator" version="1.0" targetFramework="net40" />
<package id="EnterpriseLibrary.Common" version="5.0.505.0" targetFramework="net40" />
<package id="EnterpriseLibrary.WindowsAzure.Configuration" version="5.0.1118.2" targetFramework="net40" />
<package id="EntityFramework" version="4.1.10331.0" targetFramework="net40" />
<package id="HtmlAgilityPack" version="1.4.6" targetFramework="net40" />
<package id="jQuery" version="2.0.2" targetFramework="net40" />
<package id="jQuery.UI.Combined" version="1.10.3" targetFramework="net40" />
<package id="jQuery.Validation" version="1.8.0" targetFramework="net40" />
<package id="jQuery.vsdoc" version="1.5.1" targetFramework="net40" />
<package id="log4net" version="1.2.10" targetFramework="net40" />
<package id="Microsoft.AspNet.Mvc" version="4.0.30506.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Providers" version="1.1" targetFramework="net40" />
<package id="Microsoft.AspNet.Providers.Core" version="1.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Razor" version="2.0.30506.0" targetFramework="net40" />
<package id="Microsoft.AspNet.SignalR" version="1.1.2" targetFramework="net40" />
<package id="Microsoft.AspNet.SignalR.Core" version="1.1.2" targetFramework="net40" />
<package id="Microsoft.AspNet.SignalR.JS" version="1.1.2" targetFramework="net40" />
<package id="Microsoft.AspNet.SignalR.Owin" version="1.1.2" targetFramework="net40" />
<package id="Microsoft.AspNet.SignalR.SystemWeb" version="1.1.2" targetFramework="net40" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.0.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebPages" version="2.0.30506.0" targetFramework="net40" />
<package id="Microsoft.Data.Edm" version="5.5.0" targetFramework="net40" />
<package id="Microsoft.Data.OData" version="5.5.0" targetFramework="net40" />
<package id="Microsoft.IdentityModel" version="6.1.7600.16394" targetFramework="net40" />
<package id="Microsoft.Owin.Host.SystemWeb" version="1.0.1" targetFramework="net40" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.1.0" targetFramework="net40" />
<package id="Modernizr" version="2.6.2" targetFramework="net40" />
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" />
<package id="Owin" version="1.0" targetFramework="net40" />
<package id="Pkcs12ProtectedConfigurationProvider" version="1.0.1" targetFramework="net40" />
<package id="RequireJS" version="2.1.8" targetFramework="net40" />
<package id="SevenZipSharp" version="0.64" targetFramework="net40" />
<package id="SlowCheetah" version="2.5.5" targetFramework="net40" />
<package id="System.Spatial" version="5.5.0" targetFramework="net40" />
<package id="System.Web.Providers" version="1.2" targetFramework="net40" />
<package id="Unity" version="2.1.505.2" targetFramework="net40" />
<package id="Unity.Interception" version="2.1.505.2" targetFramework="net40" />
<package id="WebGrease" version="1.1.0" targetFramework="net40" />
<package id="WindowsAzure.Storage" version="2.0.5.1" targetFramework="net40" />
<package id="WindowsAzure.Storage" version="2.0.6.0" targetFramework="net40" />
</packages>
將不勝感激任何幫助!
你有一個以上的機器嗎?如果你這樣做,請閱讀http://www.asp.net/signalr/overview/performance-and-scaling/scaleout-in-signalr – davidfowl
我必須檢查一下。所以你說的是,從服務器發送的一些消息很可能會丟失,因爲在Azure中使用了2臺或更多服務器(在我們的例子中)? – TheDude
我有一個理論。請讓我知道,如果我不符合標準,因爲我對這一切都很陌生。如果Azure服務器場中有兩臺服務器,那意味着我的Web應用程序有兩個實例。客戶端連接到其中一個實例併發送客戶端ID和消息。然後Azure負載平衡器選擇其中一個實例來回應客戶端(所以它就像一個響應的硬幣的翻轉)。如果沒有連接到客戶端的人響應,則失敗。否則,正確的實例響應成功。我在大球場嗎? – TheDude