From 35071d23e90bf0ff993e2b30442cf94c27a70672 Mon Sep 17 00:00:00 2001 From: ArunMurugan-Sahaj Date: Wed, 1 May 2024 15:51:14 +0530 Subject: [PATCH 1/7] add implementation - ArunMurugan0 --- calculate_average_ArunMurugan0.sh | 18 ++ prepare_ArunMurugan0.sh | 29 ++ .../onebrc/CalculateAverage_arun_murugan.java | 253 ++++++++++++++++++ 3 files changed, 300 insertions(+) create mode 100755 calculate_average_ArunMurugan0.sh create mode 100755 prepare_ArunMurugan0.sh create mode 100644 src/main/java/dev/morling/onebrc/CalculateAverage_arun_murugan.java diff --git a/calculate_average_ArunMurugan0.sh b/calculate_average_ArunMurugan0.sh new file mode 100755 index 0000000..21afec3 --- /dev/null +++ b/calculate_average_ArunMurugan0.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# +# Copyright 2023 The original authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +target/CalculateAverage_arun_murugan_image diff --git a/prepare_ArunMurugan0.sh b/prepare_ArunMurugan0.sh new file mode 100755 index 0000000..b16e645 --- /dev/null +++ b/prepare_ArunMurugan0.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# +# Copyright 2023 The original authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Uncomment below to use sdk +# source "$HOME/.sdkman/bin/sdkman-init.sh" +# sdk use java 21.0.1-graal 1>&2 +# + +source "$HOME/.sdkman/bin/sdkman-init.sh" +sdk use java 21.0.2-graal 1>&2 + +if [ ! -f target/CalculateAverage_arun_murugan_image ]; then + NATIVE_IMAGE_OPTS="-O3 -H:TuneInlinerExploration=1 -march=native" + native-image $NATIVE_IMAGE_OPTS -cp target/average-1.0.0-SNAPSHOT.jar -o target/CalculateAverage_arun_murugan_image dev.morling.onebrc.CalculateAverage_arun_murugan +fi \ No newline at end of file diff --git a/src/main/java/dev/morling/onebrc/CalculateAverage_arun_murugan.java b/src/main/java/dev/morling/onebrc/CalculateAverage_arun_murugan.java new file mode 100644 index 0000000..9917e50 --- /dev/null +++ b/src/main/java/dev/morling/onebrc/CalculateAverage_arun_murugan.java @@ -0,0 +1,253 @@ +/* + * Copyright 2023 The original authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package dev.morling.onebrc; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.TreeMap; + +public class CalculateAverage_arun_murugan { + + private static final String FILE = "./measurements.txt"; + // private static final String FILE = "/Volumes/RAM Disk/measurements_1B.txt"; + + private static record Aggregate(double min, double max, Long count, Double sum) { + public static Aggregate defaultAggr = new Aggregate(Double.POSITIVE_INFINITY, + Double.NEGATIVE_INFINITY, 0L, 0D); + public Aggregate withUpdated(Double val) { + return new Aggregate(Math.min(min, val), Math.max(max, val), count + 1, round(sum + val)); + } + + public Aggregate merge(Aggregate other) { + return new Aggregate(Math.min(min, other.min), Math.max(max, other.max), count + other.count, round(sum + other.sum)); + } + + public String toString() { + return round(min) + "/" + round(sum / count) + "/" + round(max); + } + + private double round(double value) { + return Math.round(value * 10.0) / 10.0; + } + } + + private static class MappedByteBufferReader { + private final Long maxReads; + private Long reads = 0L; + private final MappedByteBuffer buf; + + public MappedByteBufferReader(MappedByteBuffer buf, Long maxReads) { + this.buf = buf; + this.maxReads = maxReads; + } + + public int getPosition() { + return this.buf.position(); + } + + public void setReadPosition(int newPosition, int counterDiff) { + this.buf.position(newPosition); + this.reads -= counterDiff; + } + + public int read() { + if (reads + 1 > maxReads) + return -1; + + var res = this.buf.get(); + reads++; + return res; + } + } + + private static class Processor extends Thread { + private final MappedByteBufferReader mbbReader; + private HashMap map = new HashMap<>(); + private Long offset; + private Long maxOffset; + private HashMap nameMapping = new HashMap<>(); + + public HashMap getAggrMap() { + return this.map; + } + + public HashMap getNameMapping() { + return this.nameMapping; + } + + Processor(RandomAccessFile file, long offset, long maxOffset) throws IOException { + file.seek(offset); + this.offset = offset; + this.maxOffset = maxOffset; + long maxCounter = maxOffset - offset + (maxOffset == file.length() ? 0 : 107); + var buf = file.getChannel() + .map(FileChannel.MapMode.READ_ONLY, offset, maxCounter); + this.mbbReader = new MappedByteBufferReader(buf, maxCounter); + } + + @Override + public void run() { + try { + if (offset != 0) { + skipToStartOfKey(mbbReader); + } + + while (true) { + if (offset + mbbReader.reads > maxOffset) + break; + + int prev_position = mbbReader.getPosition(); + var key = readKey(mbbReader); + if (key == null) + break; + + var aggr = map.get(key); + if (aggr == null) { + mbbReader.setReadPosition(prev_position, mbbReader.getPosition() - prev_position); + var keyStr = readKeyStr(mbbReader); + nameMapping.put(key, keyStr); + aggr = Aggregate.defaultAggr; + } + + var val = readVal(mbbReader); + if (val == null) + break; + + map.put(key, aggr.withUpdated(val)); + } + } + catch (IOException ex) { + System.out.println(ex.getMessage()); + } + } + + private void skipToStartOfKey(MappedByteBufferReader reader) throws IOException { + while (true) { + var val = reader.read(); + if (val == '\n' || val == -1) + break; + } + } + + private Long readKey(MappedByteBufferReader reader) throws IOException { + long hash = 0; + + while (true) { + var val = reader.read(); + if (val == -1) + return null; + if (val == ';') { + return hash; + } + + hash = (char) val + (hash << 6) + (hash << 16) - hash; + } + } + + private String readKeyStr(MappedByteBufferReader reader) throws IOException { + ArrayList arr = new ArrayList<>(); + while (true) { + var val = reader.read(); + if (val == -1) + return null; + if (val == ';') { + var bytes = new byte[arr.size()]; + for (int i = 0; i < arr.size(); i++) { + bytes[i] = arr.get(i); + } + + return new String(bytes, StandardCharsets.UTF_8); + } + + arr.add((byte) val); + } + } + + private Double readVal(MappedByteBufferReader reader) throws IOException { + double res = 0; + int sign = 1; + var val = reader.read(); + if (val == -1) + return null; + + if (val == '-') { + sign = -1; + } + else { + res = val - '0'; + } + + while (true) { + val = reader.read(); + if (val == -1) + return null; + if (val == '.') { + val = reader.read(); + reader.read(); + if (val == -1) + return null; + res = res + (double) (val - '0') / 10; + + return sign * res; + } + res = 10 * res + (val - '0'); + } + } + } + + public static void main(String[] args) throws IOException, InterruptedException { + long fileSize = 0L; + { + var file = new File(FILE); + fileSize = file.length(); + } + var processors = new ArrayList(); + int cores = Runtime.getRuntime().availableProcessors(); + int nThreads = Math.min((int) Math.ceil((double) fileSize / (100000 * 107)), cores); + + long partitionSize = (long) Math.ceil((double) fileSize / nThreads); + long offset = 0, maxOffset = partitionSize; + RandomAccessFile file = new RandomAccessFile(FILE, "r"); + + for (int i = 0; i < nThreads; i++) { + Processor processor = new Processor(file, offset, maxOffset); + processors.add(processor); + processor.start(); + offset = maxOffset; + maxOffset = Math.min(offset + partitionSize, fileSize); + } + + TreeMap result = new TreeMap<>(); + for (int i = nThreads - 1; i >= 0; i--) { + Processor processor = processors.get(i); + processor.join(); + + var nameMapping = processor.getNameMapping(); + + processor.getAggrMap().forEach((key, value) -> { + result.merge(nameMapping.get(key), value, Aggregate::merge); + }); + } + + System.out.println(result); + } +} From 335e0a17d957babfb3a39cc5ef9a55a33e91fb1d Mon Sep 17 00:00:00 2001 From: ArunMurugan-Sahaj Date: Thu, 2 May 2024 15:13:33 +0530 Subject: [PATCH 2/7] optimizations --- .../onebrc/CalculateAverage_arun_murugan.java | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/java/dev/morling/onebrc/CalculateAverage_arun_murugan.java b/src/main/java/dev/morling/onebrc/CalculateAverage_arun_murugan.java index 9917e50..07b5f47 100644 --- a/src/main/java/dev/morling/onebrc/CalculateAverage_arun_murugan.java +++ b/src/main/java/dev/morling/onebrc/CalculateAverage_arun_murugan.java @@ -15,7 +15,6 @@ */ package dev.morling.onebrc; -import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.MappedByteBuffer; @@ -34,15 +33,15 @@ private static record Aggregate(double min, double max, Long count, Double sum) public static Aggregate defaultAggr = new Aggregate(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 0L, 0D); public Aggregate withUpdated(Double val) { - return new Aggregate(Math.min(min, val), Math.max(max, val), count + 1, round(sum + val)); + return new Aggregate(Math.min(min, val), Math.max(max, val), count + 1, sum + val); } public Aggregate merge(Aggregate other) { - return new Aggregate(Math.min(min, other.min), Math.max(max, other.max), count + other.count, round(sum + other.sum)); + return new Aggregate(Math.min(min, other.min), Math.max(max, other.max), count + other.count, sum + other.sum); } public String toString() { - return round(min) + "/" + round(sum / count) + "/" + round(max); + return round(min) + "/" + round(round(sum) / count) + "/" + round(max); } private double round(double value) { @@ -84,17 +83,17 @@ private static class Processor extends Thread { private HashMap map = new HashMap<>(); private Long offset; private Long maxOffset; - private HashMap nameMapping = new HashMap<>(); + private final HashMap nameMapping; public HashMap getAggrMap() { return this.map; } - public HashMap getNameMapping() { - return this.nameMapping; - } + // public HashMap getNameMapping() { + // return this.nameMapping; + // } - Processor(RandomAccessFile file, long offset, long maxOffset) throws IOException { + Processor(RandomAccessFile file, long offset, long maxOffset, HashMap nameMapping) throws IOException { file.seek(offset); this.offset = offset; this.maxOffset = maxOffset; @@ -102,6 +101,7 @@ public HashMap getNameMapping() { var buf = file.getChannel() .map(FileChannel.MapMode.READ_ONLY, offset, maxCounter); this.mbbReader = new MappedByteBufferReader(buf, maxCounter); + this.nameMapping = nameMapping; } @Override @@ -122,10 +122,15 @@ public void run() { var aggr = map.get(key); if (aggr == null) { - mbbReader.setReadPosition(prev_position, mbbReader.getPosition() - prev_position); - var keyStr = readKeyStr(mbbReader); - nameMapping.put(key, keyStr); aggr = Aggregate.defaultAggr; + + if (!nameMapping.containsKey(key)) { + synchronized (this.nameMapping) { + mbbReader.setReadPosition(prev_position, mbbReader.getPosition() - prev_position); + var keyStr = readKeyStr(mbbReader); + nameMapping.put(key, keyStr); + } + } } var val = readVal(mbbReader); @@ -215,21 +220,18 @@ private Double readVal(MappedByteBufferReader reader) throws IOException { } public static void main(String[] args) throws IOException, InterruptedException { - long fileSize = 0L; - { - var file = new File(FILE); - fileSize = file.length(); - } + RandomAccessFile file = new RandomAccessFile(FILE, "r"); + long fileSize = file.length(); var processors = new ArrayList(); int cores = Runtime.getRuntime().availableProcessors(); int nThreads = Math.min((int) Math.ceil((double) fileSize / (100000 * 107)), cores); long partitionSize = (long) Math.ceil((double) fileSize / nThreads); long offset = 0, maxOffset = partitionSize; - RandomAccessFile file = new RandomAccessFile(FILE, "r"); + HashMap nameMapping = new HashMap<>(); for (int i = 0; i < nThreads; i++) { - Processor processor = new Processor(file, offset, maxOffset); + Processor processor = new Processor(file, offset, maxOffset, nameMapping); processors.add(processor); processor.start(); offset = maxOffset; @@ -238,11 +240,9 @@ public static void main(String[] args) throws IOException, InterruptedException TreeMap result = new TreeMap<>(); for (int i = nThreads - 1; i >= 0; i--) { - Processor processor = processors.get(i); + Processor processor = processors.get(nThreads - i - 1); processor.join(); - var nameMapping = processor.getNameMapping(); - processor.getAggrMap().forEach((key, value) -> { result.merge(nameMapping.get(key), value, Aggregate::merge); }); From 5745e18636e049566dba7615cc8c969a1a6c2375 Mon Sep 17 00:00:00 2001 From: ArunMurugan-Sahaj Date: Thu, 2 May 2024 18:08:46 +0530 Subject: [PATCH 3/7] more optimization --- .../onebrc/CalculateAverage_arun_murugan.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/dev/morling/onebrc/CalculateAverage_arun_murugan.java b/src/main/java/dev/morling/onebrc/CalculateAverage_arun_murugan.java index 07b5f47..9b29318 100644 --- a/src/main/java/dev/morling/onebrc/CalculateAverage_arun_murugan.java +++ b/src/main/java/dev/morling/onebrc/CalculateAverage_arun_murugan.java @@ -31,7 +31,8 @@ public class CalculateAverage_arun_murugan { private static record Aggregate(double min, double max, Long count, Double sum) { public static Aggregate defaultAggr = new Aggregate(Double.POSITIVE_INFINITY, - Double.NEGATIVE_INFINITY, 0L, 0D); + Double.NEGATIVE_INFINITY, 0L, 0D); + public Aggregate withUpdated(Double val) { return new Aggregate(Math.min(min, val), Math.max(max, val), count + 1, sum + val); } @@ -126,9 +127,11 @@ public void run() { if (!nameMapping.containsKey(key)) { synchronized (this.nameMapping) { - mbbReader.setReadPosition(prev_position, mbbReader.getPosition() - prev_position); - var keyStr = readKeyStr(mbbReader); - nameMapping.put(key, keyStr); + if (!nameMapping.containsKey(key)) { + mbbReader.setReadPosition(prev_position, mbbReader.getPosition() - prev_position); + var keyStr = readKeyStr(mbbReader); + nameMapping.put(key, keyStr); + } } } } @@ -139,8 +142,7 @@ public void run() { map.put(key, aggr.withUpdated(val)); } - } - catch (IOException ex) { + } catch (IOException ex) { System.out.println(ex.getMessage()); } } @@ -196,8 +198,7 @@ private Double readVal(MappedByteBufferReader reader) throws IOException { if (val == '-') { sign = -1; - } - else { + } else { res = val - '0'; } @@ -243,9 +244,8 @@ public static void main(String[] args) throws IOException, InterruptedException Processor processor = processors.get(nThreads - i - 1); processor.join(); - processor.getAggrMap().forEach((key, value) -> { - result.merge(nameMapping.get(key), value, Aggregate::merge); - }); + processor.getAggrMap() + .forEach((key, value) -> result.merge(nameMapping.get(key), value, Aggregate::merge)); } System.out.println(result); From f962bb281c69c9e5884887ed32a1fcda84004310 Mon Sep 17 00:00:00 2001 From: ArunMurugan-Sahaj Date: Thu, 2 May 2024 20:32:58 +0530 Subject: [PATCH 4/7] gc optimization --- prepare_ArunMurugan0.sh | 2 +- .../onebrc/CalculateAverage_arun_murugan.java | 105 +++++++++++++----- 2 files changed, 77 insertions(+), 30 deletions(-) diff --git a/prepare_ArunMurugan0.sh b/prepare_ArunMurugan0.sh index b16e645..385b81e 100755 --- a/prepare_ArunMurugan0.sh +++ b/prepare_ArunMurugan0.sh @@ -21,7 +21,7 @@ # source "$HOME/.sdkman/bin/sdkman-init.sh" -sdk use java 21.0.2-graal 1>&2 +sdk use java 22.0.1-graal 1>&2 if [ ! -f target/CalculateAverage_arun_murugan_image ]; then NATIVE_IMAGE_OPTS="-O3 -H:TuneInlinerExploration=1 -march=native" diff --git a/src/main/java/dev/morling/onebrc/CalculateAverage_arun_murugan.java b/src/main/java/dev/morling/onebrc/CalculateAverage_arun_murugan.java index 9b29318..c47a9d6 100644 --- a/src/main/java/dev/morling/onebrc/CalculateAverage_arun_murugan.java +++ b/src/main/java/dev/morling/onebrc/CalculateAverage_arun_murugan.java @@ -29,16 +29,58 @@ public class CalculateAverage_arun_murugan { private static final String FILE = "./measurements.txt"; // private static final String FILE = "/Volumes/RAM Disk/measurements_1B.txt"; - private static record Aggregate(double min, double max, Long count, Double sum) { - public static Aggregate defaultAggr = new Aggregate(Double.POSITIVE_INFINITY, - Double.NEGATIVE_INFINITY, 0L, 0D); + // private static record Aggregate(double min, double max, long count, double sum) { + // public static Aggregate defaultAggr = new Aggregate(Double.POSITIVE_INFINITY, + // Double.NEGATIVE_INFINITY, 0L, 0D); + // + // public Aggregate withUpdated(Double val) { + // return new Aggregate(Math.min(min, val), Math.max(max, val), count + 1, sum + val); + // } + // + // public Aggregate merge(Aggregate other) { + // return new Aggregate(Math.min(min, other.min), Math.max(max, other.max), count + other.count, sum + other.sum); + // } + // + // public String toString() { + // return round(min) + "/" + round(round(sum) / count) + "/" + round(max); + // } + // + // private double round(double value) { + // return Math.round(value * 10.0) / 10.0; + // } + // } + + public static class Aggregate { + private double min; + private double max; + private long count; + private double sum; + + public static Aggregate getDefaultAggr() { + return new Aggregate(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 0L, 0D); + } + + public Aggregate(double min, double max, long count, double sum) { + this.min = min; + this.max = max; + this.count = count; + this.sum = sum; + } - public Aggregate withUpdated(Double val) { - return new Aggregate(Math.min(min, val), Math.max(max, val), count + 1, sum + val); + public Aggregate withUpdated(float val) { + min = Math.min(min, val); + max = Math.max(max, val); + count++; + sum += val; + return this; } public Aggregate merge(Aggregate other) { - return new Aggregate(Math.min(min, other.min), Math.max(max, other.max), count + other.count, sum + other.sum); + min = Math.min(min, other.min); + max = Math.max(max, other.max); + count += other.count; + sum += other.sum; + return this; } public String toString() { @@ -51,11 +93,11 @@ private double round(double value) { } private static class MappedByteBufferReader { - private final Long maxReads; - private Long reads = 0L; + private final long maxReads; + private long reads = 0L; private final MappedByteBuffer buf; - public MappedByteBufferReader(MappedByteBuffer buf, Long maxReads) { + public MappedByteBufferReader(MappedByteBuffer buf, long maxReads) { this.buf = buf; this.maxReads = maxReads; } @@ -79,11 +121,14 @@ public int read() { } } + private static class EOFException extends Exception { + } + private static class Processor extends Thread { private final MappedByteBufferReader mbbReader; private HashMap map = new HashMap<>(); - private Long offset; - private Long maxOffset; + private long offset; + private long maxOffset; private final HashMap nameMapping; public HashMap getAggrMap() { @@ -118,12 +163,10 @@ public void run() { int prev_position = mbbReader.getPosition(); var key = readKey(mbbReader); - if (key == null) - break; var aggr = map.get(key); if (aggr == null) { - aggr = Aggregate.defaultAggr; + aggr = Aggregate.getDefaultAggr(); if (!nameMapping.containsKey(key)) { synchronized (this.nameMapping) { @@ -137,13 +180,14 @@ public void run() { } var val = readVal(mbbReader); - if (val == null) - break; map.put(key, aggr.withUpdated(val)); } - } catch (IOException ex) { - System.out.println(ex.getMessage()); + } + catch (CalculateAverage_arun_murugan.EOFException ignored) { + } + catch (IOException ex) { + System.err.println(ex); } } @@ -155,13 +199,13 @@ private void skipToStartOfKey(MappedByteBufferReader reader) throws IOException } } - private Long readKey(MappedByteBufferReader reader) throws IOException { + private long readKey(MappedByteBufferReader reader) throws IOException, CalculateAverage_arun_murugan.EOFException { long hash = 0; while (true) { var val = reader.read(); if (val == -1) - return null; + throw new CalculateAverage_arun_murugan.EOFException(); if (val == ';') { return hash; } @@ -170,12 +214,12 @@ private Long readKey(MappedByteBufferReader reader) throws IOException { } } - private String readKeyStr(MappedByteBufferReader reader) throws IOException { + private String readKeyStr(MappedByteBufferReader reader) throws IOException, CalculateAverage_arun_murugan.EOFException { ArrayList arr = new ArrayList<>(); while (true) { var val = reader.read(); if (val == -1) - return null; + throw new CalculateAverage_arun_murugan.EOFException(); if (val == ';') { var bytes = new byte[arr.size()]; for (int i = 0; i < arr.size(); i++) { @@ -189,29 +233,32 @@ private String readKeyStr(MappedByteBufferReader reader) throws IOException { } } - private Double readVal(MappedByteBufferReader reader) throws IOException { - double res = 0; + private float readVal(MappedByteBufferReader reader) throws IOException, CalculateAverage_arun_murugan.EOFException { + float res = 0; int sign = 1; var val = reader.read(); if (val == -1) - return null; + throw new CalculateAverage_arun_murugan.EOFException(); if (val == '-') { sign = -1; - } else { + } + else { res = val - '0'; } while (true) { val = reader.read(); if (val == -1) - return null; + throw new CalculateAverage_arun_murugan.EOFException(); + if (val == '.') { val = reader.read(); reader.read(); if (val == -1) - return null; - res = res + (double) (val - '0') / 10; + throw new CalculateAverage_arun_murugan.EOFException(); + + res = res + (float) (val - '0') / 10; return sign * res; } From d400cd247e3db7fb44e1c85e11684f00254ad4e8 Mon Sep 17 00:00:00 2001 From: ArunMurugan-Sahaj Date: Thu, 2 May 2024 23:10:28 +0530 Subject: [PATCH 5/7] set max heap size --- calculate_average_ArunMurugan0.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/calculate_average_ArunMurugan0.sh b/calculate_average_ArunMurugan0.sh index 21afec3..9ee61d2 100755 --- a/calculate_average_ArunMurugan0.sh +++ b/calculate_average_ArunMurugan0.sh @@ -15,4 +15,5 @@ # limitations under the License. # -target/CalculateAverage_arun_murugan_image +# -XX:+PrintGC +target/CalculateAverage_arun_murugan_image -Xms12g -Xmx12g \ No newline at end of file From 1a99c3b144611aeff7bee5fb6acf4634d2b0b28b Mon Sep 17 00:00:00 2001 From: ArunMurugan-Sahaj Date: Fri, 3 May 2024 09:48:29 +0530 Subject: [PATCH 6/7] remove heap falgs --- calculate_average_ArunMurugan0.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/calculate_average_ArunMurugan0.sh b/calculate_average_ArunMurugan0.sh index 9ee61d2..51651a7 100755 --- a/calculate_average_ArunMurugan0.sh +++ b/calculate_average_ArunMurugan0.sh @@ -16,4 +16,4 @@ # # -XX:+PrintGC -target/CalculateAverage_arun_murugan_image -Xms12g -Xmx12g \ No newline at end of file +target/CalculateAverage_arun_murugan_image From b3f91d438102b05ea169c7147b00d0a18190807a Mon Sep 17 00:00:00 2001 From: ArunMurugan-Sahaj Date: Fri, 3 May 2024 09:54:00 +0530 Subject: [PATCH 7/7] rename class --- calculate_average_ArunMurugan0.sh | 2 +- prepare_ArunMurugan0.sh | 4 ++-- ...ava => CalculateAverage_ArunMurugan0.java} | 20 +++++++++---------- 3 files changed, 13 insertions(+), 13 deletions(-) rename src/main/java/dev/morling/onebrc/{CalculateAverage_arun_murugan.java => CalculateAverage_ArunMurugan0.java} (94%) diff --git a/calculate_average_ArunMurugan0.sh b/calculate_average_ArunMurugan0.sh index 51651a7..fc43f8d 100755 --- a/calculate_average_ArunMurugan0.sh +++ b/calculate_average_ArunMurugan0.sh @@ -16,4 +16,4 @@ # # -XX:+PrintGC -target/CalculateAverage_arun_murugan_image +target/CalculateAverage_ArunMurugan0_image diff --git a/prepare_ArunMurugan0.sh b/prepare_ArunMurugan0.sh index 385b81e..865699d 100755 --- a/prepare_ArunMurugan0.sh +++ b/prepare_ArunMurugan0.sh @@ -23,7 +23,7 @@ source "$HOME/.sdkman/bin/sdkman-init.sh" sdk use java 22.0.1-graal 1>&2 -if [ ! -f target/CalculateAverage_arun_murugan_image ]; then +if [ ! -f target/CalculateAverage_ArunMurugan0_image ]; then NATIVE_IMAGE_OPTS="-O3 -H:TuneInlinerExploration=1 -march=native" - native-image $NATIVE_IMAGE_OPTS -cp target/average-1.0.0-SNAPSHOT.jar -o target/CalculateAverage_arun_murugan_image dev.morling.onebrc.CalculateAverage_arun_murugan + native-image $NATIVE_IMAGE_OPTS -cp target/average-1.0.0-SNAPSHOT.jar -o target/CalculateAverage_ArunMurugan0_image dev.morling.onebrc.CalculateAverage_ArunMurugan0 fi \ No newline at end of file diff --git a/src/main/java/dev/morling/onebrc/CalculateAverage_arun_murugan.java b/src/main/java/dev/morling/onebrc/CalculateAverage_ArunMurugan0.java similarity index 94% rename from src/main/java/dev/morling/onebrc/CalculateAverage_arun_murugan.java rename to src/main/java/dev/morling/onebrc/CalculateAverage_ArunMurugan0.java index c47a9d6..5281a90 100644 --- a/src/main/java/dev/morling/onebrc/CalculateAverage_arun_murugan.java +++ b/src/main/java/dev/morling/onebrc/CalculateAverage_ArunMurugan0.java @@ -24,7 +24,7 @@ import java.util.HashMap; import java.util.TreeMap; -public class CalculateAverage_arun_murugan { +public class CalculateAverage_ArunMurugan0 { private static final String FILE = "./measurements.txt"; // private static final String FILE = "/Volumes/RAM Disk/measurements_1B.txt"; @@ -184,7 +184,7 @@ public void run() { map.put(key, aggr.withUpdated(val)); } } - catch (CalculateAverage_arun_murugan.EOFException ignored) { + catch (CalculateAverage_ArunMurugan0.EOFException ignored) { } catch (IOException ex) { System.err.println(ex); @@ -199,13 +199,13 @@ private void skipToStartOfKey(MappedByteBufferReader reader) throws IOException } } - private long readKey(MappedByteBufferReader reader) throws IOException, CalculateAverage_arun_murugan.EOFException { + private long readKey(MappedByteBufferReader reader) throws IOException, CalculateAverage_ArunMurugan0.EOFException { long hash = 0; while (true) { var val = reader.read(); if (val == -1) - throw new CalculateAverage_arun_murugan.EOFException(); + throw new CalculateAverage_ArunMurugan0.EOFException(); if (val == ';') { return hash; } @@ -214,12 +214,12 @@ private long readKey(MappedByteBufferReader reader) throws IOException, Calculat } } - private String readKeyStr(MappedByteBufferReader reader) throws IOException, CalculateAverage_arun_murugan.EOFException { + private String readKeyStr(MappedByteBufferReader reader) throws IOException, CalculateAverage_ArunMurugan0.EOFException { ArrayList arr = new ArrayList<>(); while (true) { var val = reader.read(); if (val == -1) - throw new CalculateAverage_arun_murugan.EOFException(); + throw new CalculateAverage_ArunMurugan0.EOFException(); if (val == ';') { var bytes = new byte[arr.size()]; for (int i = 0; i < arr.size(); i++) { @@ -233,12 +233,12 @@ private String readKeyStr(MappedByteBufferReader reader) throws IOException, Cal } } - private float readVal(MappedByteBufferReader reader) throws IOException, CalculateAverage_arun_murugan.EOFException { + private float readVal(MappedByteBufferReader reader) throws IOException, CalculateAverage_ArunMurugan0.EOFException { float res = 0; int sign = 1; var val = reader.read(); if (val == -1) - throw new CalculateAverage_arun_murugan.EOFException(); + throw new CalculateAverage_ArunMurugan0.EOFException(); if (val == '-') { sign = -1; @@ -250,13 +250,13 @@ private float readVal(MappedByteBufferReader reader) throws IOException, Calcula while (true) { val = reader.read(); if (val == -1) - throw new CalculateAverage_arun_murugan.EOFException(); + throw new CalculateAverage_ArunMurugan0.EOFException(); if (val == '.') { val = reader.read(); reader.read(); if (val == -1) - throw new CalculateAverage_arun_murugan.EOFException(); + throw new CalculateAverage_ArunMurugan0.EOFException(); res = res + (float) (val - '0') / 10;