[d2]java 성능에 대한 오해와 편견

Post on 20-Jul-2015

18.500 Views

Category:

Technology

14 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Java 성능에 대한 오해와 편견

최영목

2015-05

1. Java는정말느린가?

2. 무엇때문에느린가?

3. 느리지않게하기

4. 다시 한번 질문하기 : Java는 정말느린가?

1. Java는 정말 느린가?

4

대외비

1. Java는 정말 느린가?

네, 느립니다.

5

대외비

1. Java는 정말 느린가?

출처 : http://benchmarksgame.alioth.debian.org/

x64����������� ������������������  Ubuntu™����������� ������������������   Intel®����������� ������������������  Q6600®����������� ������������������  quad-core

6

대외비

1. Java는 정말 느린가?

Java의 생각

7

대외비

1. Java는 정말 느린가?

이미지 출처 : http://www.yes24.com/24/goods/8262373?scode=032&OzSrank=1

8

대외비

1. Java는 정말 느린가?

좀 더 구체적으로…⋯

9

대외비

1. Java는 정말 느린가?

그러니까…⋯음…⋯

이미지 출처 : https://goo.gl/C3aIZx

10

대외비

1. Java는 정말 느린가?

Web����������� ������������������  Framework����������� ������������������  BenchmarksTechEmpower Round����������� ������������������  10

(2015-04-21)

11

대외비

1. Java는 정말 느린가?

HTTP/1.1����������� ������������������  200����������� ������������������  OK����������� ������������������  Content-Type:����������� ������������������   application/json;����������� ������������������   charset=UTF-8����������� ������������������  Content-Length:����������� ������������������   28����������� ������������������  Server:����������� ������������������  Example����������� ������������������  Date:����������� ������������������  Wed,����������� ������������������  17����������� ������������������  Apr����������� ������������������  2013����������� ������������������  12:00:00����������� ������������������   GMT����������� ������������������  

{"message":"Hello,����������� ������������������  World!"}

출처 : http://www.techempower.com/benchmarks/#section=data-r10&hw=peak&test=json

- Top����������� ������������������  10����������� ������������������  :����������� ������������������  JSON

12

대외비

1. Java는 정말 느린가?

HTTP/1.1����������� ������������������  200����������� ������������������  OK����������� ������������������  Content-Length:����������� ������������������   32����������� ������������������  Content-Type:����������� ������������������   application/json;����������� ������������������   charset=UTF-8����������� ������������������  Server:����������� ������������������  Example����������� ������������������  Date:����������� ������������������  Wed,����������� ������������������  17����������� ������������������  Apr����������� ������������������  2013����������� ������������������  12:00:00����������� ������������������   GMT����������� ������������������  

{"id":3217,"randomNumber":2149}

출처 : http://www.techempower.com/benchmarks/#section=data-r10&hw=peak&test=db

- Top����������� ������������������  10����������� ������������������  :����������� ������������������  Single����������� ������������������  Query

13

대외비

1. Java는 정말 느린가?

HTTP/1.1����������� ������������������  200����������� ������������������  OK����������� ������������������  Content-Length:����������� ������������������   315����������� ������������������  Content-Type:����������� ������������������   application/json;����������� ������������������   charset=UTF-8����������� ������������������  Server:����������� ������������������  Example����������� ������������������  Date:����������� ������������������  Wed,����������� ������������������  17����������� ������������������  Apr����������� ������������������  2013����������� ������������������  12:00:00����������� ������������������   GMT����������� ������������������  

[{"id":4174,"randomNumber":331},{"id":51,"randomNumber":6544},{"id":4462,"randomNumber":952},{"id":2221,"randomNumber":532},{"id":9276,"randomNumber":3097},{"id":3056,"randomNumber":7293},{"id":6964,"randomNumber":620},{"id":675,"randomNumber":6601},{"id":8414,"randomNumber":6569},{"id":2753,"randomNumber":4065}]

출처 : http://www.techempower.com/benchmarks/#section=data-r10&hw=peak&test=query

- Top����������� ������������������  10����������� ������������������  :����������� ������������������  Multiple����������� ������������������  Queries

14

대외비

1. Java는 정말 느린가?

HTTP/1.1����������� ������������������  200����������� ������������������  OK����������� ������������������  Content-Length:����������� ������������������   1196����������� ������������������  Content-Type:����������� ������������������   text/html;����������� ������������������   charset=UTF-8����������� ������������������  Server:����������� ������������������  Example����������� ������������������  Date:����������� ������������������  Wed,����������� ������������������  17����������� ������������������  Apr����������� ������������������  2013����������� ������������������  12:00:00����������� ������������������   GMT

<!DOCTYPE����������� ������������������  html><html>…⋯</html>

출처 : http://www.techempower.com/benchmarks/#section=data-r10&hw=peak&test=fortune

- Top����������� ������������������  10����������� ������������������  :����������� ������������������  Fortunes

15

대외비

1. Java는 정말 느린가?

HTTP/1.1����������� ������������������  200����������� ������������������  OK����������� ������������������  Content-Length:����������� ������������������   315����������� ������������������  Content-Type:����������� ������������������   application/json;����������� ������������������   charset=UTF-8����������� ������������������  Server:����������� ������������������  Example����������� ������������������  Date:����������� ������������������  Wed,����������� ������������������  17����������� ������������������  Apr����������� ������������������  2013����������� ������������������  12:00:00����������� ������������������   GMT����������� ������������������  

[{"id":4174,"randomNumber":331},{"id":51,"randomNumber":6544},{"id":4462,"randomNumber":952},{"id":2221,"randomNumber":532},{"id":9276,"randomNumber":3097},{"id":3056,"randomNumber":7293},{"id":6964,"randomNumber":620},{"id":675,"randomNumber":6601},{"id":8414,"randomNumber":6569},{"id":2753,"randomNumber":4065}]

출처 : http://www.techempower.com/benchmarks/#section=data-r10&hw=peak&test=update

- Top����������� ������������������  10����������� ������������������  :����������� ������������������  Data����������� ������������������  updates

16

대외비

1. Java는 정말 느린가?

HTTP/1.1����������� ������������������  200����������� ������������������  OK����������� ������������������  Content-Length:����������� ������������������   15����������� ������������������  Content-Type:����������� ������������������   text/plain;����������� ������������������   charset=UTF-8����������� ������������������  Server:����������� ������������������  Example����������� ������������������  Date:����������� ������������������  Wed,����������� ������������������  17����������� ������������������  Apr����������� ������������������  2013����������� ������������������  12:00:00����������� ������������������   GMT����������� ������������������  

Hello,����������� ������������������  World!

출처 : http://www.techempower.com/benchmarks/#section=data-r10&hw=peak&test=plaintext

- Top����������� ������������������  10����������� ������������������  :����������� ������������������  Plaintext

17

대외비

1. Java는 정말 느린가?

그래서 하고 싶은 말은?

18

대외비

1. Java는 정말 느린가?

Java가 native����������� ������������������  언어보다는느리지만 차이가 크지 않고,����������� ������������������  성능 문제도 극복 가능하다

2. 무엇 때문에 느린가?

20

대외비

2. 무엇 때문에 느린가?

GC(Garbage����������� ������������������  Collection)

GC

21

대외비

2. 무엇 때문에 느린가?

정말로 문제가 되는것은?(조금더 정확히표현해서…⋯)

GC

22

대외비

2. 무엇 때문에 느린가?

• 캐릭터명 : 얼음불꽃애니 JVM• 스킬 :

[패시브] Stop����������� ������������������  The����������� ������������������  World����������� ������������������  (STW)- GC를 실행하기위해 Java 세상을 얼려버림(조건발동)- 지속시간 : 랜덤

GC

이미지 출처 : http://qbguy.tistory.com/657

23

대외비

2. 무엇 때문에 느린가?

GC가 Java의 성능에영향을 주는 것은 사실이다.

GC

24

대외비

2. 무엇 때문에 느린가?

GC와 관련된 오해

GC

25

대외비

2. 무엇 때문에 느린가?

오해 1 :힙메모리는 2G이상 사용하면안된다?

GC

26

대외비

2. 무엇 때문에 느린가?

확인해보자

GC

27

대외비

2. 무엇 때문에 느린가?

Oracle

GC

28

대외비

2. 무엇 때문에 느린가?

GC가 오래 걸릴 경우OOM(OutOfMemoryError)����������� ������������������  발생

GC

29

대외비

2. 무엇 때문에 느린가?

CMS GC와 G1����������� ������������������  GC의 경우초기에 버그로 인해서GC가 오래 걸림

GC

30

대외비

2. 무엇 때문에 느린가?

4.����������� ������������������  Bug����������� ������������������  in����������� ������������������  the����������� ������������������  JVMSometimes����������� ������������������  these����������� ������������������  long����������� ������������������  pauses����������� ������������������  could����������� ������������������  be����������� ������������������  due����������� ������������������  to����������� ������������������  a����������� ������������������  bug����������� ������������������   in����������� ������������������  the����������� ������������������  JVM.����������� ������������������  For����������� ������������������  example,����������� ������������������  due����������� ������������������  to����������� ������������������  the����������� ������������������  following����������� ������������������   bugs����������� ������������������  in����������� ������������������  the����������� ������������������  JVM,����������� ������������������  Java����������� ������������������  applications����������� ������������������  may����������� ������������������  face����������� ������������������  long����������� ������������������  GC����������� ������������������  pauses.

• 6459113:����������� ������������������   CMS+ParNew:����������� ������������������  wildly����������� ������������������   different����������� ������������������  ParNew pause����������� ������������������  times����������� ������������������  depending����������� ������������������  on����������� ������������������  heap����������� ������������������  shape����������� ������������������  caused����������� ������������������  by����������� ������������������  allocation����������� ������������������   spread• fixed����������� ������������������  in����������� ������������������  JDK����������� ������������������  6u1����������� ������������������  and����������� ������������������  7

• 6572569:����������� ������������������   CMS:����������� ������������������  consistently����������� ������������������   skewed����������� ������������������  work����������� ������������������  distribution����������� ������������������   indicated����������� ������������������   in����������� ������������������  (long)����������� ������������������   re-mark����������� ������������������  pauses• fixed����������� ������������������  in����������� ������������������  JDK����������� ������������������  6u4����������� ������������������  and����������� ������������������  7

• 6631166:����������� ������������������   CMS:����������� ������������������  better����������� ������������������  heuristics����������� ������������������  when����������� ������������������  combatting����������� ������������������  fragmentation• fixed����������� ������������������  in����������� ������������������  JDK����������� ������������������  6u21����������� ������������������  and����������� ������������������  7

• 6999988:����������� ������������������   CMS:����������� ������������������  Increased����������� ������������������  fragmentation����������� ������������������   leading����������� ������������������  to����������� ������������������  promotion����������� ������������������   failure����������� ������������������  after����������� ������������������  CR#6631166����������� ������������������   got����������� ������������������  implemented• fixed����������� ������������������  in����������� ������������������  JDK����������� ������������������  6u25����������� ������������������  and����������� ������������������  7

• 6683623:����������� ������������������   G1:����������� ������������������  use����������� ������������������  logarithmic����������� ������������������   BOT����������� ������������������  code����������� ������������������  such����������� ������������������  as����������� ������������������  used����������� ������������������  by����������� ������������������  other����������� ������������������  collectors• fixed����������� ������������������  in����������� ������������������  JDK����������� ������������������  6u14����������� ������������������  and����������� ������������������  7

• 6976350:����������� ������������������   G1:����������� ������������������  deal����������� ������������������  with����������� ������������������  fragmentation����������� ������������������  while����������� ������������������  copying����������� ������������������   objects����������� ������������������  during����������� ������������������  GC• fixed����������� ������������������  in����������� ������������������  JDK����������� ������������������  8

If����������� ������������������  you����������� ������������������   are����������� ������������������  running����������� ������������������   with����������� ������������������  a����������� ������������������  JVM����������� ������������������  version����������� ������������������  affected����������� ������������������  with����������� ������������������  these����������� ������������������  bugs,����������� ������������������  please����������� ������������������  upgrade����������� ������������������  to����������� ������������������  the����������� ������������������  version����������� ������������������  where����������� ������������������  these����������� ������������������  bugs����������� ������������������  are����������� ������������������  fixed.

출처 : https://blogs.oracle.com/poonam/entry/troubleshooting_long_gc_pauses

- Troubleshooting����������� ������������������  Long����������� ������������������  GC����������� ������������������  Pauses

GC

31

대외비

2. 무엇 때문에 느린가?

심지어는 JVM����������� ������������������  크래시를 유발

GC

32

대외비

2. 무엇 때문에 느린가?

A����������� ������������������  flaw����������� ������������������  in����������� ������������������  the����������� ������������������  implementation����������� ������������������  of����������� ������������������  a����������� ������������������  card-marking����������� ������������������  performance����������� ������������������  optimization����������� ������������������  in����������� ������������������  the����������� ������������������  JVM����������� ������������������  can����������� ������������������  cause����������� ������������������  heap����������� ������������������  corruption����������� ������������������  under����������� ������������������  some����������� ������������������  circumstances.����������� ������������������  This����������� ������������������  issue����������� ������������������  affects����������� ������������������  the����������� ������������������  CMS����������� ������������������  garbage����������� ������������������  collector����������� ������������������  prior����������� ������������������  to����������� ������������������  6u18,����������� ������������������  and����������� ������������������  the����������� ������������������  CMS,����������� ������������������  G1����������� ������������������  and����������� ������������������  Parallel����������� ������������������  Garbage����������� ������������������  Collectors����������� ������������������  in����������� ������������������  6u18.����������� ������������������  The����������� ������������������  serial����������� ������������������  garbage����������� ������������������  collector����������� ������������������  is����������� ������������������  not����������� ������������������  affected.����������� ������������������  Applications����������� ������������������  most����������� ������������������  likely����������� ������������������  to����������� ������������������  be����������� ������������������  affected����������� ������������������  by����������� ������������������  this����������� ������������������  issue����������� ������������������  are����������� ������������������  those����������� ������������������  that����������� ������������������  allocate����������� ������������������  very����������� ������������������  large����������� ������������������  objects����������� ������������������  which����������� ������������������  would����������� ������������������  not����������� ������������������  normally����������� ������������������  fit����������� ������������������  in����������� ������������������  Eden,����������� ������������������  or����������� ������������������  those����������� ������������������  that����������� ������������������  make����������� ������������������  extensive����������� ������������������  use����������� ������������������  of����������� ������������������  JNI����������� ������������������  Critical����������� ������������������  Sections����������� ������������������  (JNI����������� ������������������  Get/Release*Critical).

JVM에서 카드 표시알고리즘의 성능을최적화하는 데 결함이있어 어떤 상황에서는힙영역에서 문제가발생할 수 있다.����������� ������������������  6u18����������� ������������������  이전 버전의 CMS����������� ������������������  GC에 영향을미치고,����������� ������������������  6u18에서는 CMS����������� ������������������  GC와 G1����������� ������������������  GC,����������� ������������������  Parallel����������� ������������������  GC에 영향을 미친다.����������� ������������������  Serial����������� ������������������  GC에는 영향이 없다.����������� ������������������  이 문제에 가장큰 영향을 받는 애플리케이션은Eden����������� ������������������  영역에맞지 않는 매우큰 객체를할당하거나 JNI����������� ������������������  크리티컬 섹션을 광범위하게사용하는애플리케이션이다.

출처 : http://bugs.java.com/view_bug.do?bug_id=6896647

- Changes����������� ������������������  in����������� ������������������  1.6.0_18����������� ������������������  (6u18)

GC

33

대외비

2. 무엇 때문에 느린가?

Parallel����������� ������������������  GC의 경우heap����������� ������������������  size가 크면 GC가 오래걸림

GC

34

대외비

2. 무엇 때문에 느린가?

따라서 적정선의heap����������� ������������������  size����������� ������������������  유지가 필요했음

GC

35

대외비

