use buffered writer
despite my previous test, writing the csv is a little bit faster with a buffered writer (~ 10-15%)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package org.lucares.recommind.logs;
|
package org.lucares.recommind.logs;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -129,10 +130,12 @@ public class Plotter {
|
|||||||
if (minDate.until(maxDate, ChronoUnit.WEEKS) > 1) {
|
if (minDate.until(maxDate, ChronoUnit.WEEKS) > 1) {
|
||||||
formatX = "%Y-%m-%d";
|
formatX = "%Y-%m-%d";
|
||||||
rotateX = 0;
|
rotateX = 0;
|
||||||
} else {
|
} else if (minDate.until(maxDate, ChronoUnit.SECONDS) > 10) {
|
||||||
|
|
||||||
formatX = "%Y-%m-%d %H:%M:%S";
|
formatX = "%Y-%m-%d %H:%M:%S";
|
||||||
rotateX = gnuplotSettings.getRotateXAxisLabel();
|
rotateX = gnuplotSettings.getRotateXAxisLabel();
|
||||||
|
} else {
|
||||||
|
formatX = "%Y-%m-%d %H:%M:%.3S";
|
||||||
|
rotateX = gnuplotSettings.getRotateXAxisLabel();
|
||||||
}
|
}
|
||||||
formattedMinDate = minDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"));
|
formattedMinDate = minDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"));
|
||||||
formattedMaxDate = maxDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"));
|
formattedMaxDate = maxDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"));
|
||||||
@@ -214,9 +217,11 @@ public class Plotter {
|
|||||||
final long fromEpochMilli = dateFrom.toInstant().toEpochMilli();
|
final long fromEpochMilli = dateFrom.toInstant().toEpochMilli();
|
||||||
final long toEpochMilli = dateTo.toInstant().toEpochMilli();
|
final long toEpochMilli = dateTo.toInstant().toEpochMilli();
|
||||||
long maxValue = 0;
|
long maxValue = 0;
|
||||||
|
long ignoredValues = 0;
|
||||||
final int separator = ',';
|
final int separator = ',';
|
||||||
final int newline = '\n';
|
final int newline = '\n';
|
||||||
try (final Writer output = new OutputStreamWriter(new FileOutputStream(dataFile), StandardCharsets.US_ASCII);) {
|
final DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
|
||||||
|
try (final Writer output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dataFile), StandardCharsets.US_ASCII));) {
|
||||||
|
|
||||||
final Iterator<Entry> it = entries.iterator();
|
final Iterator<Entry> it = entries.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
@@ -225,7 +230,7 @@ public class Plotter {
|
|||||||
if (fromEpochMilli <= entry.getEpochMilli() && entry.getEpochMilli() <= toEpochMilli) {
|
if (fromEpochMilli <= entry.getEpochMilli() && entry.getEpochMilli() <= toEpochMilli) {
|
||||||
final OffsetDateTime date = entry.getDate();
|
final OffsetDateTime date = entry.getDate();
|
||||||
final String value = String.valueOf(entry.getValue());
|
final String value = String.valueOf(entry.getValue());
|
||||||
final String formattedDate = date.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
|
final String formattedDate = date.format(formatter);
|
||||||
output.write(formattedDate);
|
output.write(formattedDate);
|
||||||
output.write(separator);
|
output.write(separator);
|
||||||
output.write(value);
|
output.write(value);
|
||||||
@@ -233,11 +238,13 @@ public class Plotter {
|
|||||||
|
|
||||||
count++;
|
count++;
|
||||||
maxValue = Math.max(maxValue, entry.getValue());
|
maxValue = Math.max(maxValue, entry.getValue());
|
||||||
|
}else {
|
||||||
|
ignoredValues++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
METRICS_LOGGER.debug("wrote {} values to csv in: {}ms", count, (System.nanoTime() - start) / 1_000_000.0);
|
METRICS_LOGGER.debug("wrote {} values to csv in: {}ms (ignored {} values)", count, (System.nanoTime() - start) / 1_000_000.0, ignoredValues);
|
||||||
return new CsvSummary(count, maxValue);
|
return new CsvSummary(count, maxValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user