2024-01-05-TIL

Today I Learned

AWS Fargate

AWS Fargate는 Amazon EC2 인스턴스의 서버나 클러스터를 관리할 필요 없이 컨테이너를 실행하기 위해 Amazon ECS에 사용할 수 있는 기술이다. Fargate를 사용하면 더 이상 컨테이너를 실행하기 위해 가상 머신의 클러스터를 프로비저닝, 구성 또는 조정할 필요가 없다. 따라서 서버 유형을 선택하거나, 클러스터를 조정할 시점을 결정하거나, 클러스터 패킹을 최적화할 필요가 없다.

Fargate 시작 유형 또는 Fargate 용량 공급자를 사용하여 Amazon ECS 태스크와 서비스를 실행할 때는 애플리케이션을 컨테이너에 패키징하고, 운영 체제, CPU 및 메모리 요구 사항을 지정한 다음, 네트워킹 및 IAM 정책을 정의하고, 애플리케이션을 시작한다. 각 Fargate 태스크에는 자체 격리 경계가 있으며 다른 태스크와 기본 커널, CPU 리소스, 메모리 리소스 또는 탄력적 네트워크 인터페이스를 공유하지 않는다.

  • https://docs.aws.amazon.com/AmazonECS/latest/userguide/what-is-fargate.html

AWS Instance Resizing

  • https://repost.aws/knowledge-center/resize-instance

How to Check Memory Usage in Linux

free -h 이 명령어로 기본적인 메모리 사용량을 확인할 수 있다.

top 명령어 입력 후, m을 누르면 메모리 모니터링 뷰의 형태로 바뀐다.

  • https://lascrea.tistory.com/71
  • https://dataonair.or.kr/db-tech-reference/d-lounge/technical-data/?mod=document&uid=235927#:~:text=%EC%9C%A0%EB%8B%89%EC%8A%A4%20%EA%B3%84%EC%97%B4%EC%9D%98%20%EC%8B%9C%EC%8A%A4%ED%85%9C%EC%97%90%EC%84%9C,%EB%A5%BC%20%EC%89%BD%EA%B2%8C%20%ED%99%95%EC%9D%B8%ED%95%A0%20%EC%88%98%20%EC%9E%88%EB%8B%A4%20.

Resident Set Size (RSS) vs Virtual Memory Size (VSZ)

RSS is a measure of how much memory a process is consuming in our physical RAM, to load all of its pages after its execution.

VSZ is a measure of much memory a process can access after its execution.

  • https://rainbound.tistory.com/entry/smem-%EC%97%90%EC%84%9C-%EB%82%98%EC%98%A4%EB%8A%94-uss-pss-rss-%EC%9D%98%EB%AF%B8
  • https://www.baeldung.com/linux/resident-set-vs-virtual-memory-size
  • https://en.wikipedia.org/wiki/Resident_set_size
  • https://softwareperformancenotes.github.io/rssvsz/
  • https://en.wikichip.org/wiki/resident_set_size
  • https://www.baeldung.com/linux/process-memory-management

Shared Memory in Linux

  • https://www.scaler.com/topics/shared-memory-linux/
  • https://dev.to/0xog_pg/using-shared-memory-in-linux-1p62
  • https://www.csl.mtu.edu/cs4411.ck/www/NOTES/process/shm/what-is-shm.html
  • https://reakwon.tistory.com/96

Java Heap Dump

  • https://timotimo.tistory.com/94

JVM Default Heap Size

Java 애플리케이션을 단독으로 실행시키면 default heap size가 Java 버전별로 고정되어 있다. 하지만 Spring Boot 애플리케이션을 실행하면 시스템 메모리 용량에 따라 heap size를 조절해서 min, max를 지정하는 것 같다.

  • https://sarc.io/index.php/java/1092-jvm-default-heap-size#google_vignette
  • https://www.baeldung.com/spring-boot-default-memory-settings

Java Metaspace

  • https://jaemunbro.medium.com/java-metaspace%EC%97%90-%EB%8C%80%ED%95%B4-%EC%95%8C%EC%95%84%EB%B3%B4%EC%9E%90-ac363816d35e

