python-parallel-programming-cookbook-cn icon indicating copy to clipboard operation
python-parallel-programming-cookbook-cn copied to clipboard

ch2.13 一句话很奇怪不会翻译

Open laixintao opened this issue 8 years ago • 4 comments

We have begun to see a better result in the multithreading case. In particular, we've noted how the threaded execution is half time-consuming if we compare it with the non_threaded one. Let's remember that in real life, we would not use threads as a benchmark. Typically, we would put the threads in a queue, pull them out, and perform other tasks. Having multiple threads that execute the same function although useful in certain cases, is not a common use case for a concurrent program, unless it divides the data in the input.

看不懂加粗加斜的这句话。位置第三次测试的结果解释的地方。

laixintao avatar Sep 30 '17 03:09 laixintao

“other tasks” 指的是thread的具体任务吧? 拙译:“通常的并发场景里,我们先把各个任务线程放进队列排队,然后依次取出队首的线程,执行线程任务。”

全译:“我们开始看到多线程方式的结果更好。特别是相对于非多线程方式来说,多线程方式只耗费了一半左右的时间。所以在实际情况中,我们不会将多线程的耗时作为时间比较基准。通常的并发场景里,我们先把各个任务线程放进队列排队,然后依次取出队首的线程,执行线程任务。少数场景下,我们也可以同时使用多个线程执行同一函数,不过这种方式必须要先将输入数据按照线程进行独立划分后才能进行。”

Roon2300 avatar Nov 15 '17 02:11 Roon2300

@Roon2300 R

Hi,感谢帮忙。不过我觉得不太说的过去。这里测试的是用多线程读文件,结果是多线程表现良好。 http://python-parallel-programmning-cookbook.readthedocs.io/zh_CN/latest/chapter2/13_Evaluating_the_performance_of_multithread_applications.html

然后依次取出队首的线程,执行线程任务。

这样说的话理解起来是顺序执行每一个线程。但是结合上下文,我觉得原文想表达的应该是线程遇到IO的时候就暂停执行,然后去执行其他的线程(perform other tasks),等这里的IO好了再回来执行这个线程。

laixintao avatar Nov 15 '17 02:11 laixintao

@laixintao 我觉得你说的是正确的。百度翻译:pull them out -> tirateli fuori(意呆利语) -> 带他们出去。 意呆利式英文读起来总感觉前言不搭后语的。。。

PS:依次取队首线程执行并不代表是顺序的,比如优先队列就不是。

Roon2300 avatar Nov 15 '17 05:11 Roon2300

@laixintao

进程和线程调度的确是靠队列的。时间片走完之后,计时器向总线发中断,CPU接到之后切到内核态,把队列头部的线程移到队尾,上下文保存好,然后把下一个设为活动的,并取出上下文。

wizardforcel avatar Mar 30 '18 16:03 wizardforcel