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

Use hardware accelerated CRC32C function if available #1389

Merged
merged 2 commits into from
Feb 21, 2018
Merged

Conversation

tvoinarovskyi
Copy link
Collaborator

@tvoinarovskyi tvoinarovskyi commented Feb 19, 2018

@dpkp @jeffwidman Hehe, I'm an idiot for this =) So, here I was pushing my butt to accelerate varint implementation, but did not look properly at the profiler.
Long story short, while accelerating the V2 implementation for aiokafka I found that _crc32c.py is super slow and takes more time for 1 call than 100 append. So as a fast fix I propose to use https://github.com/ICRAR/crc32c if available on the system. I will look into _crc32c.py script later to make it a bit faster.

Benchmark without HW crc32:

.....................
batch_read_v0: Mean +- std dev: 1.42 ms +- 0.03 ms
.....................
batch_read_v1: Mean +- std dev: 1.44 ms +- 0.03 ms
.....................
batch_read_v2: Mean +- std dev: 3.10 ms +- 0.06 ms

With HW crc32:

.....................
batch_read_v0: Mean +- std dev: 1.48 ms +- 0.05 ms
.....................
batch_read_v1: Mean +- std dev: 1.49 ms +- 0.05 ms
.....................
batch_read_v2: Mean +- std dev: 1.09 ms +- 0.04 ms

So now V2 is relatively the same speed as V1 and V0. Now we can move on to TransactionalProducer =)

@jeffwidman
Copy link
Collaborator

jeffwidman commented Feb 21, 2018

Oh interesting. Two thoughts:

  1. If we go down this route of fixing by adding an optional dependency, there should be a note about it in the docs as an optional way to speedup kafka-python.
  2. It's not clear to me what the other options are beyond adding an optional dependency... since this isn't pure python, does that create problems with directly vendoring it in like we do a few other libs?

@tvoinarovskyi
Copy link
Collaborator Author

@jeffwidman Yea, will patch the docs.
Yes, you can't easiely bundle a C extension module, you will need to correctly build it. As for alternitives, in aiokafka I plan to use the C implementation taken from librdkafka...
I will also try to make the python script at least somewhat faster.

@@ -70,3 +70,16 @@ Install the `python-snappy` module
.. code:: bash

pip install python-snappy


Optional crc32c install
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeffwidman Could you read this through, good enough?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great

Copy link
Collaborator

@jeffwidman jeffwidman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I held off on merging this @tvoinarovskyi in case you want to make any more changes first... when you're ready please press the green button.

@@ -70,3 +70,16 @@ Install the `python-snappy` module
.. code:: bash

pip install python-snappy


Optional crc32c install
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great

@tvoinarovskyi tvoinarovskyi merged commit 0c0c7ea into master Feb 21, 2018
@dpkp dpkp deleted the hw_crc32c branch March 24, 2018 13:28
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

Successfully merging this pull request may close these issues.

3 participants