Created
October 23, 2018 11:19
-
-
Save apangin/b75bc5e52c38321cc1d264f2916cb591 to your computer and use it in GitHub Desktop.
GC off-heap overhead
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package map; | |
import java.io.PrintStream; | |
import java.util.Base64; | |
import java.util.concurrent.ThreadLocalRandom; | |
public class MapGenerator { | |
public static void main(String[] args) throws Exception { | |
try (PrintStream out = new PrintStream("in.txt")) { | |
for (int i = 0; i < 10_000_000; i++) { | |
int length = ThreadLocalRandom.current().nextInt(1, 9); | |
byte[] b = new byte[length]; | |
ThreadLocalRandom.current().nextBytes(b); | |
String key = Base64.getEncoder().encodeToString(b); | |
long value = ThreadLocalRandom.current().nextLong(1000000); | |
out.println(key + ": " + value); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package map; | |
import java.io.BufferedReader; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.util.HashMap; | |
import java.util.Map; | |
public class MapReader { | |
public static void main(String[] args) throws Exception { | |
while (true) { | |
long startTime = System.nanoTime(); | |
Map<String, Long> map = readMap("in.txt"); | |
long time = System.nanoTime() - startTime; | |
System.out.printf("Read %d elements in %.3f seconds\n", map.size(), time / 1e9); | |
} | |
} | |
private static Map<String, Long> readMap(String fileName) throws IOException { | |
Map<String, Long> map = new HashMap<>(); | |
try (BufferedReader br = new BufferedReader(new FileReader(fileName))) { | |
for (String line; (line = br.readLine()) != null; ) { | |
String[] parts = line.split(":"); | |
String key = parts[0].trim(); | |
String value = parts[1].trim(); | |
map.put(key, Long.parseLong(value)); | |
} | |
} | |
return map; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /usr/java/jdk-11.0.1/bin/java -XX:+UseG1GC -Xmx4g -Xms4g -Xlog:gc -XX:NativeMemoryTracking=summary map.MapReader | |
Native Memory Tracking: | |
Total: reserved=5787348KB, committed=4473360KB | |
- Java Heap (reserved=4194304KB, committed=4194304KB) | |
(mmap: reserved=4194304KB, committed=4194304KB) | |
- Class (reserved=1056905KB, committed=5769KB) | |
(classes #702) | |
( instance classes #608, array classes #94) | |
(malloc=137KB #910) | |
(mmap: reserved=1056768KB, committed=5632KB) | |
( Metadata: ) | |
( reserved=8192KB, committed=5120KB) | |
( used=4922KB) | |
( free=198KB) | |
( waste=0KB =0.00%) | |
( Class space:) | |
( reserved=1048576KB, committed=512KB) | |
( used=434KB) | |
( free=78KB) | |
( waste=0KB =0.00%) | |
- Thread (reserved=23698KB, committed=986KB) | |
(thread #23) | |
(stack: reserved=23592KB, committed=880KB) | |
(malloc=78KB #130) | |
(arena=28KB #44) | |
- Code (reserved=247753KB, committed=7613KB) | |
(malloc=65KB #633) | |
(mmap: reserved=247688KB, committed=7548KB) | |
- GC (reserved=258849KB, committed=258849KB) | |
(malloc=70157KB #168287) | |
(mmap: reserved=188692KB, committed=188692KB) | |
- Compiler (reserved=148KB, committed=148KB) | |
(malloc=18KB #64) | |
(arena=130KB #5) | |
- Internal (reserved=639KB, committed=639KB) | |
(malloc=599KB #1457) | |
(mmap: reserved=40KB, committed=40KB) | |
- Symbol (reserved=2028KB, committed=2028KB) | |
(malloc=1252KB #2752) | |
(arena=775KB #1) | |
- Native Memory Tracking (reserved=2758KB, committed=2758KB) | |
(malloc=7KB #91) | |
(tracking overhead=2751KB) | |
- Arena Chunk (reserved=186KB, committed=186KB) | |
(malloc=186KB) | |
- Logging (reserved=5KB, committed=5KB) | |
(malloc=5KB #184) | |
- Arguments (reserved=17KB, committed=17KB) | |
(malloc=17KB #469) | |
- Module (reserved=58KB, committed=58KB) | |
(malloc=58KB #1025) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /usr/java/jdk-11.0.1/bin/java -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -Xmx4g -Xms4g -Xlog:gc -XX:NativeMemoryTracking=summary map.MapReader | |
Native Memory Tracking: | |
Total: reserved=17180607344KB, committed=4630564KB | |
- Java Heap (reserved=17179869184KB, committed=4155392KB) | |
(mmap: reserved=17179869184KB, committed=4155392KB) | |
- Class (reserved=8327KB, committed=5767KB) | |
(classes #702) | |
( instance classes #608, array classes #94) | |
(malloc=135KB #915) | |
(mmap: reserved=8192KB, committed=5632KB) | |
( Metadata: ) | |
( reserved=8192KB, committed=5632KB) | |
( used=5400KB) | |
( free=232KB) | |
( waste=0KB =0.00%) | |
- Thread (reserved=21600KB, committed=1312KB) | |
(thread #21) | |
(stack: reserved=21544KB, committed=1256KB) | |
(malloc=30KB #118) | |
(arena=26KB #40) | |
- Code (reserved=247763KB, committed=7623KB) | |
(malloc=75KB #719) | |
(mmap: reserved=247688KB, committed=7548KB) | |
- GC (reserved=457497KB, committed=457497KB) | |
(malloc=441113KB #7152) | |
(mmap: reserved=16384KB, committed=16384KB) | |
- Compiler (reserved=148KB, committed=148KB) | |
(malloc=18KB #65) | |
(arena=130KB #5) | |
- Internal (reserved=293KB, committed=293KB) | |
(malloc=253KB #955) | |
(mmap: reserved=40KB, committed=40KB) | |
- Symbol (reserved=2028KB, committed=2028KB) | |
(malloc=1252KB #2756) | |
(arena=775KB #1) | |
- Native Memory Tracking (reserved=238KB, committed=238KB) | |
(malloc=10KB #144) | |
(tracking overhead=228KB) | |
- Arena Chunk (reserved=186KB, committed=186KB) | |
(malloc=186KB) | |
- Logging (reserved=5KB, committed=5KB) | |
(malloc=5KB #184) | |
- Arguments (reserved=17KB, committed=17KB) | |
(malloc=17KB #466) | |
- Module (reserved=58KB, committed=58KB) | |
(malloc=58KB #1025) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment