billiard.Pool slower than multiprocessing.Pool

Open
#336 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
numpy, pandas, python

Research direction

Start by running the reported benchmark comparing billiard.Pool with multiprocessing.Pool on the pandas and numpy workload shown in the issue. Trace the source of the slowdown and document or fix the discrepancy; done means the comparison is explained or corrected while the resulting data still matches.

Written by the indexing model from the issue text.

Description

import pandas as pd
import time
import numpy as np


def aa(df):
    df_c = df.copy()
    df_c['C'] = df_c['A'] + df_c['B']
    return df_c


def using_multiprocessing(df, func, n_cores=4):
    from multiprocessing import Pool
    df_split = np.array_split(df, n_cores)

    pool = Pool(n_cores)
    start_time = time.time()
    df = pd.concat(pool.map(func, df_split))
    pool.close()
    pool.join()
    print(f"Using multiprocessing {time.time() - start_time}")
    return df


def using_billiard(df, func, n_cores=4):
    import billiard
    df_split = np.array_split(df, n_cores)

    pool = billiard.Pool(n_cores)
    start_time = time.time()
    df = pd.concat(pool.map(func, df_split))
    pool.close()
    pool.join()
    print(f"Using billiard {time.time() - start_time}")
    return df


inp = pd.DataFrame(np.random.randint(0,1000000,size=(1000000, 2)), columns=list('AB'))

df_1 = using_multiprocessing(inp, aa, 5)
df_2 = using_billiard(inp, aa, 5)

print(df_1.equals(df_2))

I got output:

Using multiprocessing 0.2115309238433838
Using billiard 31.323524951934814
True
Dominant language
Python
Stars
436
Forks
273
Avg merge
4d 19h
Merged PRs (30d)
5

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from celery/billiard

All issues in celery/billiard

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.