如何找到30个同时用户的执行时间.. [英] how to find the execution time for 30 simulataneous users..

查看:62
本文介绍了如何找到30个同时用户的执行时间..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的Windows应用程序,单击按钮将显示数据网格中的用户列表,以在文本框中输入的名称开头..



我想了解如果有30个用户同时使用此搜索页面并找出将结果提取到我的Windows应用程序的数据网格所需的时间,我需要花多少钱。





示例代码:

  private   void  btnseacrh_Click( object  sender,EventArgs e)
{
var name = txttextbox.Text;

var Resultdataset = Fecthresultfromdb(name);

// retchresultfromdb方法调用数据库并提取名称为//的所有人员在文本框中输入'name'值

// 最后结果集是绑定到datagrid以显示

datagrid.datasource = Resultdataset;

}



现在我想知道是否有30个用户同时使用此seacrher窗口,需要多长时间..这是必须在3秒内完成的非功能性要求之一。



请告诉我需要做哪些修改。也可以共享修改后的代码片段。

解决方案

您所询问的是负载测试。根据您使用的Visual Studio版本,有内置工具可帮助您加载测试应用程序。请参阅 Visual Studio负载测试工具 [ ^ ]



如果您正在使用其他一些没有这些工具的版本,你应该看看 .net的第三方负载测试工具 [ ^ ]。



你的另一个选择是创建一个单元测试应用程序和队列同时命中数据库的30个并行任务,并使用性能计数器来测量响应,但这需要更多的设置n使用负载测试工具。谷歌链接中的一些可能有试运行版本,可运行几天或多个并发测试,评估每个版本以找到满足您需求的版本。







这是一个示例,你可以做的简单负载测试:



< pre lang =C#> public class LoadTester
{

列表< TimeSpan> times = new 列表< TimeSpan>();

public void 测试()
{
Thread [] threads = new 线程[ 30 ];

for int i = 0 ; i < 30 ; i ++)
{
个线程[i] = new 线程( new ThreadStart(TestDBConn));
threads [i] .IsBackground = true ;
threads [i] .Name = 测试线程 + i.ToString();
}

for int i = 0 ; i < 30 ; i ++)
{
threads [i] .Start();
}

bool allFinished = false ;

while (!allFinished)
{
allFinished = threads.All(t = > t.ThreadState == System.Threading.ThreadState.Stopped);
Thread.Sleep( 10 );
}

double minMs,maxMs,avgMs,sum;
minMs = double .MaxValue;
maxMs = double .MinValue;
sum = 0 0 ;

foreach (TimeSpan ts 次)
{
if (ts.TotalMilliseconds < minMs)
minMs = ts.TotalMilliseconds;

if (ts.TotalMilliseconds > maxMs)
maxMs = ts.TotalMilliseconds;

sum + = ts.TotalMilliseconds;
}

avgMs = sum /( double )times.Count;

System.Diagnostics.Debug.WriteLine( Max: + maxMs );
System.Diagnostics.Debug.WriteLine( Min: + minMs);
System.Diagnostics.Debug.WriteLine( Avg: + avgMs);
}

public void TestDBConn()
{
秒表sw = 秒表();

sw.Start();

// 在此处运行测试

sw.Stop();

times.Add(sw.Elapsed);
}
}





您可以拨打Fecthresult来自db(名称) 在这里运行你的测试。我会从你的表单中提取这个函数,因为你只关心数据库的负载,UI的更新发生在固定的时间,无论客户端的数量。它将从数据库中取出将要更改。



输出将在输出窗口中。


I have a small windows application where the click on a button will display the list of users in a datagrid starting with a name that is entered in a textbox..

I would like to find out how much it takes if there are 30 users uses this search page simultaneously and find out the time it takes to fetch the results on to datagrid of my windows application..


sample code:

private void btnseacrh_Click(object sender, EventArgs e)
  {
      var name=txttextbox.Text;

     var Resultdataset= Fecthresultfromdb(name);
     
 // retchresultfromdb method calls the database and fetches all the people whose name //starts with 'name' value entered in a textbox
     
    //finally result set is bind to datagrid for display

    datagrid.datasource=Resultdataset;

  }  


Now I would like to know if there are 30 users concurrently using this seacrher window,how much time it takes..This is one of non functional requirement that has to be met within 3 secs.

PLease tell what modifications i need to do..PLease share the modified code snippet as well.

解决方案

What you are asking about is called load testing. Depending on what Visual Studio version you are using, there are built-in tools to help you load test your application. See Visual Studio Load Testing Tools[^]

If you are using some other version that doesn't have those tools, you should look at third party load testing tools for .net[^].

Your other option is to create a unit test application and queue up 30 parallel tasks to hit the database at the same time and use performance counters to measure responses, but this takes a lot more set up than using load testing tools. Some of the ones in the google link may have trial versions that run for some number of days or number of concurrent tests, evaluate each one to find one that meets your needs.

[Edit]

Here is a sample, simple load test you can do:

public class LoadTester
{

    List<TimeSpan> times = new List<TimeSpan>();

    public void Test()
    {
        Thread[] threads = new Thread[30];

        for (int i = 0; i < 30; i++)
        {
            threads[i] = new Thread(new ThreadStart(TestDBConn));
            threads[i].IsBackground = true;
            threads[i].Name = "Test Thread " + i.ToString();
        }

        for (int i = 0; i < 30; i++)
        {
            threads[i].Start();
        }

        bool allFinished = false;

        while (!allFinished)
        {
            allFinished = threads.All(t => t.ThreadState == System.Threading.ThreadState.Stopped);
            Thread.Sleep(10);
        }

        double minMs, maxMs, avgMs, sum;
        minMs = double.MaxValue;
        maxMs = double.MinValue;
        sum = 0.0;

        foreach (TimeSpan ts in times)
        {
            if (ts.TotalMilliseconds < minMs)
                minMs = ts.TotalMilliseconds;

            if (ts.TotalMilliseconds > maxMs)
                maxMs = ts.TotalMilliseconds;

            sum += ts.TotalMilliseconds;
        }

        avgMs = sum / (double)times.Count;

        System.Diagnostics.Debug.WriteLine("Max: " + maxMs);
        System.Diagnostics.Debug.WriteLine("Min: " + minMs);
        System.Diagnostics.Debug.WriteLine("Avg: " + avgMs);
    }

    public void TestDBConn()
    {
        Stopwatch sw = new Stopwatch();

        sw.Start();

        //Run your test here

        sw.Stop();

        times.Add(sw.Elapsed);
    }
}



You would put your call to Fecthresultfromdb(name) where it says "Run your test here". I would pull this function out of your form since you only care about the load on the database, the updating of the UI happens in a fixed time, regardless of the number of clients. Its the fetch from the database that will change.

Output will be in the output window.


这篇关于如何找到30个同时用户的执行时间..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