kopia lustrzana https://github.com/onthegomap/planetiler
move benchmarks to separate module
rodzic
0a94157888
commit
233bbe3e34
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>flatmap-benchmarks</artifactId>
|
||||
|
||||
<parent>
|
||||
<groupId>com.onthegomap</groupId>
|
||||
<artifactId>flatmap-parent</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.onthegomap</groupId>
|
||||
<artifactId>flatmap-core</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.onthegomap</groupId>
|
||||
<artifactId>flatmap-openmaptiles</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,123 @@
|
|||
package com.onthegomap.flatmap.benchmarks;
|
||||
|
||||
import static io.prometheus.client.Collector.NANOSECONDS_PER_SECOND;
|
||||
|
||||
import com.onthegomap.flatmap.collection.LongLongMap;
|
||||
import com.onthegomap.flatmap.stats.Counter;
|
||||
import com.onthegomap.flatmap.stats.ProcessInfo;
|
||||
import com.onthegomap.flatmap.stats.ProgressLoggers;
|
||||
import com.onthegomap.flatmap.stats.Stats;
|
||||
import com.onthegomap.flatmap.util.FileUtils;
|
||||
import com.onthegomap.flatmap.util.Format;
|
||||
import com.onthegomap.flatmap.worker.Worker;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Duration;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class LongLongMapBench {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
Path path = Path.of("./llmaptest");
|
||||
FileUtils.delete(path);
|
||||
LongLongMap map = switch (args[0]) {
|
||||
case "sparsemem2" -> LongLongMap.newInMemorySparseArray2();
|
||||
case "sparsearraymemory" -> LongLongMap.newInMemorySparseArray();
|
||||
case "hppc" -> new LongLongMap.HppcMap();
|
||||
case "array" -> new LongLongMap.Array();
|
||||
|
||||
case "sparse2" -> LongLongMap.newFileBackedSparseArray2(path);
|
||||
case "sqlite" -> LongLongMap.newSqlite(path);
|
||||
case "sparsearray" -> LongLongMap.newFileBackedSparseArray(path);
|
||||
case "mapdb" -> LongLongMap.newFileBackedSortedTable(path);
|
||||
default -> throw new IllegalStateException("Unexpected value: " + args[0]);
|
||||
};
|
||||
long entries = Long.parseLong(args[1]);
|
||||
int readers = Integer.parseInt(args[2]);
|
||||
|
||||
class LocalCounter {
|
||||
|
||||
long count = 0;
|
||||
}
|
||||
LocalCounter counter = new LocalCounter();
|
||||
ProgressLoggers loggers = new ProgressLoggers("write")
|
||||
.addRatePercentCounter("entries", entries, () -> counter.count)
|
||||
.newLine()
|
||||
.addProcessStats();
|
||||
AtomicReference<String> writeRate = new AtomicReference<>();
|
||||
new Worker("writer", Stats.inMemory(), 1, () -> {
|
||||
long start = System.nanoTime();
|
||||
for (long i = 0; i < entries; i++) {
|
||||
map.put(i + 1L, i + 2L);
|
||||
counter.count = i;
|
||||
}
|
||||
long end = System.nanoTime();
|
||||
String rate = Format.formatNumeric(entries * NANOSECONDS_PER_SECOND / (end - start), false) + "/s";
|
||||
System.err.println("Loaded " + entries + " in " + Duration.ofNanos(end - start).toSeconds() + "s (" + rate + ")");
|
||||
writeRate.set(rate);
|
||||
}).awaitAndLog(loggers, Duration.ofSeconds(10));
|
||||
|
||||
map.get(1);
|
||||
System.err.println("Storage: " + Format.formatStorage(map.fileSize(), false));
|
||||
|
||||
Counter.Readable readCount = Counter.newMultiThreadCounter();
|
||||
loggers = new ProgressLoggers("read")
|
||||
.addRateCounter("entries", readCount)
|
||||
.newLine()
|
||||
.addProcessStats();
|
||||
CountDownLatch latch = new CountDownLatch(readers);
|
||||
for (int i = 0; i < readers; i++) {
|
||||
int rnum = i;
|
||||
new Thread(() -> {
|
||||
latch.countDown();
|
||||
try {
|
||||
latch.await();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Random random = new Random(rnum);
|
||||
try {
|
||||
long sum = 0;
|
||||
long b = 0;
|
||||
while (b == 0) {
|
||||
readCount.inc();
|
||||
long key = 1L + (Math.abs(random.nextLong()) % entries);
|
||||
long value = map.get(key);
|
||||
assert key + 1 == value : key + " value was " + value;
|
||||
sum += value;
|
||||
}
|
||||
System.err.println(sum);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
latch.await();
|
||||
long start = System.nanoTime();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Thread.sleep(10000);
|
||||
loggers.log();
|
||||
}
|
||||
long end = System.nanoTime();
|
||||
long read = readCount.getAsLong();
|
||||
String readRate = Format.formatNumeric(read * NANOSECONDS_PER_SECOND / (end - start), false) + "/s";
|
||||
System.err.println("Read " + read + " in 30s (" + readRate + ")");
|
||||
System.err.println(
|
||||
String.join("\t",
|
||||
args[0],
|
||||
args[1],
|
||||
args[2],
|
||||
args[3],
|
||||
Format.formatStorage(ProcessInfo.getMaxMemoryBytes(), false),
|
||||
Format.formatStorage(map.fileSize(), false),
|
||||
Format.formatStorage(FileUtils.size(path), false),
|
||||
writeRate.get(),
|
||||
readRate
|
||||
)
|
||||
);
|
||||
Thread.sleep(100);
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
package com.onthegomap.flatmap.benchmarks;
|
||||
|
||||
import com.graphhopper.reader.ReaderElementUtils;
|
||||
import com.graphhopper.reader.ReaderNode;
|
||||
import com.graphhopper.reader.ReaderRelation;
|
||||
import com.graphhopper.reader.ReaderWay;
|
||||
import com.onthegomap.flatmap.Translations;
|
||||
import com.onthegomap.flatmap.config.Arguments;
|
||||
import com.onthegomap.flatmap.openmaptiles.OpenMapTilesProfile;
|
||||
import com.onthegomap.flatmap.reader.SourceFeature;
|
||||
import com.onthegomap.flatmap.reader.osm.OsmInputFile;
|
||||
import com.onthegomap.flatmap.stats.Stats;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
|
||||
public class OpenMapTilesMapping {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
var profile = new OpenMapTilesProfile(Translations.nullProvider(List.of()), Arguments.of(), Stats.inMemory());
|
||||
var random = new Random(0);
|
||||
var input = new OsmInputFile(Path.of("data", "sources", "north-america_us_massachusetts.pbf"));
|
||||
List<SourceFeature> inputs = new ArrayList<>();
|
||||
input.readTo(readerElem -> {
|
||||
if (random.nextDouble() < 0.2) {
|
||||
if (inputs.size() % 1_000_000 == 0) {
|
||||
System.err.println(inputs.size());
|
||||
}
|
||||
var props = ReaderElementUtils.getTags(readerElem);
|
||||
inputs.add(new SourceFeature(props, "", "", null, readerElem.getId()) {
|
||||
@Override
|
||||
public Geometry latLonGeometry() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Geometry worldGeometry() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPoint() {
|
||||
return readerElem instanceof ReaderNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBePolygon() {
|
||||
return readerElem instanceof ReaderWay || readerElem instanceof ReaderRelation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeLine() {
|
||||
return readerElem instanceof ReaderWay;
|
||||
}
|
||||
});
|
||||
}
|
||||
}, "reader", 3);
|
||||
|
||||
System.err.println("read " + inputs.size() + " elems");
|
||||
|
||||
long startStart = System.nanoTime();
|
||||
long count = -1;
|
||||
while (true) {
|
||||
count++;
|
||||
long start = System.nanoTime();
|
||||
int i = 0;
|
||||
for (SourceFeature in : inputs) {
|
||||
i += profile.getTableMatches(in).size();
|
||||
}
|
||||
if (count == 0) {
|
||||
startStart = System.nanoTime();
|
||||
System.err.println("finished warmup");
|
||||
} else {
|
||||
System.err.println(
|
||||
"took:" + Duration.ofNanos(System.nanoTime() - start).toMillis() + "ms found:" + i + " avg:" + (Duration
|
||||
.ofNanos(System.nanoTime() - startStart).toMillis() / count) + "ms");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,18 +1,11 @@
|
|||
package com.onthegomap.flatmap.collection;
|
||||
|
||||
import static io.prometheus.client.Collector.NANOSECONDS_PER_SECOND;
|
||||
|
||||
import com.carrotsearch.hppc.LongArrayList;
|
||||
import com.carrotsearch.hppc.LongLongHashMap;
|
||||
import com.graphhopper.coll.GHLongLongHashMap;
|
||||
import com.onthegomap.flatmap.stats.Counter;
|
||||
import com.onthegomap.flatmap.stats.ProcessInfo;
|
||||
import com.onthegomap.flatmap.stats.ProgressLoggers;
|
||||
import com.onthegomap.flatmap.stats.Stats;
|
||||
import com.onthegomap.flatmap.util.FileUtils;
|
||||
import com.onthegomap.flatmap.util.Format;
|
||||
import com.onthegomap.flatmap.util.MemoryEstimator;
|
||||
import com.onthegomap.flatmap.worker.Worker;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.DataOutputStream;
|
||||
|
@ -27,15 +20,11 @@ import java.sql.DriverManager;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.LongSupplier;
|
||||
import org.mapdb.Serializer;
|
||||
import org.mapdb.SortedTableMap;
|
||||
|
@ -48,109 +37,6 @@ import org.sqlite.SQLiteConfig;
|
|||
|
||||
public interface LongLongMap extends Closeable {
|
||||
|
||||
static void main(String[] args) throws IOException, InterruptedException {
|
||||
Path path = Path.of("./llmaptest");
|
||||
FileUtils.delete(path);
|
||||
LongLongMap map = switch (args[0]) {
|
||||
case "sparsemem2" -> new SparseArray2Memory();
|
||||
case "sparsearraymemory" -> new SparseArrayMemory();
|
||||
case "hppc" -> new HppcMap();
|
||||
case "array" -> new Array();
|
||||
|
||||
case "sparse2" -> new SparseArray2(path);
|
||||
case "sqlite" -> newSqlite(path);
|
||||
case "sparsearray" -> new SparseArray(path);
|
||||
case "mapdb" -> newFileBackedSortedTable(path);
|
||||
default -> throw new IllegalStateException("Unexpected value: " + args[0]);
|
||||
};
|
||||
long entries = Long.parseLong(args[1]);
|
||||
int readers = Integer.parseInt(args[2]);
|
||||
|
||||
class LocalCounter {
|
||||
|
||||
long count = 0;
|
||||
}
|
||||
LocalCounter counter = new LocalCounter();
|
||||
ProgressLoggers loggers = new ProgressLoggers("write")
|
||||
.addRatePercentCounter("entries", entries, () -> counter.count)
|
||||
.newLine()
|
||||
.addProcessStats();
|
||||
AtomicReference<String> writeRate = new AtomicReference<>();
|
||||
new Worker("writer", Stats.inMemory(), 1, () -> {
|
||||
long start = System.nanoTime();
|
||||
for (long i = 0; i < entries; i++) {
|
||||
map.put(i + 1L, i + 2L);
|
||||
counter.count = i;
|
||||
}
|
||||
long end = System.nanoTime();
|
||||
String rate = Format.formatNumeric(entries * NANOSECONDS_PER_SECOND / (end - start), false) + "/s";
|
||||
System.err.println("Loaded " + entries + " in " + Duration.ofNanos(end - start).toSeconds() + "s (" + rate + ")");
|
||||
writeRate.set(rate);
|
||||
}).awaitAndLog(loggers, Duration.ofSeconds(10));
|
||||
|
||||
map.get(1);
|
||||
System.err.println("Storage: " + Format.formatStorage(map.fileSize(), false));
|
||||
|
||||
Counter.Readable readCount = Counter.newMultiThreadCounter();
|
||||
loggers = new ProgressLoggers("read")
|
||||
.addRateCounter("entries", readCount)
|
||||
.newLine()
|
||||
.addProcessStats();
|
||||
CountDownLatch latch = new CountDownLatch(readers);
|
||||
for (int i = 0; i < readers; i++) {
|
||||
int rnum = i;
|
||||
new Thread(() -> {
|
||||
latch.countDown();
|
||||
try {
|
||||
latch.await();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Random random = new Random(rnum);
|
||||
try {
|
||||
long sum = 0;
|
||||
long b = 0;
|
||||
while (b == 0) {
|
||||
readCount.inc();
|
||||
long key = 1L + (Math.abs(random.nextLong()) % entries);
|
||||
long value = map.get(key);
|
||||
assert key + 1 == value : key + " value was " + value;
|
||||
sum += value;
|
||||
}
|
||||
System.err.println(sum);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
latch.await();
|
||||
long start = System.nanoTime();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Thread.sleep(10000);
|
||||
loggers.log();
|
||||
}
|
||||
long end = System.nanoTime();
|
||||
long read = readCount.getAsLong();
|
||||
String readRate = Format.formatNumeric(read * NANOSECONDS_PER_SECOND / (end - start), false) + "/s";
|
||||
System.err.println("Read " + read + " in 30s (" + readRate + ")");
|
||||
System.err.println(
|
||||
String.join("\t",
|
||||
args[0],
|
||||
args[1],
|
||||
args[2],
|
||||
args[3],
|
||||
Format.formatStorage(ProcessInfo.getMaxMemoryBytes(), false),
|
||||
Format.formatStorage(map.fileSize(), false),
|
||||
Format.formatStorage(FileUtils.size(path), false),
|
||||
writeRate.get(),
|
||||
readRate
|
||||
)
|
||||
);
|
||||
Thread.sleep(100);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
long MISSING_VALUE = Long.MIN_VALUE;
|
||||
|
||||
static LongLongMap newInMemorySparseArray2() {
|
||||
|
|
|
@ -189,7 +189,7 @@ public class OpenMapTilesProfile implements Profile {
|
|||
}
|
||||
}
|
||||
|
||||
List<MultiExpression.MultiExpressionIndex.MatchWithTriggers<Tables.Constructor>> getTableMatches(
|
||||
public List<MultiExpression.MultiExpressionIndex.MatchWithTriggers<Tables.Constructor>> getTableMatches(
|
||||
SourceFeature sourceFeature) {
|
||||
List<MultiExpression.MultiExpressionIndex.MatchWithTriggers<Tables.Constructor>> result = null;
|
||||
if (sourceFeature.isPoint()) {
|
||||
|
|
1
pom.xml
1
pom.xml
|
@ -42,6 +42,7 @@
|
|||
<module>flatmap-core</module>
|
||||
<module>flatmap-examples</module>
|
||||
<module>flatmap-openmaptiles</module>
|
||||
<module>flatmap-benchmarks</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
|
|
Ładowanie…
Reference in New Issue