Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page
Help Center/ Cloud Container Engine/ Best Practices/ Storage/ Automatically Collecting JVM Dump Files That Exit Unexpectedly Using SFS 3.0

Automatically Collecting JVM Dump Files That Exit Unexpectedly Using SFS 3.0

Updated on 2024-12-28 GMT+08:00

If you are using Java to develop services, you may encounter an out of memory (OOM) problem if the JVM heap space is insufficient. To address this issue, you can use SFS 3.0 file systems to store logs and mount the file systems to the relevant directories in containers. In the event of a JVM OOM, SFS 3.0 file systems can record logs.

Prerequisites

Procedure

  1. Create a PVC based on SFS 3.0.

    cat << EOF | kubectl apply -f -
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: jvm-sfs-pvc
      namespace: default
      annotations: {}
    spec:
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 10Gi
      storageClassName: csi-sfs
    EOF

  2. Create a Deployment using the following YAML to simulate Java OOM and dump the generated dump files to the PV associated with the SFS 3.0 file system.

    cat << EOF | kubectl apply -f -
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: java-application
      namespace: default
    spec:
      selector:
        matchLabels:
          app: java-application
      template:
        metadata:
          labels:
            app: java-application
        spec:
          containers:
          - name: java-application
            image: swr.cn-east-3.myhuaweicloud.com/container/java-oom-demo:v1  #The image in this document is only an example.
            imagePullPolicy: Always
            env: 
            - name: POD_NAME     # Use metadata.name as the value of the POD_NAME environment variable.
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.name
            - name: POD_NAMESPACE     #Use metadata.namespace as the value of the POD_NAMESPACE environment variable.
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.namespace
            args:
            - java                            #Run the Java command.
            - -Xms80m                         #Configure the minimum heap size of the heap memory.
            - -Xmx80m                         #Configure the maximum heap size of the heap memory.
            - -XX:HeapDumpPath=/mnt/oom/logs  #Heap memory dump path when OOM occurs
            - -XX:+HeapDumpOnOutOfMemoryError #Capture the heap OOM error.
            - Mycode                          #Run the application.
            volumeMounts:
            - name: java-oom-pv
              mountPath: "/mnt/oom/logs"      # The container uses /mnt/oom/logs as the mount directory.
              subPathExpr: $(POD_NAMESPACE).$(POD_NAME)   #Create a subdirectory using $(POD_NAMESPACE).$(POD_NAME) and allow the OOM dump files to be generated to the subdirectory.
          imagePullSecrets:
            - name: default-secret
          volumes:
          - name: java-oom-pv
            persistentVolumeClaim:
              claimName: jvm-sfs-pvc         #PVC using the SFS file system, named jvm-sfs-pvc
    EOF

  3. Wait until the container automatically restarts due to OOM.

    # kubectl -n default get pod
    NAME                                READY   STATUS    RESTARTS      AGE
    java-application-84dc6f897f-hc9q7   1/1     Running   1 (31s ago)   97s

  4. Obtain the files generated by the Java program due to OOM.

    1. Log in to the CCE console and click the cluster name to access the cluster console. In the navigation pane, choose Storage, click the PVCs tab, locate the row containing jvm-sfs-pvc, and click the name of the associated PV.
    2. After the system automatically switches to the row containing the corresponding PV, click the name of the associated storage volume.
    3. After the system automatically switches to the SFS console, copy the mounting command.

    4. Log in to a cluster node, create a mount point, and run the mount command to mount the SFS volume to the node.
      mkdir /test-jvm
      mount -t nfs -o vers=3,timeo=600,noresvport,nolock,proto=tcp ***.com:/pvc-4ea9137e-4101-4610-a4d2-9f8bb37043a1 /test-jvm
    5. Check the files in the mounted file system. The dump file java_pid1.hprof is present in the directory. To identify the line of code that triggers an OOM error, download java_pid1.hprof to the local host and use Eclipse Memory Analyzer Tool (MAT) to further analyze JVM stack information.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback