简体   繁体   English

优化吞吐量:多线程与多进程

[英]Optimizing throughput: multi-thread vs. multi-process

I am working on a processing intensive system which does a lot of computations. 我正在一个处理大量系统的系统上进行大量的计算。 The system have two major components first is to handle input/output, and second is to process that data and compute the results. 该系统有两个主要部分,第一部分是处理输入/输出,第二部分是处理该数据并计算结果。 But the problem is that it is not able to handle 50 items whereas it is supposed to handle more than 1000 items at a time. 但是问题在于它不能处理50个项目,而应该一次处理1000个以上的项目。 Both the components have multiple threads running for different tasks. 这两个组件都有多个线程运行以执行不同任务。 I am on Linux platform and using c++. 我在Linux平台上并使用c ++。 In my understanding, in Linux systems threads and processes are almost similar other than sharing of virtual memory space. 据我了解,在Linux系统中,除了共享虚拟内存空间外,线程和进程几乎相似。 So my question is, is it a good idea to separate I/O from the the processing unit and put them in separate executables or processes and then use shared memory or message queues or any other IPC technique? 所以我的问题是,将I / O与处理单元分开并将它们放在单独的可执行文件或进程中,然后使用共享内存或消息队列或任何其他IPC技术是一个好主意吗?

In your situation, absolutely not. 在您的情况下,绝对不会。 Using different processes is done for security: If one process crashes, the other continues. 为了安全起见,使用了不同的进程:如果一个进程崩溃,则另一个进程继续。 If a hacker manages into one process, you may be able to limit its permissions so that the hacker cannot do anything harmful (bugs in your code can't do anything harmful either in that case). 如果黑客管理一个进程,则您可以限制其权限,这样黑客就不会做任何有害的事情(在这种情况下,代码中的错误也不会做任何有害的事情)。

Use whatever profiling tools you have available. 使用可用的任何概要分析工具。 Today's computers are so fast that most of the time when a task is running too slow, it's down to something stupid that the application does, not due to some missing optimisation. 当今的计算机是如此之快,以至于在大多数情况下,当任务运行太慢时,归因于应用程序的愚蠢行为,而不是由于缺少优化而导致的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM