Programming Quality - yibinericxia/documents GitHub Wiki

Memory

Design Consideration

lazy

Use SonarLint & SonarQube

Clean As You Code (CAYC)

Potential Memory Issues

Metaspace

Metaspace is the native memory allocated for Java class metadata including static content. Before Java 8, it is called PermGen which is the memory to store class and method objects in heap with the setting of "-XX:MaxPermSize". In Java 8 and later it is called Metaspace, and it is directly limited by the OS and not part of heap any more. The default of MaxMetaspaceSize depends on the environment, for some Kubernetes container, it is 100M. It can be changed via "-XX:MaxMetaspaceSize=512m". For example, we can put something below in the deployment yaml file

spec
  containers:
  - env:
    - name: JAVA_OPTIONS
      value: '-Xms128m -Xmx1024m -XX:MaxmetaspaceSiize=512m -XX:NativeMemoryTracking=summary'

so that the garbage collection can be triggered to deallocate dead class metadata and recycled to the OS. If metaspace is exausted, the java.lang.OutOfMemoryError: Metaspace will be issued. The detailed metaspace (MC) and garbage collection (GC) info can be viewed by the following command:

jstat -gcmetacapacity appPID
[docker exec myApp] jcmd myAppPID VM.native_memory summary

There are some other settings like MaxMetaspaceFreeRatio with the default value of 70% and MinMetaspaceFreeRatio with the default value of 40%.

Root Cause Analysis

BigPanda

A SaaS platform which integrates monitoring tools and service management ticketing system with AI for event aggregation, normalization, correlation and enrichment, and provides various views of applications and infrastructure environment. Inputs could be

  • distributed applications: kubenetes
  • database monitoring tools: oracle
  • log monitoring platform: splunk
  • system/network monitoring: zabbix
  • synthetic monitoring: jmeter