• Stars
    star
    127
  • Rank 282,790 (Top 6 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ring buffer that allows for high-throughput data transfer between multiproccessing Python processes.

A multiple writer and reader ring buffer that allows for high-throughput data transfer between multiproccessing Python processes. The goal is to make it easy to construct bandwidth-heavy pipelines (e.g., for video stream processing) that can utilize multiple cores with Python tools like OpenCV, Scikit Learn, and TensorFlow.

The RingBuffer data structure's performance is primarily bound by the behavior of the Lock class, which is a Kernel semaphore under the covers. The lock is used to coordinate a readers/writer lock, meaning that lock contention dominates as the number of writes per second increases. Memory performance isn't an issue because all data is transferred through mmap'ed buffers.

For examples of how it all fits together, look at example_numpy.py and example_ctypes.py.

On an old MacBook, the ring buffer can easily do 2 gigabytes per second of transfer when using large slot sizes (~100MB), a relatively low number of writes per second (~24), and a single reader/writer pair. As you increase the number of writes per second the performance degrades proportionately due to the lock. However, increasing the number of readers has a minimal effect (when the slot sizes are ~10MB) because multiple readers can hold the read lock at the same time.

Build Status

Works with Python 3.5 and later. Background on why it doesn't work with Python 3.3 and 3.4 is here.


Included is a tool called perf_test_ringbuffer.py that tests the performance characteristics of the ring buffer. This can be used to exercise the various ways in which the RingBuffer scales, including number of readers, number of writes per second, slow readers, etc.

Example that shows good behavior:

./perf_test_ringbuffer.py \
    --debug \
    --slot-bytes=1000000 \
    --slots=50 \
    --duration-seconds=10 \
    --writes-per-second=24 \
    --readers=5

Example that shows that too many readers will slow the system down due to lock contention:

./perf_test_ringbuffer.py \
    --debug \
    --slot-bytes=1000000 \
    --slots=10 \
    --duration-seconds=10 \
    --writes-per-second=24 \
    --readers=100

Example that shows how the writer will fall behind its target rate when the locking overhead becomes too large:

./perf_test_ringbuffer.py \
    --debug \
    --slot-bytes=1000000 \
    --slots=10 \
    --duration-seconds=10 \
    --writes-per-second=2000 \
    --readers=1

Example that shows how the writer will fall behind its target rate when the requested data transfer rate is too high for the memory performance of the machine:

./perf_test_ringbuffer.py \
    --debug \
    --slot-bytes=100000000 \
    --slots=3 \
    --duration-seconds=10 \
    --writes-per-second=24 \
    --readers=1 \
    --no-verify_writes

Example that shows what happens when the readers can't keep up with the writer:

./perf_test_ringbuffer.py \
    --debug \
    --slot-bytes=1000000 \
    --slots=10 \
    --duration-seconds=3 \
    --writes-per-second=24 \
    --readers=4 \
    --reader-burn-cpu-milliseconds=100

More Repositories

1

effectivepython

Effective Python: Second Edition — Source Code and Errata for the Book
Python
2,133
star
2

dpxdt

Make continuous deployment safe by comparing before and after webpage screenshots for each release. Depicted shows when any visual, perceptual differences are found. This is the ultimate, automated end-to-end test.
Python
1,439
star
3

cohorts

Cohort visualizer – A handy tool for browsing cohort datasets
JavaScript
264
star
4

mirrorrr

Web proxy for App Engine
Python
179
star
5

pyliterate

The tool I used to write my book, Effective Python.
Python
81
star
6

joiner

A generic strings.Join implementation that uses the "go generate" command
Go
37
star
7

clip-it-good

Chrome extension for saving images and GIFs to Google Photo Albums
JavaScript
31
star
8

tweeps2opml

Get the RSS feeds of all of my Twitter friends
Go
30
star
9

pycon2014

Supporting code for my PyCon 2014 presentation: https://us.pycon.org/2014/schedule/presentation/218/
Python
24
star
10

pycon2016

Example code from the talk "Refactoring Python: Why and how to restructure your code" at PyCon 2016
Jupyter Notebook
19
star
11

quilla

Python
18
star
12

8-bits

Ephemeral stream app
Python
13
star
13

template-perf

Performance test of client-side <template> tag vs. server-side rendered templates
Go
8
star
14

effpygo

Example code from the series "Translating Effective Python into Go"
Go
7
star
15

pyvulcanize

Vulcanizer for Polymer projects written in Python
Python
6
star
16

heartbeat

Timeseries monitoring API built on app.net
6
star
17

opaque

Go
6
star
18

pycon2015

Example code from my talk at PyCon 2015: "How to Be More Effective with Functions"
Python
5
star
19

Baboon-Simulator

2
star
20

Interceptor

2
star
21

alum

Window manager for Chrome
JavaScript
2
star
22

existential_crisis

JavaScript
1
star