小さな遊び場アプリを VPS でスムーズに実行するのに問題があります。アプリは開発マシンでスムーズに実行されますが、VPS に移動すると、最初のリクエストが完了するまでに時間がかかります。
IIS には特定の構成はありません。DNS はDNS Simpleでホストされています。
適切なアプリケーション プールをアプリケーションに割り当て、プールの権限を localSystem に変更しましたが、問題には影響しませんでした。
MVC4プロジェクト全体で唯一のハブ クラスを次に示します。
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
namespace SignalR_chat.Models
{
[HubName("chatHub")]
public class ChatHub : Hub
{
private static Dictionary<string, string> _userList = new Dictionary<string, string>();
public void AddText(string chatMessage)
{
var validUser = _userList.SingleOrDefault(s => s.Key == Context.ConnectionId);
var message = validUser.Value == string.Empty ? null :
string.Format("<li><b>{0}</b>: {1} </li>",
validUser.Value, HttpUtility.HtmlEncode(chatMessage));
if (message != null)
Clients.All.retrieveInput(message);
}
public void AddInUserList(string nickName, string connectionId)
{
_userList.Add(connectionId, nickName);
OnConnected();
}
public override Task OnDisconnected()
{
var userInstance = _userList.SingleOrDefault(x => x.Key == Context.ConnectionId);
if (userInstance.Value != string.Empty)
_userList.Remove(Context.ConnectionId);
OnConnected();
return null;
}
public override Task OnConnected()
{
var jsonObj = _userList.Count != -1
? new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(_userList)
: string.Empty;
if (jsonObj != string.Empty)
Clients.All.currentUsers(jsonObj);
return null;
}
}
}
Hubs ルートがGloabl.asaxに登録される方法は次のとおりです。
protected void Application_Start()
{
RouteTable.Routes.MapHubs();
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
そして、ここにシグナルイベントを処理するための私のjQueryコードがあります
/* File Created: July 24, 2012 */
/// <reference path="jquery-2.0.0.min.js" />
/// <reference path="jquery.signalR-0.5.3.min.js" />
/// <reference path="shortcut.js" />
/// <reference path="bootbox.min.js" />
/**********************/
/* Client functions */
/**********************/
var Chathub = $.connection.chatHub;
Chathub.client.retrieveInput = function (val) {
$('.chatList').append(val);
$(function () {
var height = $('.chatBox')[0].scrollHeight;
$('.chatBox').scrollTop(height);
});
$(function () {
var height = $('#chat')[0].scrollHeight;
$('#chat').scrollTop(height);
});
};
Chathub.client.currentUsers = function (list) {
$('.userList').empty();
var json = $.parseJSON(list);
$.each(json, function (name, value) {
$('.userList').append("<li>" + value + "</li>");
});
};
/**********************/
/* Server functions */
/**********************/
$.connection.hub.start().done(function () {
$('.chatInput').click(function () {
if (!localStorage.getItem('nickName')) {
$('.chatInput').attr('disabled', 'disabled');
window.bootbox.prompt('Enter nickname please', function (temp) {
if (temp) {
if (temp.length <= 10) {
localStorage.setItem('nickName', temp);
Chathub.server.addInUserList(temp, $.connection.hub.id);
$('.chatInput').unbind();
} else {
window.bootbox.alert("nickname must be 10 characters or less");
}
}
});
$('.chatInput').removeAttr('disabled', 'disabled');
} else {
Chathub.server.addInUserList(localStorage.getItem('nickName'), $.connection.hub.id);
$('.chatInput').unbind();
}
});
$('.submitChat').click(function () {
if ($('.chatInput').val() != '' && localStorage.getItem('nickName')) {
Chathub.server.addText($('.chatInput').val());
$('.chatInput').val('');
}
});
});
shortcut.add("Enter", function () {
$('.submitChat').click();
});
$.connection.hub.stateChanged(function (change) {
if (change.newState === $.signalR.connectionState.reconnecting) {
$('.chatBox').addClass("Tilt");
$('.overlay').css('display', 'block');
} else if (change.newState === $.signalR.connectionState.connected) {
$('.chatBox').removeClass("Tilt");
$('.overlay').css('display', 'none');
}
});
jQueryの接続が同期的に処理されていることを知っている限り、これが完全なプロジェクトです。つまり、.done()のリンクイベントです。
最後のポイントとして、JS ライブラリに対してのみバンドルと縮小を使用していますが、「~/signalr/hubs」は含めず、レイアウト ビューで個別にリンクされたままにします。
前もって感謝します
編集: SignalR 1.0.1を使用していることを忘れていました
Edit2:フィドラーで問題をデバッグしようとしましたが、特定の詳細が見つかりませんでした。私が気付いた唯一のことは、すべてのセッションを削除した後のすべての最初のリクエストで、21 秒で応答が得られますが、その後のすべての要求はかなり高速な応答を受け取ることです。以下は、すべてのセッションを終了した後のリクエストと、セッションを終了する前のリクエストのフィドラーからの統計です。
新しいセッション統計
Request Count: 1
Bytes Sent: 332 (headers:332; body:0)
Bytes Received: 3,234 (headers:169; body:3,065)
ACTUAL PERFORMANCE
--------------
ClientConnected: 17:35:30.949
ClientBeginRequest: 17:35:30.949
GotRequestHeaders: 17:35:30.949
ClientDoneRequest: 17:35:30.949
Determine Gateway: 0ms
DNS Lookup: 0ms
TCP/IP Connect: 21102ms
HTTPS Handshake: 0ms
ServerConnected: 17:35:52.054
FiddlerBeginRequest: 17:35:52.054
ServerGotRequest: 17:35:52.054
ServerBeginResponse: 17:35:52.275
GotResponseHeaders: 17:35:52.275
ServerDoneResponse: 17:35:52.275
ClientBeginResponse: 17:35:52.275
ClientDoneResponse: 17:35:52.275
Overall Elapsed: 0:00:21.326
RESPONSE BYTES (by Content-Type)
--------------
text/html: 3,065
~headers~: 169
REQUESTS PER HOST
--------------
[removing this one]
ESTIMATED WORLDWIDE PERFORMANCE
--------------
The following are VERY rough estimates of download times when hitting servers based in WA, USA.
US West Coast (Modem - 6KB/sec)
RTT: 0.10s
Elapsed: 0.10s
Japan / Northern Europe (Modem)
RTT: 0.15s
Elapsed: 0.15s
China (Modem)
RTT: 0.45s
Elapsed: 0.45s
US West Coast (DSL - 30KB/sec)
RTT: 0.10s
Elapsed: 0.10s
Japan / Northern Europe (DSL)
RTT: 0.15s
Elapsed: 0.15s
China (DSL)
RTT: 0.45s
Elapsed: 0.45s
セッション終了前の統計
Request Count: 1
Bytes Sent: 332 (headers:332; body:0)
Bytes Received: 3,234 (headers:169; body:3,065)
ACTUAL PERFORMANCE
--------------
ClientConnected: 17:37:56.795
ClientBeginRequest: 17:37:56.795
GotRequestHeaders: 17:37:56.795
ClientDoneRequest: 17:37:56.795
Determine Gateway: 0ms
DNS Lookup: 0ms
TCP/IP Connect: 0ms
HTTPS Handshake: 0ms
ServerConnected: 17:35:52.054
FiddlerBeginRequest: 17:37:56.795
ServerGotRequest: 17:37:56.795
ServerBeginResponse: 17:37:56.899
GotResponseHeaders: 17:37:56.899
ServerDoneResponse: 17:37:56.899
ClientBeginResponse: 17:37:56.899
ClientDoneResponse: 17:37:56.899
Overall Elapsed: 0:00:00.103
RESPONSE BYTES (by Content-Type)
--------------
text/html: 3,065
~headers~: 169
REQUESTS PER HOST
--------------
[removing this one]
ESTIMATED WORLDWIDE PERFORMANCE
--------------
The following are VERY rough estimates of download times when hitting servers based in WA, USA.
US West Coast (Modem - 6KB/sec)
RTT: 0.10s
Elapsed: 0.10s
Japan / Northern Europe (Modem)
RTT: 0.15s
Elapsed: 0.15s
China (Modem)
RTT: 0.45s
Elapsed: 0.45s
US West Coast (DSL - 30KB/sec)
RTT: 0.10s
Elapsed: 0.10s
Japan / Northern Europe (DSL)
RTT: 0.15s
Elapsed: 0.15s
China (DSL)
RTT: 0.45s
Elapsed: 0.45s
Edit3: VS で次の出力に気付きました。
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Internals\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Internals.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Data.Linq.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xaml.Hosting\v4.0_4.0.0.0__31bf3856ad364e35\System.Xaml.Hosting.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Transactions\v4.0_4.0.0.0__b77a5c561934e089\System.Transactions.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Workflow.ComponentModel\v4.0_4.0.0.0__31bf3856ad364e35\System.Workflow.ComponentModel.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Workflow.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.Workflow.Activities.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Workflow.Runtime\v4.0_4.0.0.0__31bf3856ad364e35\System.Workflow.Runtime.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.DurableInstancing\v4.0_4.0.0.0__31bf3856ad364e35\System.Runtime.DurableInstancing.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xaml\v4.0_4.0.0.0__b77a5c561934e089\System.Xaml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Build.Framework\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.Build.Framework.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.Entity\v4.0_4.0.0.0__b77a5c561934e089\System.Data.Entity.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\SMDiagnostics\v4.0_4.0.0.0__b77a5c561934e089\SMDiagnostics.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\Microsoft.VisualBasic.Activities.Compiler\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualBasic.Activities.Compiler.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Mobile\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.Mobile.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'Anonymously Hosted DynamicMethods Assembly'
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\XXX\AppData\Local\Temp\Temporary ASP.NET Files\root\c514b873\93518333\App_Web_lcqvz5d1.dll', Symbols loaded.
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\XXX\AppData\Local\Temp\Temporary ASP.NET Files\root\c514b873\93518333\App_Web_l5dllaun.dll', Symbols loaded.
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Dynamic\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Dynamic.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The thread '<No Name>' (0x275c) has exited with code 0 (0x0).
The thread '<No Name>' (0x1f80) has exited with code 0 (0x0).
The thread '<No Name>' (0x1878) has exited with code 0 (0x0).
The thread '<No Name>' (0x2238) has exited with code 0 (0x0).
The thread '<No Name>' (0x69c) has exited with code 0 (0x0).
The thread '<No Name>' (0x21d0) has exited with code 0 (0x0).
The thread '<No Name>' (0xadc) has exited with code 0 (0x0).
The thread '<No Name>' (0x1278) has exited with code 0 (0x0).
The thread '<No Name>' (0x177c) has exited with code 0 (0x0).
The thread '<No Name>' (0x1e90) has exited with code 0 (0x0).
The thread '<No Name>' (0x1988) has exited with code 0 (0x0).
The thread '<No Name>' (0x56c) has exited with code 0 (0x0).
The thread '<No Name>' (0x1100) has exited with code 0 (0x0).
The thread '<No Name>' (0x22c4) has exited with code 0 (0x0).
The program '[7720] iisexpress.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
The program '[7720] iisexpress.exe: Program Trace' has exited with code 0 (0x0).
どうやら一部のタスクにはいくつかの例外があります。それが私のコードなのか、それとも他の問題なのかわかりません