Erasure Codes(based on Reed-Solomon Codes) engine in pure Go.
It's a kind of Systematic Codes, which means the input data is embedded in the encoded output .
High Performance: More than 15GB/s per physics core.
- At least two companies are using this library in their storage system. (More than dozens PB data)
- Full test of galois field calculation and invertible matrices (You can also find the mathematical proof in this repo).
Coding over in GF(2^8).
Primitive Polynomial: x^8 + x^4 + x^3 + x^2 + 1 (0x1d).
Cauchy Matrix is the generator matrix.
- Any submatrix of encoding matrix is invertible (See the proof here).
Galois Field Tool: Generate primitive polynomial and it's log, exponent, multiply and inverse tables etc.
Inverse Matrices Tool: Calculate the number of inverse matrices with specific data & parity number.
Reduce memory I/O: Write cache-friendly code. In the process of two matrices multiply, we will have to read data times, and keep the temporary results, then write to memory. If we could put more data into CPU's Cache but not read/write memory again and again, the performance should improve a lot.
Cache inverse matrices: It'll save thousands ns, not much, but it's still meaningful for small data.
Here (in Chinese) is an article about how to write a fast Erasure Codes engine. (Written by me years ago, need update, but the main ideas still work)
Performance depends mainly on:
CPU instruction extension.
Number of data/parity row vectors.
AWS c5d.xlarge (Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz)
All test run on a single Core.
I/O = (data + parity) * vector_size / cost
Base means no SIMD.
|Data||Parity||Vector size||AVX512 I/O (MB/S)||AVX2 I/O (MB/S)||Base I/O (MB/S)|
I/O = (data + reconstruct_data_num) * vector_size / cost
|Data||Parity||Vector size||Reconstruct Data Num||AVX512 I/O (MB/S)|
I/O = (2 + parity_num + parity_num) * vector_size / cost
|Data||Parity||Vector size||AVX512 I/O (MB/S)|
I/O = (parity_num + parity_num + replace_data_num) * vector_size / cost
|Data||Parity||Vector size||Replace Data Num||AVX512 I/O (MB/S)|
And we must know the benchmark test is quite different with encoding/decoding in practice. Because in benchmark test loops, the CPU Cache may help a lot.