經過granfana 以及prometheus 比較zulu 、oracle、openjdk 等jvm 運行

說明,此測試不完備,只是一個簡單的集成,詳細的須要進行jvm 參數的調整java

環境準備

pom.xmlgithub

 
<?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="1141591465@qq.com"
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:web

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

openjdk以及oracle 的都是相似,主要的不通就是基礎鏡像spring

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

幾個說明,由於spring boot 已經包含了jmx 的暴露,因此對於jmx 的處理就沒有多加複雜的處理,項目中包含了一個jmx-exporter
若是須要能夠添加使用docker

  • 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.shshell

#!/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

    須要配置premetheus server 地址,以及初始化中帳戶的處理apache

加載dashborad json 文件,在grafana/dashboard.json
json

 

  • prometheus 效果

 

  • granfana dashborad 的參數效果

 

  • 簡單說明
    由於測試上的很隨意其實是有問題的,可是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/api

相關文章
相關標籤/搜索