2

私は現在、いくつかのページが大量のデータをロードする ASP.NET MVC アプリケーションに取り組んでいます (別の LINQ クエリで再分割されています)。

これらのページのパフォーマンスを向上させるために、C# 4 タスクを使用してクエリを同時に作成し、実行時間を短縮できるようにすることを想定しています。

しかし、私は 1 つの大きな質問があります: サーバー側から、どの状況が最適か:

  • タスクなどを使用するページで、短時間に大量のサーバー リソースを使用することはありませんか?
  • 同期コードのみを使用し、サーバー リソースは少ないが、より多くの時間を使用するページですか?
  • 無発生?

ページのパフォーマンスも重要ですが、サーバーの安定性はもっと重要です。よろしくお願いします。

4

1 に答える 1

2

You don't say whether the LINQ queries are CPU bound (e.g. computed in-memory) or IO bound (e.g. reading across the network or from disk).

If they are CPU bound, then using asynchronous code will improve fairness, but reduce throughput - but only so everyone suffers. For example, say you could only process one request at a time, and each request takes 5 seconds. Two requests come in almost at the same time. With synchronous code, the first will complete in 5 seconds while the second is queued, and the second will complete after 10. With asychronous code, both will start together and finish after slightly more than 10 seconds (due to overhead of swapping between the two). This is hypothetical, because you have many threads to process requests concurrently.

In reality, you'll find asynchronous code will only help when you have lots of IO bound operations that take long enough to cause request queuing. If the queue fills up, the server will start issuing Server Unavailable 503 errors. Check your performance counters - if you have little or no requests queued in ASP.NET under typical live loads then don't bother with the additional complexity.

If the work is IO bound, then using asynchronous code will push the bottleneck towards the network/disk. This is a good thing, because you aren't wasting your web server's memory resource on idle blocked request threads just waiting for responses - instead you make request throughput dependent on downstream performance and can focus on optimizing that. i.e. You'll keep those request threads free to take more work from the queue.

EDIT - Nice article on this here: http://blog.stevensanderson.com/2010/01/25/measuring-the-performance-of-asynchronous-controllers/

于 2012-06-15T13:27:15.933 に答える