Why doesn't multithreading in C# reach 100% CPU?

前端 未结 13 1533
眼角桃花
眼角桃花 2021-01-30 22:17

I\'m working on a program that processes many requests, none of them reaching more than 50% of CPU (currently I\'m working on a dual core). So I created a threa

13条回答
  •  误落风尘
    2021-01-30 22:44

    So you solved the problem of using a single COM object and now have an IO problem.

    The increased run time for multiple threads is probably because of mixing random IO together, which will slow it all down.

    If the data set will fit into RAM, try to see if you can prefetch it into cache. Perhaps just reading the data, or maybe memory mapping it together with a command to make it available.

    This is why SQL databases will often choose sequential table scan over an index scan on queries you wouldn't expect: it can be much faster to read all of it in order than to read it in random chunks.

提交回复
热议问题