回答編集履歴
7
補足
test
CHANGED
@@ -106,8 +106,6 @@
|
|
106
106
|
|
107
107
|
[ProcessPoolExecutor](https://docs.python.jp/3/library/concurrent.futures.html#processpoolexecutor)と[ThreadPoolExecutor](https://docs.python.jp/3/library/concurrent.futures.html#threadpoolexecutor)違い
|
108
108
|
|
109
|
-
リンク先に全部書いてありますが。
|
110
|
-
|
111
109
|
|
112
110
|
|
113
111
|
|Executor名|並列対象|オーバーラップ対象|GILの制限|データの受け渡し|
|
6
追記
test
CHANGED
@@ -92,6 +92,14 @@
|
|
92
92
|
|
93
93
|
---
|
94
94
|
|
95
|
+
一番重要な、質問文のメモリ問題は解決したのでしょうか?
|
96
|
+
|
97
|
+
その点気になってますが。。。
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
以下はコメント欄への質問への回答。
|
102
|
+
|
95
103
|
できるだけ調べたことを書いてくださいな。どのような内容を調べて、どこの記述がわからないのか。丸投げではなく、そういう形の質問にしてくださいな。
|
96
104
|
|
97
105
|
|
5
補足
test
CHANGED
@@ -102,13 +102,13 @@
|
|
102
102
|
|
103
103
|
|
104
104
|
|
105
|
-
|Executor名|並列対象|オーバーラップ対象|GIL制限
|
105
|
+
|Executor名|並列対象|オーバーラップ対象|GILの制限|データの受け渡し|
|
106
106
|
|
107
107
|
|:--|:--:|--:|
|
108
108
|
|
109
|
-
|ProcessPoolExecutor|プロセス|CPUの計算|影響を受けない|pickle可能なオブジェクト|
|
109
|
+
|ProcessPoolExecutor|プロセス|マルチプロセスなため、CPUの計算|影響を受けない|pickle可能なオブジェクト|
|
110
110
|
|
111
|
-
|ThreadPoolExecutor|スレッド|IO処理(ネットワークやDisk)|影響を受ける|制約なし|
|
111
|
+
|ThreadPoolExecutor|スレッド|IOがボトルネックな処理(ネットワークやDisk)|影響を受ける|制約なし|
|
112
112
|
|
113
113
|
|
114
114
|
|
4
追記
test
CHANGED
@@ -87,3 +87,29 @@
|
|
87
87
|
|
88
88
|
|
89
89
|
このプログラムは最大で992*20MBの19,840MB(大凡19.8GB)のメモリを使用します。
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
---
|
94
|
+
|
95
|
+
できるだけ調べたことを書いてくださいな。どのような内容を調べて、どこの記述がわからないのか。丸投げではなく、そういう形の質問にしてくださいな。
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
[ProcessPoolExecutor](https://docs.python.jp/3/library/concurrent.futures.html#processpoolexecutor)と[ThreadPoolExecutor](https://docs.python.jp/3/library/concurrent.futures.html#threadpoolexecutor)違い
|
100
|
+
|
101
|
+
リンク先に全部書いてありますが。
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|Executor名|並列対象|オーバーラップ対象|GIL制限事項|データの受け渡し|
|
106
|
+
|
107
|
+
|:--|:--:|--:|
|
108
|
+
|
109
|
+
|ProcessPoolExecutor|プロセス|CPUの計算|影響を受けない|pickle可能なオブジェクト|
|
110
|
+
|
111
|
+
|ThreadPoolExecutor|スレッド|IO処理(ネットワークやDisk)|影響を受ける|制約なし|
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
GILは[GlobalInterpreterLock](https://wiki.python.org/moin/GlobalInterpreterLock)といいます。
|
3
補足
test
CHANGED
@@ -44,8 +44,46 @@
|
|
44
44
|
|
45
45
|
|
46
46
|
|
47
|
-
CPythonの[ProcessPoolExecutor](https://github.com/python/cpython/blob/8e149ff481acbb3889c825b8bf7b10aa191f09a7/Lib/concurrent/futures/process.py#L379)の
|
47
|
+
Githubにある、CPythonの[ProcessPoolExecutor](https://github.com/python/cpython/blob/8e149ff481acbb3889c825b8bf7b10aa191f09a7/Lib/concurrent/futures/process.py#L379)の__init__部分より引用。
|
48
48
|
|
49
49
|
|
50
50
|
|
51
|
+
```Python
|
52
|
+
|
53
|
+
if max_workers is None:
|
54
|
+
|
55
|
+
self._max_workers = os.cpu_count() or 1
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
■参考情報
|
62
|
+
|
51
|
-
[os.cpu_count()](https://docs.python.jp/3/library/os.html#os.cpu_count)
|
63
|
+
[os.cpu_count()](https://docs.python.jp/3/library/os.html#os.cpu_count)
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
■余談
|
68
|
+
|
69
|
+
1,プロファイルを取ってみたほうがいいと思いますが。
|
70
|
+
|
71
|
+
URLからダウンロードしている部分 with gzip.open(url,"rt") はThreadPoolExecutorでI/O をオーバーラップしたほうが良いかもしれません。
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
2,max_workers = 992に関して
|
76
|
+
|
77
|
+
この設定値はどこかのサイトのサンプルソースの設定値なのでしょうか?
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
最大ワーカープロセス数=992なため
|
82
|
+
|
83
|
+
a,プロセス数の生成が最大で992個行われる
|
84
|
+
|
85
|
+
b,1プロセスあたり20MBメモリを消費
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
このプログラムは最大で992*20MBの19,840MB(大凡19.8GB)のメモリを使用します。
|
2
追記
test
CHANGED
@@ -33,3 +33,19 @@
|
|
33
33
|
with concurrent.futures.ProcessPoolExecutor() as executor:
|
34
34
|
|
35
35
|
```
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
---
|
40
|
+
|
41
|
+
> maxworker 指定なしで大丈夫でした。
|
42
|
+
|
43
|
+
指定がない場合はプロセス数はどのように処理されているのでしょうか?
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
CPythonの[ProcessPoolExecutor](https://github.com/python/cpython/blob/8e149ff481acbb3889c825b8bf7b10aa191f09a7/Lib/concurrent/futures/process.py#L379)のpythonソースコード。
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
[os.cpu_count()](https://docs.python.jp/3/library/os.html#os.cpu_count) or 1
|
1
追記
test
CHANGED
@@ -7,3 +7,29 @@
|
|
7
7
|
|
8
8
|
|
9
9
|
あと例外メッセージが発生してるなら、質問文に追記していただくと回答時に参考情報になります。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
---
|
14
|
+
|
15
|
+
追記
|
16
|
+
|
17
|
+
以下のように変更してくださいな。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
```Python
|
22
|
+
|
23
|
+
with concurrent.futures.ProcessPoolExecutor(max_workers = 992) as executor:
|
24
|
+
|
25
|
+
```
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
↓
|
30
|
+
|
31
|
+
```Python
|
32
|
+
|
33
|
+
with concurrent.futures.ProcessPoolExecutor() as executor:
|
34
|
+
|
35
|
+
```
|