簡體   English   中英

使用 Jmeter - Kubernetes 進行測試后,spring boot 的容器內存使用率不低

[英]Container memory usage with spring boot not low after testing with Jmeter - Kubernetes

早上好。 我有一個查詢,我對 Kubernetes 和 Java(spring boot)比較陌生,我目前正在使用 spring boot 部署一個帶有三個容器的 pod,問題是我正在使用 Jmeter 進行測試以測量指標並在 Kubernetes 中使用 HPA 自動擴展,但是我發現當您強調容器的內存會增加時,但是當我完成測試時,容器不會降低內存使用量。 不知道這個話題是不是因為JVM的原因,是典型的Java,還是垃圾收集器失敗了,必須在docker鏡像中定義。 我在 yaml manifest 的容器中給了他 CPU 和內存方面的資源限制

這是我的容器在使用 Jmeter 開始測試之前的狀態

在此處輸入圖片說明

用Jmeter測試后,通過了大約15分鍾,容器在內存方面也是如此:

在此處輸入圖片說明

這就是我定義 Dockerfile 的方式:

FROM openjdk:8-alpine
RUN rm -rf /var/cache/apk/*
RUN rm -rf /tmp/*
RUN apk update
RUN apk add busybox-extras
ENV UBICATION_CERTIFICATE_SSL=/etc/letsencrypt/tmp224.p12
ENV PASSWORD_CERTIFICATE_SSL=xxxxx
ENV ALIAS_CERTIFICATE_SSL=tmp224
ADD FindAccountNumber-0.0.1-SNAPSHOT.jar /home/app.jar
ADD tmp224.p12 /etc/letsencrypt/tmp224.p12
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/home/app.jar"]

還有我的清單 yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: find-complementary-account-info-1
  labels:
    app: find-complementary-account-info-1
spec:
  replicas: 2
  selector:
    matchLabels:
      app: find-complementary-account-info-1
  template:
    metadata:
      labels:
        app: find-complementary-account-info-1
    spec:
      containers:
      - name: find-account-number-1
        image: find-account-number:latest
        imagePullPolicy: IfNotPresent
        resources:
          limits:
            cpu: "250m"
            memory: "350Mi"
          requests:
            cpu: "150m"
            memory: "300Mi"
        ports:
        - containerPort: 8081
        env:
        - name: URL_CONNECTION_BD
          value: jdbc:oracle:thin:@xxxxxxxx:1531/DEFAULTSRV.WORLD
        - name: USERNAME_CONNECTION_BD
          valueFrom:
            secretKeyRef:
              name: credentials-bd-pers
              key: user_pers
        - name: PASSWORD_CONNECTION_BD
          valueFrom:
            secretKeyRef:
              name: credentials-bd-pers
              key: password_pers
      - name: find-account-validators-1
        image: find-account-validators:latest
        imagePullPolicy: IfNotPresent
        resources:
          limits:
            cpu: "250m"
            memory: "350Mi"
          requests:
            cpu: "150m"
            memory: "300Mi"
        ports:
        - containerPort: 8082
        env:
        - name: URL_CONNECTION_BD
          value: jdbc:oracle:thin:@xxxxxxxx:1522/DEFAULTSRV.WORLD
        - name: USERNAME_CONNECTION_BD
          valueFrom:
            secretKeyRef:
              name: credentials-bd-billing
              key: user_billing
        - name: PASSWORD_CONNECTION_BD
          valueFrom:
            secretKeyRef:
              name: credentials-bd-billing
              key: password_billing
      - name: find-complementary-account-info-1
        image: find-complementary-account-info:latest
        imagePullPolicy: IfNotPresent
        resources:
          limits:
            cpu: "250m"
            memory: "350Mi"
          requests:
            cpu: "150m"
            memory: "300Mi"
        ports:
        - containerPort: 8083
        env:
        - name: UBICATION_URL_ACCOUNT_NUMBER
          value: "https://localhost:8081/api/FindAccountNumber"
        - name: UBICATION_URL_ACCOUNT_VALIDATORS
          value: "https://localhost:8082/api/FindAccountValidator"
---

apiVersion: v1
kind: Service
metadata:
  name: svc-find-complementary-account-info-1
  labels:
    app: find-complementary-account-info-1
  annotations:
    metallb.universe.tf/allow-shared-ip: shared-ip
  namespace: default
spec:
  selector:
    app: find-complementary-account-info-1
  externalTrafficPolicy: Cluster
  loadBalancerIP: 10.161.174.68
  type: LoadBalancer
  ports:
   -
    protocol: TCP
    port: 8083
    targetPort: 8083
    nodePort: 30025
---

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: find-complementary-account-info-1
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: find-complementary-account-info-1
  minReplicas: 2
  maxReplicas: 5
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 70

我怎樣才能減少在容器中使用彈簧靴的內存,因為我想它會隨着壓力的增加而不斷增加

我認為差異很小(~220 MB vs 250-290 MB),你不應該為此煩惱。

但您似乎在談論 Java 應用程序(不是)將內存返回給操作系統。 這是很長一段時間以來的常見行為,它取決於垃圾收集器 - 這並不意味着 GC 不起作用。 您使用的是 JDK 8,因此您沒有太多選擇,但在更高版本中,有改進的收集器,例如

您可以在此處找到更多信息: GC 是否將內存釋放回操作系統?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM