private Measurement doOneEncodeMeasurement(ReedSolomon codec, BufferSet[] bufferSets) { long passesCompleted = 0; long bytesEncoded = 0; long encodingTime = 0; while (encodingTime < MEASUREMENT_DURATION) { BufferSet bufferSet = bufferSets[nextBuffer]; nextBuffer = (nextBuffer + 1) % bufferSets.Length; byte[][] shards = bufferSet.buffers; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); codec.encodeParity(shards, 0, BUFFER_SIZE); stopwatch.Stop(); long stop = stopwatch.ElapsedMilliseconds; TimeSpan timespan = stopwatch.Elapsed; encodingTime += (long)timespan.TotalMilliseconds; bytesEncoded += BUFFER_SIZE * DATA_COUNT; passesCompleted += 1; } double seconds = ((double)encodingTime) / 1000.0; double megabytes = ((double)bytesEncoded) / 1000000.0; Measurement result = new Measurement(megabytes, seconds); Console.WriteLine(" {0} passes, {1}", passesCompleted, result.ToString()); return(result); }
/** * Encodes a set of data shards, and then tries decoding * using all possible subsets of the encoded shards. * * Uses 5+5 coding, so there must be 5 input data shards. */ private void runEncodeDecode(int dataCount, int parityCount, byte[][] dataShards) { int totalCount = dataCount + parityCount; int shardLength = dataShards[0].Length; // Make the list of data and parity shards. // assertEquals(dataCount, dataShards.length); int dataLength = dataShards[0].Length; byte [] [] allShards = new byte [totalCount] []; for (int i = 0; i < dataCount; i++) { byte[] temp = new byte[dataLength]; Array.Copy(dataShards[i], 0, temp, 0, dataLength); allShards[i] = temp; } for (int i = dataCount; i < totalCount; i++) { allShards[i] = new byte [dataLength]; } // Encode. ReedSolomon codec = ReedSolomon.create(dataCount, parityCount); codec.encodeParity(allShards, 0, dataLength); // Make a copy to decode with. byte [] [] testShards = new byte [totalCount] []; bool [] shardPresent = new bool [totalCount]; for (int i = 0; i < totalCount; i++) { byte[] temp = new byte[shardLength]; Array.Copy(allShards[i], 0, temp, 0, shardLength); testShards[i] = temp; shardPresent[i] = true; } // Decode with 0, 1, ..., 5 shards missing. for (int numberMissing = 0; numberMissing < parityCount + 1; numberMissing++) { tryAllSubsetsMissing(codec, allShards, testShards, shardPresent, numberMissing); } }