Multithreading in .NET 4.0 and Performance

I played with the Parallel library in .NET 4.0. I recently developed the usual ORM for some unusual read / write operations that one of our large systems should use. This allows me to decorate an object with attributes and analyze which columns it should retrieve from the database, as well as what XML should output to the records.

Since I assume that this wrapper will be reused in many projects, I would like to get the maximum speed out of it as soon as possible. This library will be mainly used in .NET web applications. I am testing the framework using a one-time console application to poke into the classes that I created.

Now I have learned the lesson of the costs that multithreading faces. Multithreading makes it work slower. From reading around it seems that it is intuitive to people who have been doing this for a long time, but it is actually intuitive to me: how can I use the method 30 times at the same time more slowly than running it 30 times in a row?

I don’t think that I am causing problems with several threads that must fight for the same common object (although I am not good enough at that to say for sure or not), so I assume that the slowdown is approaching the overhead from spawning all of these threads and runtime, keeping them all straight. So:

  • Although I mainly do this as a training exercise, is it pessimization? For trivial tasks other than IO, is a multithreaded excess number? My main goal is speed, not user interface responsiveness or anything else.
  • IIS, - , , , , , ? , , , , , . , - , , , , .
+3
3

.

, (, ). , 2/4.

30 , 30 , . , , , .

1 , . , , - , . , , , , .

.net 4.0 , . , , , , /, , 30 , TP 2 . , , . - ThreadPool.QueueUserWorkItem(...) , , .

, , .net( 4.0).net , , . . , Thread.

[ - . hyperthreading - , , 4-8 ]

+8

, , , . " Windows" "Java Concurrency in Practice". , . , , - , , , .

, , . , .

, , , , , .

Parallel.For Parallel.ForEach, :

http://rocksolidknowledge.com/ScreenCasts.mvc/Watch?video=ParallelLoops.wmv

+2

ORM, , - . , .

, -: ( , ), , , . , 30 , , , , -, . , - , , , , , .

; , , .

" " , , . (, ), , . , , , parallelism; , : , , , .

+1

Source: https://habr.com/ru/post/1728185/


All Articles