Last post Apr 06, 2017 07:50 AM by PatriceSc
Apr 04, 2017 02:07 AM|Test888|LINK
I want to know, during the developing for a web site. in which situation, we could use single thread and multiple thread to resolve our questions. Would someone could give me a example.
Thank you for anyone to share the developing experience.
Apr 04, 2017 03:04 AM|Cathy Zou|LINK
1.If you have only 1 cpu, and the tasks have no blocking I/O, then the single threaded will finish equal to or faster than multi-threaded, as there is overhead to switching threads.
2.If you have 1 cpu, but the tasks involve a lot of blocking I/O, you might see a speedup by using threading, assuming work can be done when I/O is in progress.
3.If you have multiple cpus, then you should see a speedup with the multi-threaded implementation over the single threaded, since more than 1 thread can execute in parallel. Unless of course the tasks are I/O dominated, in which case the limiting factor
is your device speed, not cpu power.
4.Threads can add substantial performance improvements even on single processor systems. Thus, if you are performing a particularly complex or detailed simulation, using multiple threads is recommended.
5.If you have only one core, then the only way that multi-threading can help you is if chunks of that work depends on something other than CPU, so one thread can get some work done while another is waiting for data from a disk or network connection.
For more information. Please refer to the following links:
Apr 04, 2017 10:25 AM|Test888|LINK
Thanks Cathy Zou,
thank you for your further explain for single thread and multiple thread. But i want to know during your developing which situation we could use them.
such as a faceboook site or amazon site or others, which place we need to use thread and multiple thread. this is a question when I am being asked by interviewer. Thank you for any others.
Apr 06, 2017 07:21 AM|Test888|LINK
Does someone could share a example?
Apr 06, 2017 07:50 AM|PatriceSc|LINK
You could try
https://msdn.microsoft.com/en-us/library/dd460717(v=vs.110).aspx (ie use a library to ease that, for example you could use a parallel loop on an array to compute something).
Whenever I see this kind of question I wonder if they don't want rather to see if you'll just plunge directly into that or if you can step back a bit when needed. My main point would be that being able to break down a single problem with a minimal amount
of data sharing should be quite rare for most web apps. I would suggest to look first at async APIs and async/await as most web apps are likely waiting for IOs and scalability matter likely much than individual user performance.
Maybe they just wanted to see that you do know that before investing time into that, you should really double check that your problem is really suitable for this approach ?