2. 무엇 때문에 느린가?

그리고…⋯

GC

36

대외비

2. 무엇 때문에 느린가?

Why����������� ������������������  can't����������� ������������������  I����������� ������������������  get����������� ������������������  a����������� ������������������  larger����������� ������������������  heap����������� ������������������  with����������� ������������������  the����������� ������������������  32-bit����������� ������������������  JVM?

The����������� ������������������  maximum����������� ������������������  theoretical����������� ������������������  heap����������� ������������������  limit����������� ������������������  for����������� ������������������  the����������� ������������������  32-bit����������� ������������������  JVM����������� ������������������  is����������� ������������������  4G.����������� ������������������  Due����������� ������������������  to����������� ������������������  various����������� ������������������  additional����������� ������������������  constraints����������� ������������������  such����������� ������������������  as����������� ������������������  available����������� ������������������  swap,����������� ������������������  kernel����������� ������������������  address����������� ������������������  space����������� ������������������  usage,����������� ������������������  memory����������� ������������������  fragmentation,����������� ������������������  and����������� ������������������  VM����������� ������������������  overhead,����������� ������������������  in����������� ������������������  practice����������� ������������������  the����������� ������������������  limit����������� ������������������  can����������� ������������������  be����������� ������������������  much����������� ������������������  lower.����������� ������������������  On����������� ������������������  most����������� ������������������  modern����������� ������������������  32-bit����������� ������������������  Windows����������� ������������������  systems����������� ������������������  the����������� ������������������  maximum����������� ������������������  heap����������� ������������������  size����������� ������������������  will����������� ������������������  range����������� ������������������  from����������� ������������������  1.4G����������� ������������������  to����������� ������������������  1.6G.����������� ������������������  On����������� ������������������  32-bit����������� ������������������  Solaris����������� ������������������  kernels����������� ������������������  the����������� ������������������  address����������� ������������������  space����������� ������������������  is����������� ������������������  limited����������� ������������������  to����������� ������������������  2G.����������� ������������������  On����������� ������������������  64-bit����������� ������������������  operating����������� ������������������  systems����������� ������������������  running����������� ������������������  the����������� ������������������  32-bit����������� ������������������  VM,����������� ������������������  the����������� ������������������  max����������� ������������������  heap����������� ������������������  size����������� ������������������  can����������� ������������������  be����������� ������������������  higher,����������� ������������������  approaching����������� ������������������  4G����������� ������������������  on����������� ������������������  many����������� ������������������  Solaris����������� ������������������  systems.

As����������� ������������������  of����������� ������������������  Java����������� ������������������  SE����������� ������������������  6,����������� ������������������  the����������� ������������������  Windows����������� ������������������  /3GB����������� ������������������  boot.ini feature����������� ������������������  is����������� ������������������  not����������� ������������������  supported.

If����������� ������������������  your����������� ������������������  application����������� ������������������  requires����������� ������������������  a����������� ������������������  very����������� ������������������  large����������� ������������������  heap����������� ������������������  you����������� ������������������  should����������� ������������������  use����������� ������������������  a����������� ������������������  64-bit����������� ������������������  VM����������� ������������������  on����������� ������������������  a����������� ������������������  version����������� ������������������  of����������� ������������������  the����������� ������������������  operating����������� ������������������  system����������� ������������������  that����������� ������������������  supports����������� ������������������  64-bit����������� ������������������  applications.����������� ������������������  See Java����������� ������������������  SE����������� ������������������  Supported����������� ������������������  System����������� ������������������  Configurations����������� ������������������  for����������� ������������������  details.

출처 : http://www.oracle.com/technetwork/java/hotspotfaq-138619.html#gc_heap_32bit

- Frequently����������� ������������������  Asked����������� ������������������  Questions����������� ������������������  About����������� ������������������  the����������� ������������������  Java����������� ������������������  HotSpot VM

GC

37

대외비

2. 무엇 때문에 느린가?

하지만 지금은…⋯

GC

38

대외비

2. 무엇 때문에 느린가?

Elasticsearch

GC

39

대외비

2. 무엇 때문에 느린가?

The����������� ������������������  32����������� ������������������  GB����������� ������������������  line����������� ������������������  is����������� ������������������  fairly����������� ������������������  important.����������� ������������������   So����������� ������������������  what����������� ������������������  do����������� ������������������  you����������� ������������������  do����������� ������������������  when����������� ������������������  your����������� ������������������  machine����������� ������������������  has����������� ������������������  a����������� ������������������  lot����������� ������������������  of����������� ������������������  memory?����������� ������������������  It����������� ������������������  is����������� ������������������  becoming����������� ������������������  increasingly����������� ������������������   common����������� ������������������  to����������� ������������������  see����������� ������������������  super-servers����������� ������������������  with����������� ������������������  300­–500����������� ������������������   GB����������� ������������������  of����������� ������������������  RAM.

First,����������� ������������������  we����������� ������������������  would����������� ������������������   recommend����������� ������������������  avoiding����������� ������������������   such����������� ������������������  large����������� ������������������  machines����������� ������������������  (see Hardware).

But����������� ������������������  if����������� ������������������  you����������� ������������������   already����������� ������������������  have����������� ������������������  the����������� ������������������  machines,����������� ������������������  you����������� ������������������  have����������� ������������������  two����������� ������������������  practical����������� ������������������  options:

• Are����������� ������������������  you����������� ������������������  doing����������� ������������������  mostly����������� ������������������  full-text����������� ������������������   search?����������� ������������������  Consider����������� ������������������   giving����������� ������������������  32����������� ������������������  GB����������� ������������������  to����������� ������������������  Elasticsearch and����������� ������������������  letting����������� ������������������   Luceneuse����������� ������������������  the����������� ������������������  rest����������� ������������������  of����������� ������������������  memory����������� ������������������  via����������� ������������������  the����������� ������������������  OS����������� ������������������  filesystem cache.All����������� ������������������  that����������� ������������������  memory����������� ������������������  will����������� ������������������  cache����������� ������������������  segments����������� ������������������  and����������� ������������������  lead����������� ������������������  to����������� ������������������  blisteringly����������� ������������������   fast����������� ������������������  full-text����������� ������������������  search.

• Are����������� ������������������  you����������� ������������������  doing����������� ������������������   a����������� ������������������  lot����������� ������������������  of����������� ������������������  sorting/aggregations?����������� ������������������   You’ll����������� ������������������  likely����������� ������������������  want����������� ������������������  that����������� ������������������  memory����������� ������������������  in����������� ������������������  the����������� ������������������  heap����������� ������������������  then.����������� ������������������  Instead����������� ������������������  of����������� ������������������  one����������� ������������������  node����������� ������������������  with����������� ������������������  32����������� ������������������  GB+����������� ������������������  of����������� ������������������  RAM,����������� ������������������  consider����������� ������������������  running����������� ������������������   two����������� ������������������  or����������� ������������������  more����������� ������������������  nodes����������� ������������������  on����������� ������������������  a����������� ������������������  single����������� ������������������  machine.Still����������� ������������������  adhere����������� ������������������  to����������� ������������������  the����������� ������������������  50%����������� ������������������  rule,����������� ������������������  though.����������� ������������������   So����������� ������������������  if����������� ������������������  your����������� ������������������  machine����������� ������������������  has����������� ������������������  128����������� ������������������  GB����������� ������������������  of����������� ������������������  RAM,����������� ������������������  run����������� ������������������  two����������� ������������������  nodes,����������� ������������������  each����������� ������������������  with����������� ������������������  32����������� ������������������  GB.����������� ������������������  This����������� ������������������  means����������� ������������������  64����������� ������������������  GB����������� ������������������  will����������� ������������������  be����������� ������������������  used����������� ������������������  for����������� ������������������  heaps,����������� ������������������  and����������� ������������������  64����������� ������������������  will����������� ������������������  be����������� ������������������  left����������� ������������������  over����������� ������������������  for����������� ������������������  Lucene.

