问题描述
会不会是有很大的区别这两scenarious:
- 在应用程序的一个实例创建100个线程来处理一些工作 同一应用程序的
- 在10个实例创建每个10线程来处理作业(总100)
线程在这两种情况下的数量将是相同的。是它的一些性能或任何类型的一个改进过别人呢。
一个线程使用更少的资源比一个过程所以理论上选项1将是更好。但是,你可能不会注意到两者之间没有太大的区别,因为100个独立的线程的或的进程同时所有正在运行的,并争取同O / S资源是pretty的多少保证磨系统停了下来。
我会选择选项3 - 包含一个相当小的线程池的一个过程。这样一来,一些工作将同时执行,其余的将排队等待轮到自己。这种方法也可很好,如果大量的就业机会将要运行。
请参见线程池类的或preferably 的,在它上面的很多高层次的抽象之一(如的,甚至是普通的旧异步委托)。
Will it be a big difference between this two scenarious:
- one instance of application creates 100 threads to process some jobs
- 10 instances of the same application creates 10 threads each to process jobs (total 100)
The number of threads in both cases will be the same. Is it some performance or any type of improvements of one over another?
A thread uses less resources than a process so theoretically option 1 would be "better". However, you probably won't notice much difference between the two, because 100 separate threads or processes all running simultaneously and fighting for the same O/S resources is pretty much guaranteed to grind your system to a halt.
I would choose option 3 - one process containing a fairly small thread pool. That way, some jobs will execute simultaneously and the rest will queue up and wait their turn. This approach also scales well if a very large number of jobs are going to be run.
See the ThreadPool class, or preferably, one of the many higher-level abstractions on top of it (e.g. the task library, or even plain old asynchronous delegates).
这篇关于多线程与多实例 - 选择哪一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!