jcmd

Native Memory Tracking

The Native Memory Tracking (NMT) is a Java HotSpot VM feature that tracks internal memory usage for a Java HotSpot VM.

Since NMT doesn't track memory allocations by non-JVM code, you may have to use tools supported by the operating system to detect memory leaks in native code.

The following sections describe how to monitor VM internal memory allocations and diagnose VM memory leaks.

Use NMT to Detect a Memory Leak

Procedure to use Native Memory Tracking to detect memory leaks.

Follow these steps to detect a memory leak:

Start the JVM with summary or detail tracking using the command line option: -XX:NativeMemoryTracking=summary or -XX:NativeMemoryTracking=detail. Establish an early baseline. Use NMT baseline feature to get a baseline to compare during development and maintenance by running: jcmd VM.native_memory baseline. Monitor memory changes using: jcmd VM.native_memory detail.diff. If the application leaks a small amount of memory, then it may take a while to show up.

  • https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr006.html#BABEJDGE
  • https://www.fusion-reactor.com/blog/alternatives-to-jstack-and-jcmd/
  • https://www.whatap.io/ko/blog/57/
  • https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr007.html
  • https://www.samsungsds.com/kr/insights/1232762_4627.html
  • https://www.digitalocean.com/community/tutorials/java-thread-dump-visualvm-jstack-kill-3-jcmd
  • https://docs.oracle.com/en/java/javase/11/troubleshoot/diagnostic-tools.html#GUID-CBC97A20-7379-4762-BA17-FB1A560D02E4
  • https://blog.naver.com/kbh3983/220999618166
  • https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/memleaks004.html
  • https://sheerheart.tistory.com/entry/JVM-%ED%8A%B8%EB%9F%AC%EB%B8%94-%EC%8A%88%ED%8C%85-%EB%B0%8F-%EB%B6%84%EC%84%9D%EC%9D%84-%EC%9C%84%ED%95%9C-%EB%AA%85%EB%A0%B9%EC%96%B4%EB%93%A4
  • https://stackoverflow.com/questions/52053455/why-there-is-difference-in-heap-dump-size-generated-by-jmap-and-jcmd
  • https://command-not-found.com/jcmd#google_vignette
  • https://bell-sw.com/announcements/2021/10/14/jcmd-everywhere-locally-containerized-and-remotely/
  • https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr006.html#BABEJDGE
  • https://download.java.net/java/early_access/loom/docs/specs/man/jcmd.html
  • https://download.java.net/java/early_access/loom/docs/specs/man/jcmd.html
  • https://www.ibm.com/docs/en/semeru-runtime-ce-z/11?topic=tools-java-command-jcmd-tool
  • https://kwonnam.pe.kr/wiki/java/jcmd#google_vignette
  • https://dzone.com/articles/jvm-tuning-using-jcmd
  • https://www.baeldung.com/running-jvm-diagnose -> ***

JFR

  • https://access.redhat.com/documentation/en-us/red_hat_build_of_openjdk/21
  • https://www.baeldung.com/java-flight-recorder-monitoring
  • https://medium.com/@chrishantha/java-flight-recorder-cheat-sheet-98f5143f5f88
  • https://www.javatpoint.com/java-flight-recorder
  • https://docs.oracle.com/javacomponents/jmc-5-4/jfr-runtime-guide/run.htm#JFRUH164
  • https://docs.oracle.com/javacomponents/jmc-5-5/jfr-command-reference/diagnostic-command-reference.htm#JFRCR-GUID-BA5A1AA8-50C8-497E-BF4F-525872D643EC
  • https://access.redhat.com/solutions/662203
  • https://javakr.medium.com/jdk-21%EC%97%90%EC%84%9C-jfr%EC%9D%98-%EC%8B%A0-%EA%B8%B0%EB%8A%A5-jfr-view-6d596a6a62c6
  • https://docs.azul.com/prime/Java-Flight-Recorder
  • https://warpgate3.tistory.com/entry/JFR-Java-Flight-Recorder-JVM-%EC%A7%84%EB%8B%A8-Tool
  • https://access.redhat.com/documentation/en-us/red_hat_build_of_openjdk/8/html/using_jdk_flight_recorder_with_red_hat_build_of_openjdk/configure-jfr-options
  • https://access.redhat.com/documentation/en-us/red_hat_build_of_openjdk/8/html/using_jdk_flight_recorder_with_red_hat_build_of_openjdk/configure-jfr-options

