3
私はPythonに新しく、スレッドとGILを学習しています。 これらはlscpu
コマンドの統計です:Pythonスレッディングパフォーマンスとコア数
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 2
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 69
Stepping: 1
CPU MHz: 1700.062
BogoMIPS: 4789.05
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 3072K
NUMA node0 CPU(s): 0-3
私は例をスレッドこの単純なパイソンを走った、私は次の出力を取得します。
import time
import threading
def counter(n):
for i in range(0,n):
i = i+1
return
t1 = threading.Thread(target=counter, args = (10000000,))
t2 = threading.Thread(target=counter, args = (10000000,))
t0 = time.clock()
t1.start()
t2.start()
t1.join()
t2.join()
t3 = time.clock()
print "Total time : %s"%str(t3-t0)
[email protected]:~/Desktop$ python threads.py
Total time : 2.115326
しかし、私は3つのコアと再実行コード無効にする場合:
[email protected]:~/Desktop$ python threads.py
Total time : 1.115442
をこれらの数字は、多かれ少なかれ同じまま。なぜこれはそうですか?誰かが説明する。事前に感謝します...
動的周波数スケーリング(TurboBoostなど)のようなことを覚えておいてください。 – renemilk
'マルチプロセッシングはスレッドを利用しません。全く同じではない生成プロセス[sic]をサポートするパッケージです。 –
返信いただきありがとうございますが、no.ofアクティブコアがさらに多い場合、なぜ速度が低下するのかを知りたいのですが –