简体   繁体   中英

Force 100% CPU usage on server

I have a C# ASP.NET app that runs some lengthy simulations and does so in parallel. Something like this...

    static void Main(string[] args)
    {
        var myArray = new[] {450, 586, 879, 457, 657, 852, 407, ... };

        myArray.AsParallel().ForAll(DoStuff);
    }

    static void DoStuff(int number)
    {
        //do stuff
    }

When running locally, and on most of my servers (Amazon EC2 instances), executing this code utilizes 100% of the CPU. This is what I want. I need these large calculations to be completed as quickly as possible

1 of my servers is a C3.8XLARGE
Intel Xeon E5-2680 v2 (Ivy Bridge) Processor
vCPU: 32
mem (GiB): 60

On this server, CPU utilization never goes above 60% and runs very slowly.

What could be causing this to happen on only this server? How can I troubleshoot?

Probably the issue is in the "ForAll" method and how it scales.

To have 100% CPU you should have 1 thread per core doing something very heavy.

The TPL internally creates tasks and has a default TaskScheduler class to handle the requests and delegate it to a thread pool. Maybe there are some lags there.

I'd create a different approach creating the threads or tasks manually (1 per core). If you still don't get 100% CPU, I think server fault is a good idea. Probably something related to physical/virtual machine or some throttling in the server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM