多核CPU压力测试Visual Studio

发布于 2024-08-31 05:21:44 字数 174 浏览 3 评论 0原文

我如何配置 Visual Studio 的测试项目以使用所有 CPU 核心。

当我运行测试时,我可以在性能指示器上看到只有一个核心正在使用(100%),其余 7 个核心未使用。

我在测试项目中有一个调用单一测试的负载测试。

我设置了 200 个用户来调用一个方法。但我需要使用所有核心。

how i can configure the Test Project of visual studio to use all CPU's core.

When i run the test i can see on my performance indicator that only one core is being used (100%) and the rest 7 cores is being unused.

I have inside the Test Project a Load Test that is calling a UNitary Test.

I had set 200 users to call a single method. But i need to use all Cores.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

念三年u 2024-09-07 05:21:44

Dennis,根据 MSDN

“添加 Visual Studio 负载测试虚拟非测试控制器场景中的 User Pack 2010 具有解锁所有计算机处理器以供使用的额外优势如果没有 Visual Studio Load Test Virtual User Pack 2010,您的本地计算机只能使用第一个处理器添加 Visual Studio Load Test Virtual User Pack 2010 后,负载测试在运行时可以使用计算机上的所有处理器。”

因此,如果您没有用户包许可证,则无法解锁额外的核心。

Dennis, according to MSDN:

"Adding a Visual Studio Load Test Virtual User Pack 2010 in a nontest controller scenario has the added benefit of unlocking all machine processors for use. Without a Visual Studio Load Test Virtual User Pack 2010, your local machine can use only the first processor. After you have added a Visual Studio Load Test Virtual User Pack 2010, load tests can use all processors on the machine when they run."

So there's no way to unlock your additional cores if you don't have the user pack license.

半窗疏影 2024-09-07 05:21:44

您的测试代码很可能都是单线程的。单元测试是按顺序运行的,因此除非每个测试中的代码是多线程的,否则它只会在一个线程中运行。

请注意,在多个线程中运行测试可能会产生不良后果,单元测试应该只测试单元,如果是多线程,那么测试应该是单线程的。

The chances are that your test code is all single-threaded. Unit Tests are run sequentially, so unless the code in each test is multi-threaded, it will only run in one thread.

Be carefull that running tests in multiple threads can have adverse consequences, unit tests should only test the unit, and if that is multi-threaded, then the test should be single-threaded.

左耳近心 2024-09-07 05:21:44

您必须在多个线程中完成工作。试试这个:

class Program
{
    static bool isRunning = true;

    static void Main(string[] args)
    {
        BackgroundWorker bw1 = new BackgroundWorker();
        BackgroundWorker bw2 = new BackgroundWorker();

        bw1.DoWork += delegate(object sender, DoWorkEventArgs e)
        { while (isRunning) { } };

        bw2.DoWork += delegate(object sender, DoWorkEventArgs e)
        { while (isRunning) { } };

        bw1.RunWorkerAsync();
        bw2.RunWorkerAsync();

        Console.ReadLine();
        isRunning = false;

    }
}

您可以根据您拥有的核心数量增加后台工作人员的数量(此示例最大化了我的双核计算机)。您可以在运行工作程序后放置代码,然后通过更改 isRunning 的值来停止它们。

You have to do work in multiple threads. Try this:

class Program
{
    static bool isRunning = true;

    static void Main(string[] args)
    {
        BackgroundWorker bw1 = new BackgroundWorker();
        BackgroundWorker bw2 = new BackgroundWorker();

        bw1.DoWork += delegate(object sender, DoWorkEventArgs e)
        { while (isRunning) { } };

        bw2.DoWork += delegate(object sender, DoWorkEventArgs e)
        { while (isRunning) { } };

        bw1.RunWorkerAsync();
        bw2.RunWorkerAsync();

        Console.ReadLine();
        isRunning = false;

    }
}

You can increase the number of background workers depending on how many cores you have (this example maxes out my dual core computer). You can put your code after you run the workers, and then stop them by changing the value of isRunning.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文