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

Add parallel compression #167

Merged
merged 12 commits into from
Oct 1, 2024
Merged

Add parallel compression #167

merged 12 commits into from
Oct 1, 2024

Conversation

vasi
Copy link
Contributor

@vasi vasi commented Oct 1, 2024

zstdseek is great, but slow. Let's use more cores!

  • Adds a FrameSource abstraction, a function that returns a bunch of frames in order
  • Adds a ConcurrentWriter interface, which adds WriteMany to add all frames from a FrameSource using concurrency
    • WriteMany takes variadic options, including: WithConcurrency to manually set concurrency level, and WithWriteCallback to run a callback each time a frame is written
  • Adds pretty complete testing: Compares the results of regular Write vs WriteMany, and benchmarks them
  • Modifies benchmark to just fake writing results, so we don't have to hold so much data in memory
  • Uses WriteMany in zstdseek

Results of benchmarks on my machine:

$ go test -bench=Write -benchtime=5s
goos: linux
goarch: amd64
pkg: github.com/SaveTheRbtz/zstd-seekable-format-go/pkg
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
BenchmarkWrite/128-12         	 6892479	       820.2 ns/op	 156.06 MB/s
BenchmarkWrite/Parallel-128-12         	 1000000	      7606 ns/op	  16.83 MB/s
BenchmarkWrite/4096-12                 	 1000000	      9277 ns/op	 441.52 MB/s
BenchmarkWrite/Parallel-4096-12        	  581739	      9826 ns/op	 416.85 MB/s
BenchmarkWrite/16384-12                	  214653	     24568 ns/op	 666.88 MB/s
BenchmarkWrite/Parallel-16384-12       	  390426	     14231 ns/op	1151.31 MB/s
BenchmarkWrite/65536-12                	   60656	     85210 ns/op	 769.11 MB/s
BenchmarkWrite/Parallel-65536-12       	  134016	     41333 ns/op	1585.55 MB/s
BenchmarkWrite/1048576-12              	    3476	   1730455 ns/op	 605.95 MB/s
BenchmarkWrite/Parallel-1048576-12     	   10126	    568612 ns/op	1844.10 MB/s

In tests of zstdseek, I see speedups of anywhere between 2x and 5x. I'm not sure why I can't quite hit the 12x I'd expect.

But implementation is not yet concurrent
Also change to a null writer in benchmark, so we don't use so much memory
Benchmarks show it faster, nice
pkg/writer.go Outdated Show resolved Hide resolved
pkg/writer.go Outdated Show resolved Hide resolved
pkg/writer.go Outdated Show resolved Hide resolved
pkg/writer.go Outdated Show resolved Hide resolved
pkg/writer.go Show resolved Hide resolved
pkg/writer.go Outdated Show resolved Hide resolved
pkg/writer.go Show resolved Hide resolved
pkg/writer.go Outdated Show resolved Hide resolved
@SaveTheRbtz
Copy link
Owner

Really nice performance improvement! Thank you for the contribution!

Copy link

codecov bot commented Oct 1, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 12 lines in your changes missing coverage. Please review.

Project coverage is 79.34%. Comparing base (301c94b) to head (4e1ed4e).
Report is 43 commits behind head on main.

Files with missing lines Patch % Lines
pkg/encoder.go 42.85% 7 Missing and 1 partial ⚠️
pkg/writer.go 93.33% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #167      +/-   ##
==========================================
+ Coverage   77.34%   79.34%   +2.00%     
==========================================
  Files           7        7              
  Lines         384      460      +76     
==========================================
+ Hits          297      365      +68     
- Misses         61       67       +6     
- Partials       26       28       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vasi
Copy link
Contributor Author

vasi commented Oct 1, 2024

Tried to add a bunch of silly tests to make codecov happy :)

@SaveTheRbtz SaveTheRbtz merged commit 0e32fcc into SaveTheRbtz:main Oct 1, 2024
10 checks passed
@SaveTheRbtz
Copy link
Owner

Thank you for your contribution!

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