This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author fgregg
Recipients fgregg, ned.deily, ronaldoussoren
Date 2020-01-16.14:56:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1579186602.99.0.0759376415978.issue39362@roundup.psfhosted.org>
In-reply-to
Content
In the multiprocessing Pool methods like map, chunksize determines the trade-off between computation per task and inter-process communication. Setting chunksize appropriately has a large effect on efficiency.


However, for users directly interacting with the map methods, the way to find the appropriate chunksize is by manually checking different sizes and observing the program behavior.

For library developers, you have to hope that you set an reasonable value that will work okay across different hardware, operating systems, and task characteristics.

Generally, users of these methods want maximum throughput. It would be great if the map-like methods could adapt their chunksize towards that goal.

Something along the lines of this:

    n_items = 0
    queue = Queue(N)
    while True:
        chunk = tuple(itertools.islice(iterable, chunk_size))
        if chunk:
            queue.put(chunk)

            n_items += chunk_size
            i += 1

            if i % 10:
                time_delta = max(time.perf_counter() - t0, 0.0001)

                current_rate = n_items / time_delta

                # chunk_size is always either growing or shrinking, if
                # the shrinking led to a faster rate, keep
                # shrinking. Same with growing. If the rate decreased,
                # reverse directions
                if current_rate < last_rate:
                    multiplier = 1 / multiplier

                chunk_size = int(min(max(chunk_size * multiplier, 1), upper_bound))

                last_rate = current_rate
                n_items = 0
                t0 = time.perf_counter()


Would such a feature be desirable?
History
Date User Action Args
2020-01-16 14:56:43fgreggsetrecipients: + fgregg, ronaldoussoren, ned.deily
2020-01-16 14:56:42fgreggsetmessageid: <1579186602.99.0.0759376415978.issue39362@roundup.psfhosted.org>
2020-01-16 14:56:42fgregglinkissue39362 messages
2020-01-16 14:56:42fgreggcreate