c# - Threading issues with > 30 threads. CPU scales non-linearly -
i having trouble c# application.
i made sure threads not access resources outside themselves.
now have threadpool thread makes tcp connection, creates thread objects , runs, 1 thread performance great. 50 threads seems same, maybe 5-10% slower, cpu 10-20%. 100 threads, cpu usage goes 10-20% 70-99%.
one of our developers said windows threads suck compared linux thread , context switching incurring huge penalties. proposes create multiplexing 4-8 core threads running instances.
but thought problems start happening once have 1000+ threads. can comment sources read more topic, , thread / cpu performance , correct practices?
edit: ok many answers seem little off point because assumptions being made add points:
running 3 applications 50 threads @ 10-20% cpu usage makes them use much. 30-60% cpu usage total. running 1 application 150 threads makes cap cpu @ 70-99%. this mean threads not scaling.
to expand on comment..
it's not windows threads "suck" in comparison posix threads it's you're trying more things cpu can physically handle @ time. cpu usage not particularly relevant performance indicator should looking @ here.
if cpu has 4 cores, optimum amount of constantly-running threads 4. more , performance degradation going happen yes, context switching have performance impact tries process through threads simultaneously 1 resource.
think of threads giant stacks of books on table, you've got knock each individual book off top of each stack , want them doing fast can. you've got 4 of these book stacks (threads) 2 arms (cores), how do it? option alternate stack knock books off each time, there's no real performance benefit time taken single stack going take long other.
the time when differ if you're running blocking (ie. waiting i/o) operation , threads idle. in idle time cores free work on thread can give perceived performance benefit. of course, when resource other thread waiting becomes available you're in same situation in currently.
Comments
Post a Comment