多线程与多实例 - 选择哪一个? [英] Multithreading vs. Multi-Instancing - Which to choose?

查看:247
本文介绍了多线程与多实例 - 选择哪一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

会不会是有很大的区别这两scenarious:

  1. 在应用程序的一个实例创建100个线程来处理一些工作
  2. 同一应用程序的
  3. 在10个实例创建每个10线程来处理作业(总100)

线程在这两种情况下的数量将是相同的。是它的一些性能或任何类型的一个改进过别人呢。

  

实例 - 例如是控制台应用程序,所以在第二种情况下,   将10控制台应用程序运行。每个应用程序都有它的   自己的文件夹。

解决方案

一个线程使用更少的资源比一个过程所以理论上选项1将是更好。但是,你可能不会注意到两者之间没有太大的区别,因为100个独立的线程的的进程同时所有正在运行的,并争取同O / S资源是pretty的多少保证磨系统停了下来。

我会选择选项3 - 包含一个相当小的线程池的一个过程。这样一来,一些工作将同时​​执行,其余的将排队等待轮到自己。这种方法也可很好,如果大量的就业机会将要运行。

请参见线程池类的或preferably 的,在它上面的很多高层次的抽象之一(如的任务库,甚至是普通的旧异步委托)。

Will it be a big difference between this two scenarious:

  1. one instance of application creates 100 threads to process some jobs
  2. 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?

Instance - is for example console application, so in second case it will be 10 console application running. each of application has it's own folder.

解决方案

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).

这篇关于多线程与多实例 - 选择哪一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