If����������� ������������������  you����������� ������������������   choose����������� ������������������  this����������� ������������������  option,����������� ������������������   set cluster.routing.allocation.same_shard.host:����������� ������������������   true in����������� ������������������  your����������� ������������������   config.����������� ������������������   This����������� ������������������  will����������� ������������������  prevent����������� ������������������  a����������� ������������������  primary����������� ������������������  and����������� ������������������  a����������� ������������������  replica����������� ������������������  shard����������� ������������������  from����������� ������������������  colocating to����������� ������������������  the����������� ������������������  same����������� ������������������  physical����������� ������������������  machine����������� ������������������  (since����������� ������������������  this����������� ������������������  would����������� ������������������  remove����������� ������������������  the����������� ������������������  benefits����������� ������������������  of����������� ������������������  replica����������� ������������������  high����������� ������������������   availability).

출처 : https://www.elastic.co/guide/en/elasticsearch/guide/master/heap-sizing.html

- I����������� ������������������  Have����������� ������������������  a����������� ������������������  Machine����������� ������������������  with����������� ������������������  1����������� ������������������  TB����������� ������������������  RAM!

GC

40

대외비

2. 무엇 때문에 느린가?

64비트 운영체제 + 64비트 JVM이라면힙메모리를필요에 따라2G이상 사용할수 있다.

(CMS,����������� ������������������  G1)

확 인 됨

GC

41

대외비

2. 무엇 때문에 느린가?

단, 웹애플리케이션의경우 힙메모리를2G이상 할당하는경우는 드물고,

Elasticsearch나 HBase 같은솔루션들은 수십G를사용하기도한다.

확인 됨

GC

42

대외비

2. 무엇 때문에 느린가?

오해 2 :Full����������� ������������������  GC는 보통 수 초 걸린다?

GC

43

대외비

2. 무엇 때문에 느린가?

의문점

GC

44

대외비

2. 무엇 때문에 느린가?

그런데말입니다. Java에서GC는 피할수없는부분이고, Full����������� ������������������  GC가 수초씩걸린다면그때마다응답지연이나실패가일어날텐데어떻게상용서비스에서사용할수 있을까요?

Java를잘모르는1인

GC

이미지 출처 :����������� ������������������  http://program.sbs.co.kr/builder/endPage.do?pgm_id=00000010101&pgm_mnu_id=4021&pgm_build_id=&contNo=&srs_id=22000049883

45

대외비

2. 무엇 때문에 느린가?

확인해보자

GC

46

대외비

2. 무엇 때문에 느린가?

NAVER(CMS GC)

GC

47

대외비

2. 무엇 때문에 느린가?GC

