简体   繁体   English

使用 Jmeter - Kubernetes 进行测试后,spring boot 的容器内存使用率不低

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

Good morning.早上好。 I have a query, I am relatively new to Kubernetes and Java (spring boot) and I am currently deploying a pod with three containers with spring boot, the question is that I am testing with Jmeter to measure metrics and scale automatically with HPA in Kubernetes, but I am getting that when you stress the memory of the containers increases, however when I finish doing the tests, the containers do not lower the memory use.我有一个查询,我对 Kubernetes 和 Java(spring boot)比较陌生,我目前正在使用 spring boot 部署一个带有三个容器的 pod,问题是我正在使用 Jmeter 进行测试以测量指标并在 Kubernetes 中使用 HPA 自动扩展,但是我发现当您强调容器的内存会增加时,但是当我完成测试时,容器不会降低内存使用量。 I don't know if this topic is typical of Java because of the JVM, or if the Garbage Collector is failing, and I must define it in the docker image.不知道这个话题是不是因为JVM的原因,是典型的Java,还是垃圾收集器失败了,必须在docker镜像中定义。 I give him a resource limit in terms of CPU and memory in the container in the yaml manifest我在 yaml manifest 的容器中给了他 CPU 和内存方面的资源限制

This is how my containers were before starting the test with Jmeter这是我的容器在使用 Jmeter 开始测试之前的状态

在此处输入图片说明

After testing with Jmeter, and the passage of about 15 minutes, so are the containers in terms of memory:用Jmeter测试后,通过了大约15分钟,容器在内存方面也是如此:

在此处输入图片说明

This is how I am defining my Dockerfile:这就是我定义 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"]

And my manifest yaml:还有我的清单 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

How can I reduce the memory in use of spring boot in a container, since so I imagine it will keep increasing as it is subjected to stress我怎样才能减少在容器中使用弹簧靴的内存,因为我想它会随着压力的增加而不断增加

I'd argue that the difference is pretty small (~220 MB vs 250-290 MB) and you should not bother with that.我认为差异很小(~220 MB vs 250-290 MB),你不应该为此烦恼。

But it seems you are talking about the java app (not) returning memory to the OS.但您似乎在谈论 Java 应用程序(不是)将内存返回给操作系统。 This has been a common behavior for a very long time and it depends on the garbage collector - it doesn't mean the GC doesn't work.这是很长一段时间以来的常见行为,它取决于垃圾收集器 - 这并不意味着 GC 不起作用。 You're using JDK 8 so you don't have many choices, but in later versions there are improved collectors, eg您使用的是 JDK 8,因此您没有太多选择,但在更高版本中,有改进的收集器,例如

You can find more information here: Does GC release back memory to OS?您可以在此处找到更多信息: GC 是否将内存释放回操作系统?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 一段时间后,Spring Boot 内存使用率高 - Spring boot high memory usage after some time Spring Boot内存使用情况(JpaMetamodelMappingContext) - Spring Boot memory usage (JpaMetamodelMappingContext) 由于低 Memory 关机后如何自动重启我的 Spring 启动 JAR 应用程序 - How to auto restart my Spring Boot JAR application after shutdown due of Low Memory 如何减少spring boot内存使用? - how to reduce spring boot memory usage? 使用内存db进行Spring Boot测试 - Spring Boot testing using in memory db 使用 JMeter 使用 RabbitMQ 应用程序负载测试进行后端 Spring 启动 - Backend Spring boot with RabbitMQ application load testing using JMeter 使用 JMeter 测试 spring 启动 rest 端点时出现 SSLException - SSLException while testing spring boot rest endpoint using JMeter Kubernetes 中用于 Spring Boot 集成测试的 Testcontainers 的选项或替代方案? - Options or alternatives to Testcontainers for Spring Boot integration testing in Kubernetes? 我可以在 ZB76E98AF9AAA680979BF5A65B2 上使用 docker 组合 mysql + spring 引导容器吗? - Can I use docker compose mysql + spring boot container on kubernetes? Kubernetes Google容器引擎。 配置Spring Boot HTTPS - Kubernetes Google container engine. Configuring Spring Boot HTTPS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM