????Java ????????????????κ????????????????
????????????????????????????????????????????????????????????????????????????????????£???????1??????????
???????????????????
?????????
????????????????
???????????б???
?????????????β????
?????????????????????????????????????????Щ?????????????????????????????????????????????????????Garbage Collection Handbook?????????????????????????????????趨??????????????????????????????????????????????
//imports skipped for brevity
public class Producer implements Runnable {
private static ScheduledExecutorService executorService = Executors.newScheduledThreadPool(2);
private Deque<byte[]> deque;
private int objectSize;
private int queueSize;
public Producer(int objectSize?? int ttl) {
this.deque = new ArrayDeque<byte[]>();
this.objectSize = objectSize;
this.queueSize = ttl * 1000;
}
@Override
public void run() {
for (int i = 0; i < 100; i++) {
deque.add(new byte[objectSize]);
if (deque.size() > queueSize) {
deque.poll();
}
}
}
public static void main(String[] args) throws InterruptedException {
executorService.scheduleAtFixedRate(new Producer(200 * 1024 * 1024 / 1000?? 5)?? 0?? 100?? TimeUnit.MILLISECONDS);
executorService.scheduleAtFixedRate(new Producer(50 * 1024 * 1024 / 1000?? 120)?? 0?? 100?? TimeUnit.MILLISECONDS);
TimeUnit.MINUTES.sleep(10);
executorService.shutdownNow();
}
}
???????????????????????job??????? 100ms ??????Ρ??????????????????????????????????????????“???”???????????????????? GC ??????檔 ????????????????? GC ???????????2?????
????-XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps
?????????????????????п??? GC ????????????Щ?????
????2015-06-04T13:34:16.119-0200: 1.723: [GC (Allocation Failure) [PSYoungGen: 114016K->73191K(234496K)] 421540K->421269K(745984K)?? 0.0858176 secs] [Times: user=0.04 sys=0.06?? real=0.09 secs]
????2015-06-04T13:34:16.738-0200: 2.342: [GC (Allocation Failure) [PSYoungGen: 234462K->93677K(254976K)] 582540K->593275K(766464K)?? 0.2357086 secs] [Times: user=0.11 sys=0.14?? real=0.24 secs]
????2015-06-04T13:34:16.974-0200: 2.578: [Full GC (Ergonomics) [PSYoungGen: 93677K->70109K(254976K)] [ParOldGen: 499597K->511230K(761856K)] 593275K->581339K(1016832K)?? [Metaspace: 2936K->2936K(1056768K)]?? 0.0713174 secs] [Times: user=0.21 sys=0.02?? real=0.07 secs]
????????????е?????????????????????????????μ?????????????
??????? GC pause??????????????????????????????????????
?????????ó????????????????????????????
?????????????????????????????????????????????????????
??????????????????????????????10????????±??????????????????????
??????GC????Ч?????????
????-Xmx12g-XX:+UseConcMarkSweepGC89.8%560 ms
????-Xmx12g-XX:+UseParallelGC91.5%1??104 ms
????-Xmx8g-XX:+UseConcMarkSweepGC66.3%1??610 ms
????????У????ò???? GC ??????????С??????????????????????????????????????????????????????????????????????????????????С?????????е??Щ?????????Щ?????????????????????????????????????????
???????????????????????????????????????????????????????ж?????????????CPU core????????????в????