如何最佳地对SignalR hubs应用进行负载测试?

26

我想了解一些测试基于SignalR hubs的应用程序所使用的不同方法。

5个回答

10

简而言之,如果使用Hubs,则使用.Net客户端就足够了。

在我的情况下,我有一个新闻订阅Hub,根据用户的配置文件ID提供客户端特定数据。在我的测试案例中,我加载了一堆配置文件ID(本例中为6000),调用名为JoinNewsfeed()的hub方法,同时提供客户端特定的连接ID和配置文件ID。每100毫秒建立一个新的连接。

    [TestMethod]
    public void TestJoinNewsfeedHub()
    {
        int successfulConnections = 0;

        // get profile ID's
        memberService = new MemberServiceClient();
        List<int> profileIDs = memberService.GetProfileIDs(6000).ToList<int>();

        HubConnection hubConnection = new HubConnection(HUB_URL);
        IHubProxy newsfeedHub = hubConnection.CreateProxy("NewsfeedHub");


        foreach (int profileID in profileIDs)
        {
            hubConnection.Start().Wait();
            //hubConnection = EstablishHubConnection();
            newsfeedHub.Invoke<string>("JoinNewsfeed", hubConnection.ConnectionId, profileID).ContinueWith(task2 =>
            {
                if (task2.IsFaulted)
                {
                    System.Diagnostics.Debug.Write(String.Format("An error occurred during the method call {0}", task2.Exception.GetBaseException()));
                }
                else
                {
                    successfulConnections++;
                    System.Diagnostics.Debug.Write(String.Format("Successfully called MethodOnServer: {0}", successfulConnections));

                }
            });

            Thread.Sleep(100);

        }

        Assert.IsNotNull(newsfeedHub);
    }

这里列出的性能指标在服务器上起到了作用。为确保客户端已连接并且在服务器上成功完成了填充客户端对象的过程,我有一个服务器端方法,它调用一个客户端函数,并提供从已连接客户端集合中派生的连接客户端数量和列表。


8

@ElHaix,根据我自己的测试结果,你的方法并没有创建新的连接,而是重用了现有的连接。当你循环遍历profileIDs集合时,你应该会发现hubConnection.ConnectionID保持不变。如果想要创建一个新的连接,你需要在foreach循环内部创建一个HubConnection实例。

        int successfulConnections = 0;
        const int loopId = 10;

        Console.WriteLine("Starting...");
        for (int i = 1; i <= loopId; i++)
        {
            Console.WriteLine("loop " + i);

            var hubConnection = new HubConnection(HUB_URL);
            IHubProxy chatHub = hubConnection.CreateProxy(HUB_NAME);

            Console.WriteLine("Starting connection");
            hubConnection.Start().Wait();
            Console.WriteLine("Connection started: " + hubConnection.ConnectionId);

            chatHub.Invoke("Register", "testroom").ContinueWith(task2 =>
            {
                if (task2.IsFaulted)
                {
                    Console.WriteLine(String.Format("An error occurred during the method call {0}", task2.Exception.GetBaseException()));
                }
                else
                {
                    Console.WriteLine("Connected: " + hubConnection.ConnectionId);
                    successfulConnections++;
                }
            });

            Thread.Sleep(1000);
        }

你添加了哪些软件包? - RredCat

3
Crank 只能测试 PersistenConnections,但如果您想测试 SignalR Hub 本身,则可以使用 Tresi。不过,这是一个商业应用程序。以下是有关如何针对不同类型的负载进行性能测试的一些链接:
1. 恒定负载 2. 逐渐增加负载 3. 突发负载 HTTPWebRequests 的性能计数器设置(例如 Created/Sec、Aborted/Sec、Average Lifetime 等)在负载测试执行期间显示。它还显示其他计算度量标准,例如每用户吞吐量。下面是该应用程序的屏幕截图。

enter image description here


1

使用Gatling工具编写自己的脚本以创建虚拟用户(多线程),并使用Java SignalR客户端。如果您想知道如何将自定义的Java或Scala脚本附加到Gatling虚拟用户,请在评论中说明。如果需要进行SignalR性能测试的测试计划,请告诉我,因为这是进行测试的关键。


1

我在SignalR上并没有进行过太多的性能测试,但该项目提供了一个有用的工具Crank,可以生成客户端负载。

该项目维基还提供了一些关于有用的性能计数器和设置的指导。


6
据我理解,Crank 不适用于轮毂。还有其他需要翻译的吗? - ElHaix

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接