Profiling

이것저것 찾다보니 실시간으로 또는 특정 시점에 JVM 메모리 상에서

[system memory [container [ JVM [ JVM reserved space ] ] ] ]

  • https://www.samsungsds.com/kr/insights/1232762_4627.html
  • https://docs.datadoghq.com/ko/profiler/enabling/java/?tab=datadogprofiler

JVM Monitoring

  • https://markruler.github.io/posts/java/jvm-monitoring/
  • https://docs.whatap.io/mysql/instance-monitoring
  • https://www.whatap.io/ko/blog/126/

Java GC Tuning

  • https://johngrib.github.io/wiki/java/gc/tuning-guide/

JVM Memory Allocation

  • https://developers.redhat.com/articles/2021/09/09/how-jvm-uses-and-allocates-memory

Can a Java Application Use More Memory Than the Heap Size?

In Java, the heap is the area of memory where objects are allocated and managed by the garbage collector. The maximum heap size for a Java application is typically set using the -Xmx option when launching the Java Virtual Machine (JVM). The -Xmx option specifies the maximum heap size in bytes, kilobytes, megabytes, or gigabytes.

While the heap is a significant portion of the memory used by a Java application, it's not the only part. Java applications also use memory outside of the heap, which includes the following:

  1. PermGen/Metaspace: Before Java 8, there was a PermGen (Permanent Generation) space that stored class metadata, interned strings, and other JVM internals. In Java 8 and later versions, PermGen was replaced by Metaspace. Metaspace still occupies memory outside the heap.

  2. Thread Stacks: Each thread in a Java application has its own stack, which is used for method calls, local variables, and other thread-specific data.

  3. JVM Overhead: The JVM itself requires some memory for its internal structures and bookkeeping.

  4. Direct Memory: Java applications can use direct memory through the java.nio package, and this memory is not managed by the garbage collector. It is typically allocated outside the heap.

Given these factors, it's possible for a Java application to use more memory than the specified heap size (-Xmx). If the overall memory consumption (heap + Metaspace + thread stacks + JVM overhead + direct memory) exceeds the available system memory, the application may run into memory-related issues.

To get a better understanding of memory usage, you can use tools like jconsole, jvisualvm, or other profiling tools to monitor different memory areas and identify potential memory leaks or excessive memory usage. Keep in mind that managing memory effectively is crucial for the performance and stability of Java applications.

  • https://www.baeldung.com/java-memory-beyond-heap

Datadog Profiler

  • https://docs.datadoghq.com/ko/profiler/
  • https://docs.datadoghq.com/ko/profiler/enabling/java/?tab=datadogprofiler
  • https://docs.datadoghq.com/ko/profiler/profiler_troubleshooting/java/
  • https://docs.datadoghq.com/ko/profiler/connect_traces_and_profiles/
  • https://assets.ctfassets.net/oxjq45e8ilak/4Bse1v0k36rC5W8bklrh9C/577134937b1d8f11dfe9d11055349f01/Jean-Philippe_Bempel_Real_World_JFR_Experiences_building_and_deploying_a_continuous_profiler_at_scale_2021_04_07_16_16_00.pdf
  • https://medium.com/platform-engineer/guide-to-java-profilers-e344ce0339e0
  • https://www.datadoghq.com/blog/monitoring-rails-with-datadog/

ZGC vs G1GC

  • https://huisam.tistory.com/entry/jvmgc
  • https://d2.naver.com/helloworld/0128759
  • https://incheol-jung.gitbook.io/docs/q-and-a/java/g1-gc-vs-z-gc
  • https://www.linkedin.com/pulse/jdk-17-g1gc-vs-zgc-usage-core-exchange-application-performance-raza

FTP Read Timed out

  • https://bobcares.com/blog/ftp-read-timed-out/