Search code examples
execution-timeconcurrent.futures

ProcessPoolExecutor takes more time on windows than on mac


from concurrent.futures import ProcessPoolExecutor
import time

class Foo():
    def __init__(self, name):
        self.name = name
        self.start = time.time()

    def log(self):
        for i in range(1000):
            time.sleep(0.001)
        print(f"{self.name} - Processing time: {(time.time() - self.start)}")

class Bar():
    def __init__(self, name):
        self.name = name
        self.start = time.time()

    def log(self):
        for i in range(1000):
            time.sleep(0.001)
        print(f"{self.name} - Processing time: {(time.time() - self.start)}")

class FooBar():
    def __init__(self, name):
        self.name = name
        self.start = time.time()

    def log(self):
        for i in range(1000):
            time.sleep(0.001)
        print(f"{self.name} - Processing time: {(time.time() - self.start)}")

def main():

    c1 = Foo("1")
    c2 = Foo("2")
    c3 = Bar("3")
    c4 = Bar("4")
    c5 = FooBar("5")
    c6 = FooBar("6")

    with ProcessPoolExecutor(max_workers=12) as executor:
        executor.submit(c1.log)
        executor.submit(c2.log)
        executor.submit(c3.log)
        executor.submit(c4.log)
        executor.submit(c5.log)
        executor.submit(c6.log)

if __name__ == "__main__":

    main()

Mac finishes each log call in ~1.18 s, windows takes ~15.71 s for each call. Mac has a 6 core 2.6 GHz proc and Windows has a 6 core 2.4 GHz proc.

Why is windows execution of the same program almost 15 times slower?


Solution

  • The issue is not related to concurrency but rather to sleep resolution set by each operating system. Windows had smallest time delay 15ms which attributed to longer wait times. In order to get similar performance time resolution needs to be lowered.

    An answer on how to do that can be found here: https://stackoverflow.com/a/43505033/4431136