如何配合 multiprocessing 使用 hashlib 来计算多种摘要?
<ol>
<li>想获取一个大文件(>1GiB)的 md5 、sha1 、sha256 、crc32 、md4 等信息 </li>
<li>只想要文件被完整读取一次 </li>
</ol>
<p>使用 hashlib 获取摘要的时候明显代码瓶颈在单核 cpu 上<br> profile 显示主要都在各个 hashobj 的 update()方法耗时最长 </p>
<p>我看官方文档里有这么一句话:</p>
<pre><code class="language-text">Note For better multithreading performance, the Python GIL is released for data larger than 2047 bytes at object creation or on update.
</code></pre>
<p>然而并没有发现实际起作用 即 GIL 没有被释放 占用率仍然是 100%cpu<br> 验证了不是 io 瓶颈 python3.9.2</p>
收藏(0)
分享
相关标签:
注意:本文归作者所有,未经作者允许,不得转载