久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='0uQCr'><style id='0uQCr'><dir id='0uQCr'><q id='0uQCr'></q></dir></style></legend>

  1. <i id='0uQCr'><tr id='0uQCr'><dt id='0uQCr'><q id='0uQCr'><span id='0uQCr'><b id='0uQCr'><form id='0uQCr'><ins id='0uQCr'></ins><ul id='0uQCr'></ul><sub id='0uQCr'></sub></form><legend id='0uQCr'></legend><bdo id='0uQCr'><pre id='0uQCr'><center id='0uQCr'></center></pre></bdo></b><th id='0uQCr'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='0uQCr'><tfoot id='0uQCr'></tfoot><dl id='0uQCr'><fieldset id='0uQCr'></fieldset></dl></div>

    • <bdo id='0uQCr'></bdo><ul id='0uQCr'></ul>

      <small id='0uQCr'></small><noframes id='0uQCr'>

      <tfoot id='0uQCr'></tfoot>

      來自 concurrent.futures 的 ProcessPoolExecutor 比 multipr

      ProcessPoolExecutor from concurrent.futures way slower than multiprocessing.Pool(來自 concurrent.futures 的 ProcessPoolExecutor 比 multiprocessing.Pool 慢)
      <tfoot id='XqOqj'></tfoot>
      <legend id='XqOqj'><style id='XqOqj'><dir id='XqOqj'><q id='XqOqj'></q></dir></style></legend>

      <small id='XqOqj'></small><noframes id='XqOqj'>

          <bdo id='XqOqj'></bdo><ul id='XqOqj'></ul>

          <i id='XqOqj'><tr id='XqOqj'><dt id='XqOqj'><q id='XqOqj'><span id='XqOqj'><b id='XqOqj'><form id='XqOqj'><ins id='XqOqj'></ins><ul id='XqOqj'></ul><sub id='XqOqj'></sub></form><legend id='XqOqj'></legend><bdo id='XqOqj'><pre id='XqOqj'><center id='XqOqj'></center></pre></bdo></b><th id='XqOqj'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='XqOqj'><tfoot id='XqOqj'></tfoot><dl id='XqOqj'><fieldset id='XqOqj'></fieldset></dl></div>

              <tbody id='XqOqj'></tbody>

                本文介紹了來自 concurrent.futures 的 ProcessPoolExecutor 比 multiprocessing.Pool 慢的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                我正在試驗 Python 3.2 中引入的新的閃亮 concurrent.futures 模塊,并且我注意到,幾乎使用相同的代碼,使用 concurrent.futures 中的 Pool 比使用 方式.html#multiprocessing.pool.Pool">multiprocessing.Pool.

                I was experimenting with the new shiny concurrent.futures module introduced in Python 3.2, and I've noticed that, almost with identical code, using the Pool from concurrent.futures is way slower than using multiprocessing.Pool.

                這是使用多處理的版本:

                This is the version using multiprocessing:

                def hard_work(n):
                    # Real hard work here
                    pass
                
                if __name__ == '__main__':
                    from multiprocessing import Pool, cpu_count
                
                    try:
                        workers = cpu_count()
                    except NotImplementedError:
                        workers = 1
                    pool = Pool(processes=workers)
                    result = pool.map(hard_work, range(100, 1000000))
                

                這是使用concurrent.futures:

                And this is using concurrent.futures:

                def hard_work(n):
                    # Real hard work here
                    pass
                
                if __name__ == '__main__':
                    from concurrent.futures import ProcessPoolExecutor, wait
                    from multiprocessing import cpu_count
                    try:
                        workers = cpu_count()
                    except NotImplementedError:
                        workers = 1
                    pool = ProcessPoolExecutor(max_workers=workers)
                    result = pool.map(hard_work, range(100, 1000000))
                

                使用從 Eli Bendersky 文章,這些是我電腦上的結果(i7、64 位、Arch Linux):

                Using a na?ve factorization function taken from this Eli Bendersky article, these are the results on my computer (i7, 64-bit, Arch Linux):

                [juanlu@nebulae]─[~/Development/Python/test]
                └[10:31:10] $ time python pool_multiprocessing.py 
                
                real    0m10.330s
                user    1m13.430s
                sys 0m0.260s
                [juanlu@nebulae]─[~/Development/Python/test]
                └[10:31:29] $ time python pool_futures.py 
                
                real    4m3.939s
                user    6m33.297s
                sys 0m54.853s
                

                我無法使用 Python 分析器分析這些,因為我遇到了 pickle 錯誤.有什么想法嗎?

                I cannot profile these with the Python profiler because I get pickle errors. Any ideas?

                推薦答案

                當使用 concurrent.futures 中的 map 時,每個元素都來自可迭代的 單獨提交給執行器,執行器創建一個Future 對象每次通話.然后它返回一個迭代器,該迭代器產生期貨返回的結果.
                未來 對象是相當重量級的,它們做了很多工作來允許它們提供的所有功能(如回調、取消能力、檢查狀態......).

                When using map from concurrent.futures, each element from the iterable is submitted separately to the executor, which creates a Future object for each call. It then returns an iterator which yields the results returned by the futures.
                Future objects are rather heavyweight, they do a lot of work to allow all the features they provide (like callbacks, ability to cancel, check status, ...).

                與此相比,multiprocessing.Pool 的開銷要少得多.批量提交作業(減少IPC開銷),直接使用函數返回的結果.對于大批量的工作,多處理絕對是更好的選擇.

                Compared to that, multiprocessing.Pool has much less overhead. It submits jobs in batches (reducing IPC overhead), and directly uses the result returned by the function. For big batches of jobs, multiprocessing is definitely the better options.

                Future 非常棒,如果您想匯總開銷不那么重要的長時間運行的作業,您希望通過回調收到通知或不時檢查它們是否已完成或能夠取消單獨執行.

                Futures are great if you want to sumbit long running jobs where the overhead isn't that important, where you want to be notified by callback or check from time to time to see if they're done or be able to cancel the execution individually.

                個人筆記:

                我真的想不出太多使用 Executor.map 的理由——它沒有給你任何期貨的特性——除了指定超時的能力.如果您只對結果感興趣,最好使用 multiprocessing.Pool 的映射函數之一.

                I can't really think of much reasons to use Executor.map - it doesn't give you any of the features of futures - except for the ability to specify a timeout. If you're just interested in the results, you're better off using one of multiprocessing.Pool's map functions.

                這篇關于來自 concurrent.futures 的 ProcessPoolExecutor 比 multiprocessing.Pool 慢的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                What exactly is Python multiprocessing Module#39;s .join() Method Doing?(Python 多處理模塊的 .join() 方法到底在做什么?)
                Passing multiple parameters to pool.map() function in Python(在 Python 中將多個參數傳遞給 pool.map() 函數)
                multiprocessing.pool.MaybeEncodingError: #39;TypeError(quot;cannot serialize #39;_io.BufferedReader#39; objectquot;,)#39;(multiprocessing.pool.MaybeEncodingError: TypeError(cannot serialize _io.BufferedReader object,)) - IT屋-程序員軟件開
                Python Multiprocess Pool. How to exit the script when one of the worker process determines no more work needs to be done?(Python 多進程池.當其中一個工作進程確定不再需要完成工作時,如何退出腳本?) - IT屋-程序員
                How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊列引用傳遞給 pool.map_async() 管理的函數?)
                yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(與多處理錯誤的另一個混淆,“模塊對象沒有屬性“f)
                • <tfoot id='c8Bg5'></tfoot>
                    <bdo id='c8Bg5'></bdo><ul id='c8Bg5'></ul>
                      <tbody id='c8Bg5'></tbody>

                      <legend id='c8Bg5'><style id='c8Bg5'><dir id='c8Bg5'><q id='c8Bg5'></q></dir></style></legend>
                    • <small id='c8Bg5'></small><noframes id='c8Bg5'>

                        1. <i id='c8Bg5'><tr id='c8Bg5'><dt id='c8Bg5'><q id='c8Bg5'><span id='c8Bg5'><b id='c8Bg5'><form id='c8Bg5'><ins id='c8Bg5'></ins><ul id='c8Bg5'></ul><sub id='c8Bg5'></sub></form><legend id='c8Bg5'></legend><bdo id='c8Bg5'><pre id='c8Bg5'><center id='c8Bg5'></center></pre></bdo></b><th id='c8Bg5'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='c8Bg5'><tfoot id='c8Bg5'></tfoot><dl id='c8Bg5'><fieldset id='c8Bg5'></fieldset></dl></div>
                          主站蜘蛛池模板: 国产精品久久久久久久一区探花 | 91色站| 国产在线观看一区二区 | 综合久久久久 | 性一交一乱一伦视频免费观看 | www视频在线观看 | 手机看黄av免费网址 | 成人国产一区二区三区精品麻豆 | 久久一区二区免费视频 | 日韩在线一区二区三区 | 91就要激情| 一区二区三区视频在线观看 | 久久久久久国产精品免费免费男同 | 欧美一区视频 | 在线伊人 | 日韩有码一区 | 天天射影院 | 91精品麻豆日日躁夜夜躁 | 婷婷91| 国产一区视频在线 | 久久一区二区三区四区五区 | 亚洲不卡一 | 欧美精品久久久久 | 青青草av在线播放 | 中文字幕在线一区二区三区 | 色婷婷av久久久久久久 | 国产精品视频一二三区 | 欧美日韩在线看 | 三级在线免费 | 欧美国产免费 | 6996成人影院网在线播放 | 狠狠综合久久av一区二区老牛 | 欧美精品一区二区在线观看 | 天堂一区二区三区 | 国产精品高| 国产精品二区三区在线观看 | 国产一二三区在线 | 美女视频h | 九九久久国产 | 日韩三级免费观看 | 日韩精品一区二区三区高清免费 |