SignalR 1.0.1在Windows 2008 R2服务器/ IIS 7.5上缓慢响应第一个响应

时间:2013-05-11 18:56:06

标签: asp.net asp.net-mvc asp.net-mvc-4 iis-7.5 signalr

我无法让我的小型游乐场应用程序在我的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');
    }
});

这是完整的project,据我所知,jQuery中的连接是同步处理的,即.done()中的链接事件

最后一点,我只对JS库使用捆绑和缩小,但不包括&#34;〜/ signalr / hubs&#34;这样在布局视图中保持单独链接。

提前致谢

编辑:忘了提及我使用SignalR 1.0.1

编辑2:我尝试用fiddler调试问题但是,我找不到任何具体的细节。我注意到的唯一事情是,在删除所有会话后的每个第一个请求中,我在21秒内收到响应,但之后的所有请求都得到了相当快的响应。以下是fiddler在结束所有会话后的请求和在结束会话之前的请求的统计信息。

新会话统计信息

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

编辑3: 我注意到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).

显然在某些任务中有一些例外。不确定它是否是我的代码或其他问题

0 个答案:

没有答案