Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blosc compressor slower when running in a thread #239

Open
TomAugspurger opened this issue Aug 4, 2020 · 0 comments
Open

Blosc compressor slower when running in a thread #239

TomAugspurger opened this issue Aug 4, 2020 · 0 comments

Comments

@TomAugspurger
Copy link

Minimal, reproducible code sample, a copy-pastable example if possible

This example times an encode / decode cycle on some random bytes. It's slower by a factor of 2x - 3x when run in a thread pool.

import numcodecs
import time
import numpy as np
import concurrent.futures

def encdec():
    times = []
    for i in range(5):
        x = np.random.RandomState(0).random(10_000_0000).tobytes()    
        compressor = numcodecs.Blosc()
        t0 = time.time()
        a = compressor.encode(x)
        t1 = time.time()
        b = compressor.decode(a)
        t2 = time.time()
        times.append((t1 - t0, t2 - t1))

    return times


>>> local = encdec()
>>> tpool = concurrent.futures.ThreadPoolExecutor(max_workers=1)
>>> thread  = tpool.submit(encdec).result()

>>> np.mean(local, 0) / np.mean(thread, 0)
array([0.43173625, 0.34887189])

Problem description

When running in a thread, the Blosc compressor encodes / decodes slower than normal. As discovered in pangeo-data/rechunker#35 (comment), this only affects numcodecs.Blosc. The relative slowdown does not appear when using blosc directly, which makes me think that numcodecs.Blosc may be holding the GIL (hopefully unnecessarily?)

Version and installation information

Please provide the following:

  • Value of numcodecs.__version__: 0.6.4
  • Version of Python interpreter: 3.8.5
  • Operating system (Linux/Windows/Mac): Linux / Mac
  • How NumCodecs was installed (e.g., "using pip into virtual environment", or "using conda"): conda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant