🚀 DAY 2 OF LAUNCH WEEK: Announcing Socket Certified Patches: One-Click Fixes for Vulnerable Dependencies.Learn more →
Socket
Book a DemoInstallSign in
Socket

github.com/templexxx/reedsolomon

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/templexxx/reedsolomon

Source
Go
Version
v1.1.3
Version published
Created
Source

Reed-Solomon

GoDoc MIT licensed Build Status Go Report Card Sourcegraph

Introduction:

  • 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.

  • High Reliability:

  • 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).

  • Based on Klauspost ReedSolomon & Intel ISA-L with some additional changes/optimizations.

  • It's the backend of XRS (Erasure Codes which can save about 30% I/O in reconstruction process).

Specification

Math

  • 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.

XP has written an excellent article (Here, in Chinese) about how Erasure Codes works and the math behind it. It's a good start to read it.

Accelerate

  • SIMD: Screaming Fast Galois Field Arithmetic Using Intel SIMD Instructions

  • 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

Performance depends mainly on:

  • CPU instruction extension.

  • Number of data/parity row vectors.

Platform:

AWS c5d.xlarge (Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz)

All test run on a single Core.

Encode:

I/O = (data + parity) * vector_size / cost

Base means no SIMD.

DataParityVector sizeAVX512 I/O (MB/S)AVX2 I/O (MB/S)Base I/O (MB/S)
1024KB29683.6921371.43910.45
1021MB17664.6715505.58917.26
1028MB10363.059323.60914.62
1044KB17708.6212705.35531.82
1041MB11970.429804.57536.31
1048MB7957.96941.69534.82
1244KB16902.1212065.14511.95
1241MB11478.869392.33514.24
1248MB7949.816760.49513.06

Reconstruct:

I/O = (data + reconstruct_data_num) * vector_size / cost

DataParityVector sizeReconstruct Data NumAVX512 I/O (MB/S)
1044KB129830.36
1044KB221649.61
1044KB317088.41
1044KB414567.26

Update:

I/O = (2 + parity_num + parity_num) * vector_size / cost

DataParityVector sizeAVX512 I/O (MB/S)
1044KB36444.13

Replace:

I/O = (parity_num + parity_num + replace_data_num) * vector_size / cost

DataParityVector sizeReplace Data NumAVX512 I/O (MB/S)
1044KB178464.33
1044KB250068.71
1044KB338808.11
1044KB432457.60
1044KB528679.46
1044KB626151.85

PS:

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.

  • Klauspost ReedSolomon: It's the most commonly used Erasure Codes library in Go. Impressive performance, friendly API, and it can support multi platforms(with fast Galois Field Arithmetic). Inspired me a lot.

  • Intel ISA-L: The ideas of Cauchy matrix and saving memory I/O are from it.

FAQs

Package last updated on 17 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts