rename cluster to partition
We are not clustering the indices, we are partitioning them.
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
package org.lucares.pdbui;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.DoubleSummaryStatistics;
|
||||
import java.util.List;
|
||||
|
||||
public class CsvToEntryTransformerPerformanceTest {
|
||||
|
||||
private static final byte NEWLINE = '\n';
|
||||
|
||||
public static void main(final String[] args) throws Exception {
|
||||
// final Path csvFile =
|
||||
// Paths.get("/home/andi/ws/performanceDb/data/production/1k.csv");
|
||||
final Path csvFile = Paths.get("/home/andi/ws/performanceDb/data/production/logs_2018-09-05_2018-09-05.csv");
|
||||
|
||||
final int skip = 0;
|
||||
|
||||
final List<Double> times = new ArrayList<>();
|
||||
for (int i = 0; i < 105; i++) {
|
||||
final long start = System.nanoTime();
|
||||
runtest(csvFile);
|
||||
final double duration = (System.nanoTime() - start) / 1_000_000.0;
|
||||
times.add(duration);
|
||||
// System.out.println("duration: " + duration + "ms");
|
||||
if (i >= skip) {
|
||||
System.out.println((int) Math.round(duration * 1000));
|
||||
}
|
||||
}
|
||||
|
||||
final DoubleSummaryStatistics summaryStatisticsPut = times.stream().skip(skip).mapToDouble(d -> (double) d)
|
||||
.summaryStatistics();
|
||||
// System.out.println("summary: " + summaryStatisticsPut);
|
||||
}
|
||||
|
||||
private static void runtest(final Path csvFile) throws IOException, FileNotFoundException {
|
||||
final byte newline = NEWLINE;
|
||||
|
||||
byte[] line = new byte[4096]; // max line length
|
||||
int offsetInLine = 0;
|
||||
int offsetInBuffer = 0;
|
||||
int linecount = 0;
|
||||
|
||||
try (final FileChannel channel = FileChannel.open(csvFile, StandardOpenOption.READ)) {
|
||||
int read = 0;
|
||||
int bytesInLine = 0;
|
||||
|
||||
final ByteBuffer buffer = ByteBuffer.allocate(4096 * 4);
|
||||
while ((read = channel.read(buffer)) >= 0) {
|
||||
offsetInBuffer = 0;
|
||||
|
||||
final byte[] b = buffer.array();
|
||||
|
||||
for (int i = 0; i < read; i++) {
|
||||
if (b[i] == newline) {
|
||||
final int length = i - offsetInBuffer;
|
||||
System.arraycopy(b, offsetInBuffer, line, offsetInLine, length);
|
||||
bytesInLine = offsetInLine + length;
|
||||
|
||||
linecount++;
|
||||
handleLine(line, bytesInLine);
|
||||
line = new byte[4096];
|
||||
|
||||
offsetInBuffer = i + 1;
|
||||
offsetInLine = 0;
|
||||
bytesInLine = 0;
|
||||
}
|
||||
}
|
||||
if (offsetInBuffer < read) {
|
||||
final int length = read - offsetInBuffer;
|
||||
System.arraycopy(b, offsetInBuffer, line, offsetInLine, length);
|
||||
bytesInLine = offsetInLine + length;
|
||||
offsetInLine += length;
|
||||
offsetInBuffer = 0;
|
||||
|
||||
}
|
||||
buffer.rewind();
|
||||
}
|
||||
|
||||
linecount++;
|
||||
handleLine(line, bytesInLine);
|
||||
}
|
||||
// System.out.println("lines: " + linecount);
|
||||
}
|
||||
|
||||
private static void handleLine(final byte[] line, final int bytesInLine) {
|
||||
|
||||
final String x = new String(line, 0, bytesInLine, StandardCharsets.UTF_8);
|
||||
// System.out.println(">" + x + "<");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user