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

Remove DIRTY NIF flag #44

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

martinsumner
Copy link

Thank-you for providing this repo, I've been able to use it to test adding zstd compression to the leveled database (which is used as a storage backend for the Riak database). After running some experiments adding this zstd compression library, it has been observed that there appears to be a significant cost from the recent PR which set the ERL_DIRTY_JOB_CPU_BOUND on the compress and decompress NIF.

See OpenRiak#1. In the leveled perf_SUITE ct test (which is broad database load test), there is a 10%-30% cost from running ZSTD with the flag. Even with a simple unit test there is a clear difference.

With ERL_DIRTY_JOB_CPU_BOUND:

Compression time ZLIB 1739 LZ4 476 ZSTD 306 Decompression time ZLIB 272 LZ4 88 ZSTD 140

Without ERL_DIRTY_JOB_CPU_BOUND:

Compression time ZLIB 1877 LZ4 456 ZSTD 251 Decompression time ZLIB 284 LZ4 86 ZSTD 110

Reading the nif guidelines, it talks of the threshold being 1ms before a dirty CPU flag is required. Given the overhead is the flag appropriate for standard compress/decompress function? Perhaps there should be a separate entry point if one is sure the compress/decompress time is within those bounds?

I have limited experience with NIFs, so this PR is provided as a suggestion, but I'm happy to accept that this might not be the right thing to do.

https://www.erlang.org/doc/man/erl_nif.html documentation indicates the threshold for being a dirty NIF should be about 1ms.  Generally compress/decompress is much quicker than this.

Testing indicates a significant overhead from using this flag when compress/decompress is in fact very fast.
@CLAassistant
Copy link

CLAassistant commented Jan 12, 2024

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Using a dirty_nif for smaller objects has a performance penalty so:

- by default don't use the dirty nif if compressing < 250KB or uncompressing < 50KB
- allow application to override and specifically request either dirty or quick method.
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.

2 participants