(����������� ������������������  https://github.com/naver/pinpoint )

48

대외비

2. 무엇 때문에 느린가?GC

49

대외비

2. 무엇 때문에 느린가?

Pinpoint����������� ������������������  :����������� ������������������  24G����������� ������������������  Heap(HBase),����������� ������������������  CMS0.1초 이내

nLocation :����������� ������������������  최대 56G����������� ������������������  Heap,����������� ������������������  CMS1초 이내 (대체로 0.5초 이내)

GC

50

대외비

2. 무엇 때문에 느린가?

Intel����������� ������������������  사례(G1����������� ������������������  GC,����������� ������������������  HBase)

GC

51

대외비

2. 무엇 때문에 느린가?

구분 상세

CPU Intel®����������� ������������������  Xeon®����������� ������������������  Ivy-bridge����������� ������������������  EP����������� ������������������  processors����������� ������������������  with����������� ������������������  Hyper-threading����������� ������������������  (40����������� ������������������  logical����������� ������������������  processors)

RAM 256����������� ������������������  GB����������� ������������������  DDR3-1600����������� ������������������  RAM

Storage three����������� ������������������  400GB����������� ������������������  SSDs����������� ������������������  as����������� ������������������  local����������� ������������������  storage

JVM����������� ������������������  Option -XX:+UseG1GC����������� ������������������  -Xms100g -Xmx100g-XX:MaxGCPauseMillis=100

목표 응답시간 100����������� ������������������  milliseconds

- 서버환경

출처 : https://software.intel.com/en-us/blogs/2014/06/18/part-1-tuning-java-garbage-collection-for-hbase

GC

52

대외비

2. 무엇 때문에 느린가?

- 개선전

출처 : https://software.intel.com/en-us/blogs/2014/06/18/part-1-tuning-java-garbage-collection-for-hbase

GC

53

대외비

2. 무엇 때문에 느린가?

- 개선전

출처 : https://software.intel.com/en-us/blogs/2014/06/18/part-1-tuning-java-garbage-collection-for-hbase

GC

54

대외비

2. 무엇 때문에 느린가?

- 개선후 (JDK����������� ������������������  버전 변경)

출처 : https://software.intel.com/en-us/blogs/2014/06/18/part-1-tuning-java-garbage-collection-for-hbase

GC

55

대외비

2. 무엇 때문에 느린가?

- 개선후 (JDK����������� ������������������  버전 변경)

출처 : https://software.intel.com/en-us/blogs/2014/06/18/part-1-tuning-java-garbage-collection-for-hbase

GC

56

대외비

2. 무엇 때문에 느린가?

- 개선후 (GC����������� ������������������  튜닝)

출처 : https://software.intel.com/en-us/blogs/2014/06/18/part-1-tuning-java-garbage-collection-for-hbase

GC

57

대외비

2. 무엇 때문에 느린가?

- 개선후 (GC����������� ������������������  튜닝)

출처 : https://software.intel.com/en-us/blogs/2014/06/18/part-1-tuning-java-garbage-collection-for-hbase

GC

58

대외비

2. 무엇 때문에 느린가?

수십 G의 힙 메모리라도튜닝을 잘해서

Full����������� ������������������  GC를 1초 이내로운영한 사례가 있다.

확인 됨

GC

59

대외비

2. 무엇 때문에 느린가?

IO

IO

60

대외비

2. 무엇 때문에 느린가?

Java의 IO는 왜 느릴까?

IO

61

대외비

2. 무엇 때문에 느린가?

장까지살아서일렬로하나씩…⋯

IO

이미지 출처 : http://blog.naver.com/binna77/20071585806

62

대외비

2. 무엇 때문에 느린가?

출처 : https://blogs.oracle.com/slc/entry/javanio_vs_javaio

IO

63

대외비

2. 무엇 때문에 느린가?

Description

Included����������� ������������������   are����������� ������������������  two����������� ������������������  similar����������� ������������������  programs����������� ������������������  in����������� ������������������  C����������� ������������������  and����������� ������������������  Java����������� ������������������  (/usr/green3/local.java/NIGHTLY1/jdk1.1/solaris/JDK1.1M-5).����������� ������������������  

The����������� ������������������  java����������� ������������������  version����������� ������������������  takes����������� ������������������  443����������� ������������������   times����������� ������������������  longer����������� ������������������   to����������� ������������������  run����������� ������������������  (far����������� ������������������  more����������� ������������������  than����������� ������������������  most����������� ������������������  comparisons)����������� ������������������  

The����������� ������������������  output����������� ������������������   of����������� ������������������  the����������� ������������������  two����������� ������������������  are:����������� ������������������  

ccodeccount =����������� ������������������  19990����������� ������������������   took����������� ������������������  210 milliseconds����������� ������������������  

java����������� ������������������  jcode java����������� ������������������  count����������� ������������������  =����������� ������������������  19990����������� ������������������   took����������� ������������������  93225 milliseconds

출처 : http://bugs.java.com/view_bug.do?bug_id=4015161

- JDK-4015161����������� ������������������  :����������� ������������������  java.io.*Input*����������� ������������������  is����������� ������������������  too����������� ������������������  slow

IO

64

대외비

2. 무엇 때문에 느린가?

Comments

EVALUATION

In����������� ������������������  Merlin����������� ������������������  (jdk1.4)����������� ������������������   JSR-51����������� ������������������  introduced����������� ������������������   the����������� ������������������  java.nio and����������� ������������������  java.nio.channels packages.����������� ������������������  These����������� ������������������  add����������� ������������������  new����������� ������������������  APIs����������� ������������������  for����������� ������������������  scaleable I/O.����������� ������������������  In����������� ������������������  particular,����������� ������������������  if����������� ������������������  the����������� ������������������  example����������� ������������������  were����������� ������������������  to����������� ������������������  be����������� ������������������  re-written����������� ������������������  using����������� ������������������  a����������� ������������������  FileChannel and����������� ������������������  a����������� ������������������  direct����������� ������������������  byte����������� ������������������  buffer����������� ������������������  of����������� ������������������  reasonable����������� ������������������  size,����������� ������������������  you����������� ������������������  will����������� ������������������  see����������� ������������������  substantial����������� ������������������   performance����������� ������������������  improvements.����������� ������������������  Using����������� ������������������   these����������� ������������������  APIs,����������� ������������������  you����������� ������������������  can����������� ������������������  approach����������� ������������������  native����������� ������������������  performance����������� ������������������  more����������� ������������������  easily.����������� ������������������  

That����������� ������������������  being����������� ������������������  said,����������� ������������������  the����������� ������������������  test����������� ������������������  provided����������� ������������������  would����������� ������������������   require����������� ������������������  some����������� ������������������  work����������� ������������������  to����������� ������������������  be����������� ������������������  usable����������� ������������������  as����������� ������������������  a����������� ������������������  true����������� ������������������  benchmark����������� ������������������  of����������� ������������������  steady-state����������� ������������������  Java����������� ������������������  performance����������� ������������������  for����������� ������������������  file����������� ������������������  reads.����������� ������������������  Many����������� ������������������  benchmarks,����������� ������������������  including����������� ������������������   the����������� ������������������  one����������� ������������������  provided����������� ������������������   fall����������� ������������������  into����������� ������������������   the����������� ������������������  category����������� ������������������  of����������� ������������������  "microbenchmarks".����������� ������������������   Benchmarks����������� ������������������  need����������� ������������������  to����������� ������������������  be����������� ������������������  written����������� ������������������  very����������� ������������������  carefully����������� ������������������  in����������� ������������������  order����������� ������������������  to����������� ������������������  avoid����������� ������������������  measuring����������� ������������������  JDK����������� ������������������  start-up����������� ������������������  time,����������� ������������������  VM����������� ������������������  byte-code����������� ������������������  compilation,����������� ������������������   garbage����������� ������������������  collection,����������� ������������������   code����������� ������������������  run����������� ������������������  in����������� ������������������  interpreted����������� ������������������  mode����������� ������������������  before����������� ������������������  compilation,����������� ������������������   etc.����������� ������������������  There����������� ������������������  are����������� ������������������  several����������� ������������������  sources����������� ������������������  on����������� ������������������  the����������� ������������������  web����������� ������������������  which����������� ������������������  discuss����������� ������������������  the����������� ������������������  pitfalls����������� ������������������  of����������� ������������������  microbenchmarks and����������� ������������������  provide����������� ������������������  tips����������� ������������������  on����������� ������������������  how����������� ������������������  to����������� ������������������  write����������� ������������������  them����������� ������������������  correctly.����������� ������������������  

Closing����������� ������������������   this����������� ������������������  bug����������� ������������������   as����������� ������������������  a����������� ������������������  duplicate����������� ������������������   of����������� ������������������  4313882����������� ������������������   which����������� ������������������  covered����������� ������������������  the����������� ������������������  relevant����������� ������������������  portions����������� ������������������   of����������� ������������������  JSR-51.

2006-05-25

출처 : http://bugs.java.com/view_bug.do?bug_id=4015161

- JDK-4015161����������� ������������������  :����������� ������������������  java.io.*Input*����������� ������������������  is����������� ������������������  too����������� ������������������  slow

IO

65

대외비

2. 무엇 때문에 느린가?

byte����������� ������������������  by����������� ������������������  byte����������� ������������������  (or����������� ������������������  char����������� ������������������  by����������� ������������������  char)

IO

66

대외비

2. 무엇 때문에 느린가?

Java����������� ������������������  초기 구현체의 문제

IO

67

대외비

2. 무엇 때문에 느린가?

오해 :NIO가 나오기 전의 Java����������� ������������������  IO 성능은

개선하기 힘들다?

IO

68

대외비

2. 무엇 때문에 느린가?

확인해보자

IO

69

대외비

2. 무엇 때문에 느린가?IO

출처 : http://www.javaworld.com/article/2076241/build-ci-sdlc/tweak-your-io-performance-for-faster-runtime.html

Sun����������� ������������������  1.1.7 IBM����������� ������������������  1.1.8 Sun����������� ������������������  1.2.2 Sun����������� ������������������  1.3 IBM����������� ������������������  1.3

RawBytes 20.6 18.0 26.1 20.70 62.70

RawChars 100.0 235.0 174.0 438.00 148.00

BufferedIS 9.2 1.8 8.6 2.28 2.65

BufferedR 16.7 2.4 10.0 2.84 3.10

SelfBufferedIS 2.1 0.4 2.0 0.61 0.53

SelfBufferedR 8.2 0.9 2.7 1.12 1.17

- Runtimes����������� ������������������  of����������� ������������������  six����������� ������������������  programs����������� ������������������  using����������� ������������������  common����������� ������������������  Linux����������� ������������������  VMs

70

대외비

2. 무엇 때문에 느린가?

버퍼를 쓰지 않으면아주 느린 것은 사실이다.

하지만 버퍼를 활용함으써성능 향상을 기대할 수 있다.

IO

확 인 됨

71

대외비

2. 무엇 때문에 느린가?

DB����������� ������������������  Connection

DB

72

대외비

2. 무엇 때문에 느린가?

연결에는 비용이 발생한다.(Java만의문제는아님)

DB

3. 느리지 않게 하기

74

대외비

3. 느리지 않게 하기

GC (JVM����������� ������������������  최적화)

GC

75

대외비

3. 느리지 않게 하기

GC����������� ������������������  튜닝을 반드시 해야할까?

GC

76

대외비

3. 느리지 않게 하기

NO

GC

77

대외비

3. 느리지 않게 하기

언제 해야 하나?

GC

78

대외비

3. 느리지 않게 하기

JVM의 메모리크기를지정하지않았을때

Timeout이지속적으로발생할때

GC

79

대외비

3. 느리지 않게 하기

명심하세요

GC튜닝은 가장 마지막에하는 작업입니다

GC

80

대외비

3. 느리지 않게 하기

GC 튜닝의 목표

GC

81

대외비

3. 느리지 않게 하기

분노의 JVM����������� ������������������  :����������� ������������������  더세븐

역시 GC는튜닝해야제맛!

Full����������� ������������������  GC 따위 0.1초 내에돌파해주겠어!!!

Old����������� ������������������  영역탑승가능 : 1

GC

이미지 출처 : http://pann.news.nate.com/info/326455895

82

대외비

3. 느리지 않게 하기

Old����������� ������������������  영역객체수최소화

Full����������� ������������������  GC����������� ������������������  시간줄이기

GC

83

대외비

3. 느리지 않게 하기

GC의 성능을 결정하는 옵션

GC

84

대외비

3. 느리지 않게 하기

구분 옵션 설명

힙(heap)영역 크기-Xms JVM����������� ������������������  시작시 힙 영역크기

-Xmx 최대 힙 영역크기

New����������� ������������������  영역의 크기

-XX:NewRatio New영역과 Old����������� ������������������  영역의 비율

-XX:NewSize New영역의 크기

-XX:SurvivorRatio Eden����������� ������������������  영역과 Survivor����������� ������������������  영역의 비율

- 메모리크기와 관련된GC 옵션

GC

85

대외비

3. 느리지 않게 하기

구분 옵션 설명

Serial����������� ������������������  GC -XX:+UseSerialGC

Parallel����������� ������������������  GC-XX:+UseParallelGC-XX:ParallelGCThreads=value

Parallel����������� ������������������  Compacting����������� ������������������  GC -XX:+UseParallelOldGC

CMS����������� ������������������  GC

-XX:+UseConcMarkSweepGC-XX:+UseParNewGC-XX:+CMSParallelRemarkEnabled-XX:CMSInitiatingOccupancyFraction=value-XX:+UseCMSInitiatingOccupancyOnly

G1-XX:+UnlockExperimentalVMOptions-XX:+UseG1GC

JDK����������� ������������������  6에서는두 옵션을반드시 같이사용해야 함

- GC����������� ������������������  방식에 따라지정 가능한 옵션

GC

86

대외비

3. 느리지 않게 하기

GC의 튜닝 절차

GC

87

대외비

3. 느리지 않게 하기

GC����������� ������������������  모니터링

GC����������� ������������������  튜닝여부 결정

GC����������� ������������������  방식 / 메모리 크기지정

결과 분석

반영 및 종료

GC

88

대외비

3. 느리지 않게 하기

GC����������� ������������������  모니터링

GC����������� ������������������  튜닝여부 결정

GC����������� ������������������  방식 / 메모리 크기지정

결과 분석

반영 및 종료

GC

• JStat명령어로 확인하자1. YGC(Young����������� ������������������  Generation의GC����������� ������������������  이벤

트 발생 횟수)와 YGCT(Young����������� ������������������  Generation의GC����������� ������������������  수행 누적 시간)����������� ������������������  ����������� ������������������  값을 확인한다.Minor����������� ������������������  GC����������� ������������������  평균값=����������� ������������������  YGCT����������� ������������������  /����������� ������������������  YGC

2. FGC(Full����������� ������������������  GC����������� ������������������  이벤트가 발생한횟수)와 GFCT(Full����������� ������������������  GC����������� ������������������  수행 누적시간)����������� ������������������  값을 확인한다.Full����������� ������������������  GC����������� ������������������  평균값 =����������� ������������������  FGCT����������� ������������������  /����������� ������������������  FGC

• -verbosegc옵션으로로그를남겨 분석하자

89

대외비

3. 느리지 않게 하기

GC����������� ������������������  모니터링

GC����������� ������������������  튜닝여부 결정

GC����������� ������������������  방식 / 메모리 크기지정

결과 분석

반영 및 종료

GC

• 해당 시스템이가져야 할 목표와비교하자(예시)

1. Minor����������� ������������������  GC의 처리시간 (50ms����������� ������������������  내외)

2. Minor����������� ������������������  GC����������� ������������������  주기 (10초 내외)

3. Full����������� ������������������  GC의 처리시간 (1초이내)

4. Full����������� ������������������  GC����������� ������������������  주기 (10분에 1회)

90

대외비

3. 느리지 않게 하기

GC����������� ������������������  모니터링

GC����������� ������������������  튜닝여부 결정

GC����������� ������������������  방식 / 메모리 크기지정

결과 분석

반영 및 종료

GC

1. GC����������� ������������������  방식• Serial����������� ������������������  GC• Parallel����������� ������������������  GC• Parallel����������� ������������������  Old����������� ������������������  GC(Parallel����������� ������������������   Compacting����������� ������������������  GC)����������� ������������������  • Concurrent����������� ������������������  Mark����������� ������������������  &����������� ������������������  Sweep����������� ������������������  GC(이하 CMS)• G1(Garbage����������� ������������������  First)����������� ������������������  GC����������� ������������������  ­– JDK����������� ������������������  7����������� ������������������  이상

2. 메모리 크기• 메모리가 크면

• GC����������� ������������������  발생 횟수 감소• GC����������� ������������������  수행 시간 증가

• 메모리가 작으면• GC����������� ������������������  발생 횟수 증가• GC����������� ������������������  수행 시간 감소

• NewRatio(New����������� ������������������  영역과 Old����������� ������������������  영역의 비율)을 잘조정하자

• Oracle에서제공하는 ‘Garbage����������� ������������������  Collection����������� ������������������  Tuning����������� ������������������  Guide’도 참고하자

참고 : http://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/index.html

91

대외비

3. 느리지 않게 하기

GC����������� ������������������  모니터링

GC����������� ������������������  튜닝여부 결정

GC����������� ������������������  방식 / 메모리 크기지정

결과 분석

반영 및 종료

GC

• 다음과 같은사항을 확인하자

1. GC����������� ������������������  수행시간• 특히 Full����������� ������������������  GC����������� ������������������  수행 시간

2. GC����������� ������������������  수행간격

3. GC����������� ������������������  수행횟수

• 위 사항을 바탕으로목표를 달성하였는지확인한다

92

대외비

3. 느리지 않게 하기

GC����������� ������������������  모니터링

GC����������� ������������������  튜닝여부 결정

GC����������� ������������������  방식 / 메모리 크기지정

결과 분석

반영 및 종료

GC

• 결과에 만족한다면해당 시스템의전체 서버에 적용한다

• JVM����������� ������������������  Bug,����������� ������������������  잘못된 JVM����������� ������������������  옵션으로인하여OutOfMemoryError와같은 이상 현상이발생할 수 있으므로,����������� ������������������  지속적인모니터링을한다

93

대외비

3. 느리지 않게 하기

IO

IO

94

대외비

3. 느리지 않게 하기

IO

NIO����������� ������������������  (J2SE����������� ������������������  1.4,����������� ������������������  JSR����������� ������������������  51)

NIO2����������� ������������������  (Java����������� ������������������  SE����������� ������������������  7,����������� ������������������  JSR����������� ������������������  203)

IO

95

대외비

3. 느리지 않게 하기

- File����������� ������������������  Copy����������� ������������������  Benchmark

출처 : http://baptiste-wicht.com/posts/2010/08/file-copy-in-java-benchmark.html

구분 내용

OS Ubuntu����������� ������������������  10.04����������� ������������������  64����������� ������������������  bits

CPU Intel����������� ������������������  Core����������� ������������������  2����������� ������������������  Duo����������� ������������������  3.16����������� ������������������  GHz

RAM 6����������� ������������������  Go����������� ������������������  DDR2

HDD SATA����������� ������������������  Hard����������� ������������������  Disks

JVM Java����������� ������������������  7����������� ������������������  64����������� ������������������  bits����������� ������������������  Virtual����������� ������������������  Machine

1. Little����������� ������������������  file����������� ������������������  (5����������� ������������������  KB)2. Medium����������� ������������������  file����������� ������������������  (50����������� ������������������  KB)3. Big����������� ������������������  file����������� ������������������  (5����������� ������������������  MB)4. Fat����������� ������������������  file����������� ������������������  (50����������� ������������������  MB)5. And����������� ������������������  an����������� ������������������  enormous����������� ������������������  file����������� ������������������  (1.3����������� ������������������  GB)����������� ������������������  only����������� ������������������  binary

IO

96

대외비

3. 느리지 않게 하기

- File����������� ������������������  Copy����������� ������������������  Benchmark

1. Native����������� ������������������  Copy :����������� ������������������  Make����������� ������������������  the����������� ������������������  copy����������� ������������������  using����������� ������������������  the����������� ������������������  cp executable����������� ������������������  of����������� ������������������  Linux2. Naive����������� ������������������  Streams����������� ������������������  Copy :����������� ������������������  Open����������� ������������������  two����������� ������������������  streams,����������� ������������������  one����������� ������������������  to����������� ������������������  read,����������� ������������������  one����������� ������������������  to����������� ������������������  write����������� ������������������  and����������� ������������������  transfer����������� ������������������   the����������� ������������������  co

ntent����������� ������������������  byte����������� ������������������  by����������� ������������������  byte.3. Naive����������� ������������������  Readers����������� ������������������  Copy :����������� ������������������  Open����������� ������������������  two����������� ������������������  readers,����������� ������������������  one����������� ������������������  to����������� ������������������  read,����������� ������������������  one����������� ������������������  to����������� ������������������  write����������� ������������������  and����������� ������������������  transfer����������� ������������������   the����������� ������������������  con

tent����������� ������������������  character����������� ������������������  by����������� ������������������  character.4. Buffered����������� ������������������  Streams����������� ������������������  Copy :����������� ������������������  Same����������� ������������������  as����������� ������������������  the����������� ������������������  first����������� ������������������  but����������� ������������������  using����������� ������������������  buffered����������� ������������������  streams����������� ������������������   instead����������� ������������������  of����������� ������������������  simple����������� ������������������  

streams.5. Buffered����������� ������������������  Readers����������� ������������������  Copy :����������� ������������������  Same����������� ������������������  as����������� ������������������  the����������� ������������������  second����������� ������������������  but����������� ������������������  using����������� ������������������  buffered����������� ������������������   readers����������� ������������������   instead����������� ������������������  of����������� ������������������  sim

ple����������� ������������������  readers.6. Custom����������� ������������������  Buffer����������� ������������������  Stream����������� ������������������  Copy :����������� ������������������  Same����������� ������������������  as����������� ������������������  the����������� ������������������  first����������� ������������������  but����������� ������������������  reading����������� ������������������  the����������� ������������������  file����������� ������������������  not����������� ������������������  byte����������� ������������������  by����������� ������������������  byte����������� ������������������  but����������� ������������������  

using����������� ������������������  a����������� ������������������  simple����������� ������������������  byte����������� ������������������  array����������� ������������������  as����������� ������������������  buffer.7. Custom����������� ������������������  Buffer����������� ������������������  Reader����������� ������������������  Copy :����������� ������������������  Same����������� ������������������  as����������� ������������������  the����������� ������������������  fifth����������� ������������������  but����������� ������������������  using����������� ������������������  a����������� ������������������  Reader����������� ������������������  instead����������� ������������������  of����������� ������������������  a����������� ������������������  stream.8. Custom����������� ������������������  Buffer����������� ������������������  Buffered����������� ������������������   Stream����������� ������������������  Copy :����������� ������������������  Same����������� ������������������  as����������� ������������������  the����������� ������������������  fifth����������� ������������������  but����������� ������������������  using����������� ������������������  buffered����������� ������������������   streams.9. Custom����������� ������������������  Buffer����������� ������������������  Buffered����������� ������������������   Reader����������� ������������������  Copy :����������� ������������������  Same����������� ������������������  as����������� ������������������  the����������� ������������������  sixth����������� ������������������  but����������� ������������������  using����������� ������������������  buffered����������� ������������������   readers.10. NIO����������� ������������������  Buffer����������� ������������������  Copy :����������� ������������������  Using����������� ������������������  NIO����������� ������������������  Channel����������� ������������������  and����������� ������������������  using����������� ������������������  a����������� ������������������  ByteBuffer to����������� ������������������  make����������� ������������������  the����������� ������������������  transfer.11. NIO����������� ������������������  Transfer����������� ������������������  Copy :����������� ������������������  Using����������� ������������������  NIO����������� ������������������  Channel����������� ������������������  and����������� ������������������  direct����������� ������������������   transfer����������� ������������������   from����������� ������������������  one����������� ������������������  channel����������� ������������������  to����������� ������������������  other.12. Path����������� ������������������  (Java����������� ������������������  7)����������� ������������������  Copy :����������� ������������������  Using����������� ������������������  the����������� ������������������  Path����������� ������������������  class����������� ������������������  of����������� ������������������  Java����������� ������������������  7����������� ������������������  and����������� ������������������  its����������� ������������������  method����������� ������������������  copyTo()

출처 : http://baptiste-wicht.com/posts/2010/08/file-copy-in-java-benchmark.html

IO

97

대외비

3. 느리지 않게 하기

- File����������� ������������������  Copy����������� ������������������  Benchmark

출처 : http://baptiste-wicht.com/posts/2010/08/file-copy-in-java-benchmark.html

IO

98

대외비

3. 느리지 않게 하기

- File����������� ������������������  Copy����������� ������������������  Benchmark

출처 : http://baptiste-wicht.com/posts/2010/08/file-copy-in-java-benchmark.html

IO

99

대외비

3. 느리지 않게 하기

- File����������� ������������������  Copy����������� ������������������  Benchmark

출처 : http://baptiste-wicht.com/posts/2010/08/file-copy-in-java-benchmark.html

IO

100

대외비

3. 느리지 않게 하기

- File����������� ������������������  Copy����������� ������������������  Benchmark

출처 : http://baptiste-wicht.com/posts/2010/08/file-copy-in-java-benchmark.html

IO

101

대외비

3. 느리지 않게 하기

- File����������� ������������������  Copy����������� ������������������  Benchmark

출처 : http://baptiste-wicht.com/posts/2010/08/file-copy-in-java-benchmark.html

IO

102

대외비

3. 느리지 않게 하기

- File����������� ������������������  Copy����������� ������������������  Benchmark

출처 : http://baptiste-wicht.com/posts/2010/08/file-copy-in-java-benchmark.html

IO

103

대외비

3. 느리지 않게 하기

- File����������� ������������������  Copy����������� ������������������  Benchmark : Conclusion

1. Never����������� ������������������  made����������� ������������������  a����������� ������������������  copy����������� ������������������  of����������� ������������������  file����������� ������������������  byte����������� ������������������  by����������� ������������������  byte����������� ������������������  (or����������� ������������������  char����������� ������������������  by����������� ������������������  char)

2. Prefer����������� ������������������  a����������� ������������������  buffer����������� ������������������  in����������� ������������������  your����������� ������������������  side����������� ������������������  more����������� ������������������  than����������� ������������������  in����������� ������������������  the����������� ������������������  stream����������� ������������������  to����������� ������������������  make����������� ������������������  less����������� ������������������  invocations����������� ������������������  of����������� ������������������  the����������� ������������������  read����������� ������������������  method,����������� ������������������  but����������� ������������������  don't����������� ������������������  forget����������� ������������������  the����������� ������������������  buffer����������� ������������������  in����������� ������������������  the����������� ������������������  side����������� ������������������  of����������� ������������������  the����������� ������������������  streams

3. Pay����������� ������������������  attention����������� ������������������  to����������� ������������������  the����������� ������������������  size����������� ������������������  of����������� ������������������  the����������� ������������������  buffers

4. Don't����������� ������������������  use����������� ������������������  char����������� ������������������  conversion����������� ������������������  if����������� ������������������  you����������� ������������������  only����������� ������������������  need����������� ������������������  to����������� ������������������  transfer����������� ������������������  the����������� ������������������  content����������� ������������������  of����������� ������������������  a����������� ������������������  file,����������� ������������������  so����������� ������������������  don't����������� ������������������  use����������� ������������������  Reader����������� ������������������  if����������� ������������������  you����������� ������������������  need����������� ������������������  only����������� ������������������  streams.

5. Don't����������� ������������������  hesitate����������� ������������������  to����������� ������������������  use����������� ������������������  channels����������� ������������������  to����������� ������������������  make����������� ������������������  file����������� ������������������  transfer,����������� ������������������  it's����������� ������������������  the����������� ������������������  fastest����������� ������������������  way����������� ������������������  to����������� ������������������  make����������� ������������������  a����������� ������������������  file����������� ������������������  transfer.

6. Consider����������� ������������������  the����������� ������������������  native����������� ������������������  executable����������� ������������������  invocation����������� ������������������  only����������� ������������������  for����������� ������������������  really����������� ������������������  bigger����������� ������������������  files.

7. The����������� ������������������  new����������� ������������������  Path����������� ������������������  method����������� ������������������  of����������� ������������������  Java����������� ������������������  7����������� ������������������  is����������� ������������������  really����������� ������������������  fast����������� ������������������  except����������� ������������������  for����������� ������������������  the����������� ������������������  transfer����������� ������������������  of����������� ������������������  an����������� ������������������  enormous����������� ������������������  file����������� ������������������  between����������� ������������������  two����������� ������������������  disks.

출처 : http://baptiste-wicht.com/posts/2010/08/file-copy-in-java-benchmark.html

IO

104

대외비

3. 느리지 않게 하기

1.가능하다면 IO보다는NIO,����������� ������������������  NIO2����������� ������������������  사용을고려하라.

2. IO의 경우에도buffer 크기를잘조정하면좋은성능이나온다.

IO

105

대외비

3. 느리지 않게 하기

DB����������� ������������������  Connection

DB

106

대외비

3. 느리지 않게 하기

Connection����������� ������������������  Pool을 사용하자

DB

107

대외비

3. 느리지 않게 하기DB

108

대외비

3. 느리지 않게 하기

- Commons����������� ������������������  DBCP����������� ������������������  버전에대응하는 JDK����������� ������������������  버전과 JDBC����������� ������������������  버전

출처 : https://commons.apache.org/proper/commons-dbcp/

Commons����������� ������������������  DBCP����������� ������������������  버전 JDK����������� ������������������  버전 JDBC 버전

Commons DBCP����������� ������������������  2 JDK����������� ������������������  7 JDBC����������� ������������������  4.1

Commons DBCP����������� ������������������  1.4 JDK����������� ������������������  6 JDBC����������� ������������������  4

Commons DBCP����������� ������������������  1.3 JDK����������� ������������������  1.4 ~����������� ������������������  1.5 JDBC����������� ������������������  3

DB

109

대외비

3. 느리지 않게 하기

- 커넥션 개수관련 속성

속성이름 설명

initialSizeBasicDataSource클래스생성후최초로 getConnection()메서드를호출할 때커넥션 풀에채워 넣을커넥션 수

maxActive(=maxTotal)

동시에 사용할수 있는최대 커넥션개수 (기본값 : 8)

maxIdle 커넥션 풀에반납할 때최대로 유지될수 있는커넥션 개수 (기본값 : 8)

minIdle 최소한으로 유지할커넥션 개수 (기본값 : 0)

maxWait(=maxWaitMills)

커넥션 풀안의 커넥션이고갈되었을 때커넥션 반납을대기하는 시간(밀리초, 기본값 : 무한)

DB

110

대외비

3. 느리지 않게 하기

maxActive >=����������� ������������������  initialSize

maxIdle >=����������� ������������������  minIdle

maxActive =����������� ������������������  maxIdle

DB

111

대외비

3. 느리지 않게 하기

TPS(transaction����������� ������������������  per����������� ������������������  seconds)

DB

112

대외비

3. 느리지 않게 하기

TPS maxThread(Tomcat)

Resource maxActive(Commons����������� ������������������  DBCP)

maxWait(Commons����������� ������������������  DBCP)

- 적절한 maxWait값은?

DB

113

대외비

3. 느리지 않게 하기

가장 고려해야 할 것은?

DB

114

대외비

3. 느리지 않게 하기

maxWait <����������� ������������������  사용자 인내심

DB

115

대외비

3. 느리지 않게 하기

그 외에도…⋯(JDBC를 사용하면서)

DB

116

대외비

3. 느리지 않게 하기

setAutoCommit

executeBatch

setFetchSize

DB

117

대외비

3. 느리지 않게 하기

JDK

JDK

118

대외비

3. 느리지 않게 하기

성능을 위해서버전을 올려야 할까?

JDK

119

대외비

3. 느리지 않게 하기

확인해보자

JDK

120

대외비

3. 느리지 않게 하기JDK

- Benchmark(1)

출처 : http://www.optaplanner.org/blog/2014/03/20/HowMuchFasterIsJava8.html

121

대외비

3. 느리지 않게 하기JDK

- Benchmark(2)

출처 : http://www.dominicgiles.com/blog/files/abdb7a96e9db63644317c62d6e40c40b-142.html

122

대외비

3. 느리지 않게 하기

JDK����������� ������������������  버전을 올림으로써성능 향상을 얻을 수 있다

JDK

123

대외비

3. 느리지 않게 하기

단,����������� ������������������  7에서 8은 성능 향상이 크지 않으나 Public����������� ������������������  Update가종료되었으

므로 주의하자

JDK

124

대외비

3. 느리지 않게 하기JDK

MajorRelease

GA����������� ������������������  DateEnd����������� ������������������  of����������� ������������������  

Public����������� ������������������  UpdatesNotification

End����������� ������������������  of����������� ������������������  Public����������� ������������������  Updates

5.0 May  2004 Apr  2008 Oct  2009

6 Dec  2006 Feb  2011 Feb  2013

7 Jul  2011 Mar  2014 Apr  2015

8 Mar  2014 TBD Sep  2017*

- Java����������� ������������������  SE����������� ������������������  Public����������� ������������������  Updates

*����������� ������������������  or����������� ������������������  later,����������� ������������������  depending����������� ������������������  on����������� ������������������  factors����������� ������������������  described����������� ������������������  above.

출처 : http://www.oracle.com/technetwork/java/javase/eol-135779.html

125

대외비

3. 느리지 않게 하기

JDK����������� ������������������  9

JDK

126

대외비

3. 느리지 않게 하기JDK

- Schedule

• 2015/12/10����������� ������������������  :����������� ������������������  Feature����������� ������������������  Complete

• 2016/02/04����������� ������������������  :����������� ������������������  All����������� ������������������  Tests����������� ������������������  Run

• 2016/02/25����������� ������������������  :����������� ������������������  Rampdown Start

• 2016/04/21����������� ������������������  :����������� ������������������  Zero����������� ������������������  Bug����������� ������������������  Bounce

• 2016/06/16����������� ������������������  :����������� ������������������  Rampdown Phase����������� ������������������  2

• 2016/07/21����������� ������������������  :����������� ������������������  Final����������� ������������������  Release����������� ������������������  Candidate

• 2016/09/22����������� ������������������  :����������� ������������������  General����������� ������������������  Availability

출처 : http://openjdk.java.net/projects/jdk9/

127

대외비

3. 느리지 않게 하기JDK

- JEP����������� ������������������  214:����������� ������������������  Remove����������� ������������������  GC����������� ������������������  Combinations����������� ������������������  Deprecated����������� ������������������  in����������� ������������������  JDK����������� ������������������  8

• JDK����������� ������������������  8에서 사용하지않는 GC����������� ������������������  조합제거• DefNew +����������� ������������������  CMS :����������� ������������������  -XX:-UseParNewGC -XX:+UseConcMarkSweepGC

• ParNew +����������� ������������������  SerialOld :����������� ������������������  -XX:+UseParNewGC

• ParNew +����������� ������������������  iCMS :����������� ������������������  -Xincgc

• ParNew +����������� ������������������  iCMS :����������� ������������������  -XX:+CMSIncrementalMode -XX:+UseConcMarkSweepGC

• DefNew +����������� ������������������  iCMS :����������� ������������������  -XX:+CMSIncrementalMode -XX:+UseConcMarkSweepGC -XX:-

UseParNewGC

• CMS����������� ������������������  foreground :����������� ������������������  -XX:+UseCMSCompactAtFullCollection

• CMS����������� ������������������  foreground :����������� ������������������  -XX:+CMSFullGCsBeforeCompaction

• CMS����������� ������������������  foreground :����������� ������������������  -XX:+UseCMSCollectionPassing

출처 : http://openjdk.java.net/jeps/214

128

대외비

3. 느리지 않게 하기JDK

- JEP����������� ������������������  158:����������� ������������������  Unified����������� ������������������  JVM����������� ������������������  Logging

• JVM의모든 구성요소에 대한통합 로깅제공

• 커맨드 라인옵션으로 모든로깅 제공

• 로그 메시지는태그로 분류됨

• compiler,����������� ������������������  gc,����������� ������������������  classload,����������� ������������������  metaspace,����������� ������������������  svc,����������� ������������������  jfr 등

• 로그 레벨선택 가능

• 메시지 데코레이션가능

• 기본 데코레이션 :����������� ������������������  uptime,����������� ������������������  level,����������� ������������������  tags

• jcmd 또는MBean을통해 로깅을런타임에 동적구성을 할수 있음

출처 : http://openjdk.java.net/jeps/158

4. 다시 한번 질문하기 : Java는 정말 느린가?

130

대외비

4. 다시 한번 질문하기 : Java는 정말 느린가?

VS부가티 베이론 16.4(최고속도400km����������� ������������������  over)

BMW����������� ������������������  X6(최고속도약 250km)

131

대외비

4. 다시 한번 질문하기 : Java는 정말 느린가?

정말 느리나요?

132

질문은… 이 책을 참조하세요 ^^

133

감사합니다.

top related