说明,此测试不完备,只是一个简单的集成,详细的需要进行jvm 参数的调整

环境准备

pom.xml

 
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.1.6.RELEASE</version>
  <relativePath/> <!-- lookup parent from repository -->
 </parent>
 <groupId>com.dalong.webapi</groupId>
 <artifactId>webapi</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <name>webapi</name>
 <description>Demo project for Spring Boot</description>
 <properties>
  <java.version>1.8</java.version>
 </properties>
 <dependencies>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  <dependency>
   <groupId>com.netflix.servo</groupId>
   <artifactId>servo-core</artifactId>
   <version>0.12.7</version>
  </dependency>
  <dependency>
   <groupId>org.jolokia</groupId>
   <artifactId>jolokia-core</artifactId>
   <version>1.6.2</version>
  </dependency>
  <dependency>
   <groupId>io.micrometer</groupId>
   <artifactId>micrometer-registry-prometheus</artifactId>
  </dependency>
  <dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-swagger2</artifactId>
   <version>2.9.2</version>
  </dependency>
  <dependency>
   <groupId>com.google.guava</groupId>
   <artifactId>guava</artifactId>
   <version>20.0</version>
  </dependency>
  <dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-swagger-ui</artifactId>
   <version>2.9.2</version>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test</artifactId>
   <scope>test</scope>
  </dependency>
 </dependencies>
 <build>
  <plugins>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
   </plugin>
  </plugins>
 </build>
</project>
  • docker-compose 环境
    主要集成了zulu、oracle、openjdk 以及granfana,prometheus
 
version: "3"
services: 
  zulu:
    build: 
      context: ./zulu
      dockerfile: Dockerfile
    ports: 
    - "8080:8080"
  oracle:
    build: 
      context: ./oracle
      dockerfile: Dockerfile
    ports: 
    - "8081:8080"
  openjdk:
    build: 
      context: ./openjdk
      dockerfile: Dockerfile
    ports: 
    - "8082:8080"
  grafana:
    image: grafana/grafana
    ports:
    - "3000:3000"
  prometheus:
    image: prom/prometheus
    volumes:
    - "./prometheus.yml:/etc/prometheus/prometheus.yml"
    ports:
    - "9090:9090" 
  • 各jvm 运行dockerfile
    zulu Dockerfile
 
FROM azul/zulu-openjdk-alpine:8u222
LABEL AUTHOR="dalongrong"
LABEL EMAIL="[email protected]"
WORKDIR /
COPY jmx_prometheus_javaagent-0.12.0.jar /jmx_prometheus_javaagent-0.12.0.jar
COPY webapi-0.0.1-SNAPSHOT.jar /webapi-0.0.1-SNAPSHOT.jar
COPY docker-entrypiont.sh /docker-entrypiont.sh
RUN chmod +x /docker-entrypiont.sh
EXPOSE 8080 9999 30384
ENTRYPOINT [ "/docker-entrypiont.sh" ]

docker-entrypiont.sh:

#!/bin/sh
java -jar /webapi-0.0.1-SNAPSHOT.jar
 

openjdk以及oracle 的都是类似,主要的不通就是基础镜像

FROM frolvlad/alpine-java:jdk8-slim
FROM openjdk:8u222-jdk

几个说明,因为spring boot 已经包含了jmx 的暴露,所以对于jmx 的处理就没有多加复杂的处理,项目中包含了一个jmx-exporter
如果需要可以添加使用

  • grafana dashborad 配置
    可以参考项目中的grafana/dashboard.json
  • prometheus 配置
    使用静态配置prometheus.yml 文件
 
scrape_configs:
  - job_name: zulu
    metrics_path: /actuator/prometheus
    scrape_interval: 10s
    scrape_timeout: 10s
    static_configs:
      - targets: ['zulu:8080']
  - job_name: openjdk
    metrics_path: /actuator/prometheus
    scrape_interval: 10s
    scrape_timeout: 10s
    static_configs:
      - targets: ['openjdk:8080']
  - job_name: oracle
    scrape_interval: 10s
    scrape_timeout: 10s
    metrics_path: /actuator/prometheus
    static_configs:
      - targets: ['oracle:8080']
 
ab -c 10 -n 100000 http://localhost:port/actuator/env

为了同时运行,使用了一个简单的shell start.sh

#!/usr/bin/sh
rm -rf jdk/*.log
for file in jdk/*; do
 nohup bash $file > $file.log &
done

启动&&测试

  • 启动
docker-compose up -d
cd load-test && sh start.sh
  • 配置granfana

加载dashborad json 文件,在grafana/dashboard.json
通过granfana 以及prometheus 比较zulu 、oracle、openjdk 等jvm 运行-LMLPHP

  • prometheus 效果

通过granfana 以及prometheus 比较zulu 、oracle、openjdk 等jvm 运行-LMLPHP

  • granfana dashborad 的参数效果

通过granfana 以及prometheus 比较zulu 、oracle、openjdk 等jvm 运行-LMLPHP

  • 简单说明
    因为测试上的很随意实际上是有问题的,但是zulu 优化上的openjdk 总体还是很不错的,连接有一篇别人的测试,可以参考,但是也是不完备的。

参考资料

https://github.com/rongfengliang/zulu-openjdk-openjdk-oracle-jdk
https://technology.amis.nl/2018/11/23/comparing-jvm-performance-zulu-openjdk-openjdk-oracle-jdk-graalvm-ce/

05-11 22:52