为什么一组异步调用比同一组同步调用花费的时间更长?

问题描述 投票:0回答:0
start_time
    try:
        with concurrent.futures.ThreadPoolExecutor() as pool:
            ml_glass_grade = asyncio.get_event_loop().run_in_executor(
                pool, call1)
            is_fraud = asyncio.get_event_loop().run_in_executor(
                pool, cal2)
            lcd_brightness = asyncio.get_event_loop().run_in_executor(
                pool, call3)
            lcd_damage = asyncio.get_event_loop().run_in_executor(
                pool, call4)


        futures = [
            call1
            , call2
            , call3
            , call4
        ]

        await asyncio.gather(*futures)
        end_time

    except:
        ...

    finally:
        time_span = endtime - starttime
    

在负载下,有时time_span大于call1+call2+call3所花费的时间

在负载下,大部分时间或多或少等于time_span。

def call1() -> str:
    make one HTTP post call1

有人可以解释这种罕见的情况吗?

python-3.x performance concurrent-processing
© www.soinside.com 2019 - 2023. All rights reserved.