Skip to content

Instantly share code, notes, and snippets.

@karussell
Last active September 15, 2021 14:10
Show Gist options
  • Save karussell/e0631198a8ef7d3506df17c25f8f3f63 to your computer and use it in GitHub Desktop.
Save karussell/e0631198a8ef7d3506df17c25f8f3f63 to your computer and use it in GitHub Desktop.
#FROM openjdk:11.0-jre
FROM openjdk:16-alpine3.13
COPY web/target/graphhopper*.jar ./graphhopper.jar
ENTRYPOINT [ "java -Xmx1g -Xms1g -jar graphhopper.jar", "10" ]
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Date;
import java.util.EnumSet;
import java.util.List;
public class Main {
public static void main(String[] args) throws Exception {
RandomAccessFile raFile = new RandomAccessFile("test.data", "rw");
System.out.println("START MMAP " + new Date());
int count = args.length > 0 ? Integer.parseInt(args[0]) : 1;
List<MappedByteBuffer> segments = new ArrayList<>();
long offset = 0;
int size = 1024 * 1024 * 1024;
for (int i = 0; i < count; i++) {
MappedByteBuffer buf = raFile.getChannel().map(FileChannel.MapMode.READ_WRITE, offset, size);
offset += size;
buf.position(0);
buf.putChar('A');
buf.position(size / 2);
buf.putChar('B');
buf.position(size - 100);
buf.putChar('C');
buf.force();
segments.add(buf);
System.out.println("loaded MMAP " + i + " " + new Date());
}
raFile.getFD().sync();
raFile.close();
System.out.println("END MMAP " + new Date() + " " + segments.size());
System.out.println("START' memory " + new Date());
List<byte[]> ints = new ArrayList<>();
for (int i = 0; i < count; i++) {
ints.add(new byte[size]);
System.out.println("loaded memory " + i + " " + new Date());
}
System.out.println("END memory " + new Date() + " " + ints.size());
}
}
sudo docker run --rm -it --memory 2g --memory-swap=0g --entrypoint /bin/sh test/test -c "java -Xmx2000m -Xms2000m -jar graphhopper.jar 50"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment