2
我發現,當我使用Python的concurrent.futures.ThreadPoolExecutor
vms內存使用(由psutil報告)顯着增加。爲什麼concurrent.futures增加虛擬內存?
In [1]: import psutil
In [2]: psutil.Process().memory_info().vms/1e6
Out[2]: 360.636416
In [3]: from concurrent.futures import ThreadPoolExecutor
In [4]: e = ThreadPoolExecutor(20)
In [5]: psutil.Process().memory_info().vms/1e6
Out[5]: 363.15136
In [6]: futures = e.map(lambda x: x + 1, range(100))
In [7]: psutil.Process().memory_info().vms/1e6
Out[7]: 1873.580032
In [8]: e.shutdown()
In [9]: psutil.Process().memory_info().vms/1e6
Out[9]: 1722.51136
這似乎與線程數有些成正比。
請注意,其他內存屬性(如rss)會返回更適度的值 – MRocklin