Browse Source

Update graalvm 21.2.0 (#6713)

* Update redkale-native.dockerfile

* Update redkale-native.dockerfile

* Update redkale-graalvm.dockerfile

* Update redkale-native.dockerfile

* Update application.xml

* Update pom.xml

* random

* Update Service.java

* Update persistence.xml

* Update persistence.xml

* Update redkale-graalvm.dockerfile

* Update redkale-graalvm.dockerfile

* Update redkale-graalvm.dockerfile

* Update redkale-graalvm.dockerfile

* Update redkale-graalvm.dockerfile

* Update redkale-native.dockerfile

* from openjdk17
Redkale 4 years ago
parent
commit
cb2b2566fd

+ 1 - 0
frameworks/Java/redkale/conf/application.xml

@@ -6,6 +6,7 @@
         <executor threads="0"/>
         <properties>    
             <property name="system.property.convert.tiny" value="false"/>      
+            <property name="system.property.redkale.skip.counter" value="true"/>  
             <property name="system.property.net.invoker.max.onstack" value="24"/>
             <property name="system.property.http.request.pipeline.sameheaders" value="true"/>  
             <property name="system.property.http.response.header.server" value="redkale"/>

+ 1 - 2
frameworks/Java/redkale/conf/persistence.xml

@@ -1,6 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
+<persistence version="2.0">
     
     <persistence-unit name=".read" transaction-type="RESOURCE_LOCAL">
         <shared-cache-mode>ALL</shared-cache-mode>

+ 7 - 1
frameworks/Java/redkale/pom.xml

@@ -31,7 +31,13 @@
             <groupId>com.fizzed</groupId>
             <artifactId>rocker-compiler</artifactId>
             <version>1.3.0</version>
-        </dependency>        
+        </dependency> 
+        
+        <dependency> 
+            <groupId>io.vertx</groupId>
+            <artifactId>vertx-pg-client</artifactId>
+            <version>4.1.2</version>
+        </dependency> 
     </dependencies>
 
     <repositories>

+ 13 - 5
frameworks/Java/redkale/redkale-cache.dockerfile

@@ -1,14 +1,22 @@
-FROM maven:3.6.3-openjdk-16-slim as maven
+FROM openjdk:17-jdk-slim
+ARG DEBIAN_FRONTEND=noninteractive
+ARG MAVEN_VERSION=3.8.1
+
 WORKDIR /redkale
+RUN apt-get update -yqq
+RUN apt-get install -yqq wget
+
+RUN wget --no-verbose https://ftp.wayne.edu/apache/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz
+RUN tar -xzf apache-maven-${MAVEN_VERSION}-bin.tar.gz
+ENV MAVEN_HOME /redkale/apache-maven-${MAVEN_VERSION}
+ENV PATH $MAVEN_HOME/bin:$PATH
+
 COPY src src
 COPY conf conf
 COPY pom.xml pom.xml
 RUN mvn package -q
 
-FROM openjdk:16-jdk-slim
-WORKDIR /redkale
-COPY conf conf
-COPY --from=maven /redkale/target/redkale-benchmark-1.0.0.jar redkale-benchmark.jar
+RUN cp /redkale/target/redkale-benchmark-1.0.0.jar redkale-benchmark.jar
 
 EXPOSE 8080
 

+ 18 - 5
frameworks/Java/redkale/redkale-graalvm.dockerfile

@@ -1,14 +1,27 @@
-FROM maven:3.6.3-openjdk-16-slim as maven
+FROM ubuntu:20.10
+ARG DEBIAN_FRONTEND=noninteractive
+ARG MAVEN_VERSION=3.8.1
+
 WORKDIR /redkale
+RUN apt-get update -yqq
+RUN apt-get install -yqq wget
+
+RUN wget --no-verbose https://redkale.org/graalvm-ee-java16-linux-amd64-21.2.0.tar.gz
+RUN tar -xzf graalvm-ee-java16-linux-amd64-21.2.0.tar.gz
+ENV JAVA_HOME /redkale/graalvm-ee-java16-21.2.0
+
+RUN wget --no-verbose https://ftp.wayne.edu/apache/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz
+RUN tar -xzf apache-maven-${MAVEN_VERSION}-bin.tar.gz
+ENV MAVEN_HOME /redkale/apache-maven-${MAVEN_VERSION}
+
+ENV PATH $JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
+
 COPY src src
 COPY conf conf
 COPY pom.xml pom.xml
 RUN mvn package -q
 
-FROM ghcr.io/graalvm/graalvm-ce:21.1.0
-WORKDIR /redkale
-COPY conf conf
-COPY --from=maven /redkale/target/redkale-benchmark-1.0.0.jar redkale-benchmark.jar
+RUN cp /redkale/target/redkale-benchmark-1.0.0.jar redkale-benchmark.jar
 
 EXPOSE 8080
 

+ 1 - 1
frameworks/Java/redkale/redkale-native.dockerfile

@@ -6,7 +6,7 @@ COPY pom.xml pom.xml
 RUN mvn package -q
 
 
-FROM ghcr.io/graalvm/graalvm-ce:21.1.0
+FROM ghcr.io/graalvm/graalvm-ce:21.2.0
 RUN gu install native-image
 WORKDIR /redkale
 COPY conf conf

+ 13 - 5
frameworks/Java/redkale/redkale-postgres.dockerfile

@@ -1,14 +1,22 @@
-FROM maven:3.6.3-openjdk-16-slim as maven
+FROM openjdk:17-jdk-slim
+ARG DEBIAN_FRONTEND=noninteractive
+ARG MAVEN_VERSION=3.8.1
+
 WORKDIR /redkale
+RUN apt-get update -yqq
+RUN apt-get install -yqq wget
+
+RUN wget --no-verbose https://ftp.wayne.edu/apache/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz
+RUN tar -xzf apache-maven-${MAVEN_VERSION}-bin.tar.gz
+ENV MAVEN_HOME /redkale/apache-maven-${MAVEN_VERSION}
+ENV PATH $MAVEN_HOME/bin:$PATH
+
 COPY src src
 COPY conf conf
 COPY pom.xml pom.xml
 RUN mvn package -q
 
-FROM openjdk:16-jdk-slim
-WORKDIR /redkale
-COPY conf conf
-COPY --from=maven /redkale/target/redkale-benchmark-1.0.0.jar redkale-benchmark.jar
+RUN cp /redkale/target/redkale-benchmark-1.0.0.jar redkale-benchmark.jar
 
 EXPOSE 8080
 

+ 13 - 5
frameworks/Java/redkale/redkale.dockerfile

@@ -1,14 +1,22 @@
-FROM maven:3.6.3-openjdk-16-slim as maven
+FROM openjdk:17-jdk-slim
+ARG DEBIAN_FRONTEND=noninteractive
+ARG MAVEN_VERSION=3.8.1
+
 WORKDIR /redkale
+RUN apt-get update -yqq
+RUN apt-get install -yqq wget
+
+RUN wget --no-verbose https://ftp.wayne.edu/apache/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz
+RUN tar -xzf apache-maven-${MAVEN_VERSION}-bin.tar.gz
+ENV MAVEN_HOME /redkale/apache-maven-${MAVEN_VERSION}
+ENV PATH $MAVEN_HOME/bin:$PATH
+
 COPY src src
 COPY conf conf
 COPY pom.xml pom.xml
 RUN mvn package -q
 
-FROM openjdk:16-jdk-slim
-WORKDIR /redkale
-COPY conf conf
-COPY --from=maven /redkale/target/redkale-benchmark-1.0.0.jar redkale-benchmark.jar
+RUN cp /redkale/target/redkale-benchmark-1.0.0.jar redkale-benchmark.jar
 
 EXPOSE 8080
 

+ 81 - 69
frameworks/Java/redkale/src/main/java/org/redkalex/benchmark/CachedWorld.java

@@ -1,69 +1,81 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package org.redkalex.benchmark;
-
-import javax.persistence.*;
-import org.redkale.convert.json.JsonConvert;
-import org.redkale.source.*;
-
-/**
- *
- * @author zhangjx
- */
-//@Cacheable(direct = true)
-@Entity
-@Table(name = "World")
-public final class CachedWorld implements Comparable<CachedWorld> {
-
-    @Id
-    private int id;
-
-    private int randomNumber;
-
-    public CachedWorld randomNumber(int randomNumber) {
-        this.randomNumber = randomNumber;
-        return this;
-    }
-
-    public int getId() {
-        return id;
-    }
-
-    public void setId(int id) {
-        this.id = id;
-    }
-
-    public int getRandomNumber() {
-        return randomNumber;
-    }
-
-    public void setRandomNumber(int randomNumber) {
-        this.randomNumber = randomNumber;
-    }
-
-    @Override
-    public int compareTo(CachedWorld o) {
-        return Integer.compare(id, o.id);
-    }
-
-    @Override
-    public String toString() {
-        return JsonConvert.root().convertTo(this);
-    }
-
-    public static class WorldEntityCache {
-
-        private Object[] array;
-
-        public WorldEntityCache(DataSource source) {
-            this.array = source.queryList(CachedWorld.class).toArray();
-        }
-
-        public CachedWorld findAt(int index) {
-            return (CachedWorld) array[index];
-        }
-    }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkalex.benchmark;
+
+import java.util.Random;
+import javax.persistence.*;
+import org.redkale.convert.json.JsonConvert;
+import org.redkale.source.*;
+
+/**
+ *
+ * @author zhangjx
+ */
+//@Cacheable(direct = true)
+@Entity
+@Table(name = "World")
+public final class CachedWorld implements Comparable<CachedWorld> {
+
+    @Id
+    private int id;
+
+    private int randomNumber;
+
+    public CachedWorld randomNumber(int randomNumber) {
+        this.randomNumber = randomNumber;
+        return this;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getRandomNumber() {
+        return randomNumber;
+    }
+
+    public void setRandomNumber(int randomNumber) {
+        this.randomNumber = randomNumber;
+    }
+
+    @Override
+    public int compareTo(CachedWorld o) {
+        return Integer.compare(id, o.id);
+    }
+
+    @Override
+    public String toString() {
+        return JsonConvert.root().convertTo(this);
+    }
+
+    public static class WorldEntityCache {
+
+        private Object[] array;
+
+        public WorldEntityCache(DataSource source) {
+            this.array = source.queryList(CachedWorld.class).toArray();
+        }
+
+        public CachedWorld findAt(int index) {
+            return (CachedWorld) array[index];
+        }
+
+        public CachedWorld[] random(Random random, int size) {
+            final CachedWorld[] worlds = new CachedWorld[size];
+            int count = size;
+            Random rand = random;
+            for (int i = 0; i < count; i++) {
+                long index = Math.abs(rand.nextLong()) % 10000;
+                worlds[i] = (CachedWorld) array[(int) index];
+            }
+            return worlds;
+        }
+    }
+}

+ 45 - 0
frameworks/Java/redkale/src/main/java/org/redkalex/benchmark/RedRandom.java

@@ -0,0 +1,45 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkalex.benchmark;
+
+import java.util.Random;
+
+/**
+ *
+ * @author zhangjx
+ */
+public class RedRandom extends Random {
+
+    private long s0, s1;
+
+    public RedRandom() {
+        this.s0 = super.nextLong();
+        this.s1 = super.nextLong();
+    }
+
+    @Override
+    public long nextLong() {
+        final long s0 = this.s0;
+        long s1 = this.s1;
+        final long result = s0 + s1;
+        s1 ^= s0;
+        this.s0 = Long.rotateLeft(s0, 24) ^ s1 ^ s1 << 16;
+        this.s1 = Long.rotateLeft(s1, 37);
+        return result;
+    }
+
+    @Override
+    public int nextInt() {
+        return (int) nextLong();
+    }
+
+    @Override
+    public int nextInt(int bound) {
+        long s = nextLong();
+        return (int) (s < 0 ? -s : s) % bound;
+    }
+
+}

+ 99 - 96
frameworks/Java/redkale/src/main/java/org/redkalex/benchmark/Service.java

@@ -1,96 +1,99 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package org.redkalex.benchmark;
-
-import java.util.concurrent.*;
-import javax.annotation.Resource;
-import org.redkale.net.ChannelContext;
-import org.redkale.net.http.*;
-import org.redkale.service.AbstractService;
-import org.redkale.source.*;
-import org.redkalex.benchmark.CachedWorld.WorldEntityCache;
-
-/**
- *
- * @author zhangjx
- */
-@RestService(name = " ", repair = false)
-public class Service extends AbstractService {
-
-    private static final byte[] helloBytes = "Hello, world!".getBytes();
-
-    @Resource
-    private DataSource source;
-
-    private WorldEntityCache cache;
-
-    @RestMapping(name = "plaintext")
-    public byte[] getHelloBytes() {
-        return helloBytes;
-    }
-
-    @RestMapping(name = "json")
-    public Message getHelloMessage() {
-        return Message.create("Hello, World!");
-    }
-
-    @RestMapping(name = "db")
-    public CompletableFuture<World> findWorldAsync(ChannelContext context) {
-        return source.findAsync(World.class, context, 1 + ThreadLocalRandom.current().nextInt(10000));
-    }
-
-    @RestMapping(name = "queries")
-    public CompletableFuture<World[]> queryWorldAsync(ChannelContext context, int q) {
-        final int size = Math.min(500, Math.max(1, q));
-        final World[] worlds = new World[size];
-        final ThreadLocalRandom random = ThreadLocalRandom.current();
-        final CompletableFuture[] futures = new CompletableFuture[size];
-        for (int i = 0; i < size; i++) {
-            final int index = i;
-            futures[index] = source.findAsync(World.class, context, 1 + random.nextInt(10000)).thenAccept(v -> worlds[index] = v);
-        }
-        return CompletableFuture.allOf(futures).thenApply(v -> worlds);
-    }
-
-    @RestMapping(name = "updates")
-    public CompletableFuture<World[]> updateWorldAsync(ChannelContext context, int q) {
-        final int size = Math.min(500, Math.max(1, q));
-        final World[] worlds = new World[size];
-        final ThreadLocalRandom random = ThreadLocalRandom.current();
-        final CompletableFuture[] futures = new CompletableFuture[size];
-        for (int i = 0; i < size; i++) {
-            final int index = i;
-            futures[index] = source.findAsync(World.class, context, 1 + random.nextInt(10000)).thenAccept(v -> worlds[index] = v.randomNumber(1 + random.nextInt(10000)));
-        }
-        return CompletableFuture.allOf(futures).thenCompose(v -> source.updateAsync(context, World.sort(worlds))).thenApply(v -> worlds);
-    }
-
-    @RestMapping(name = "fortunes")
-    public CompletableFuture<HttpResult<String>> queryFortunes() {
-        return source.queryListAsync(Fortune.class).thenApply((fortunes) -> {
-            fortunes.add(new Fortune(0, "Additional fortune added at request time."));
-            String html = FortunesTemplate.template(Fortune.sort(fortunes)).render().toString();
-            return new HttpResult("text/html; charset=utf-8", html);
-        });
-    }
-
-    @RestMapping(name = "cached-worlds")
-    public CachedWorld[] cachedWorlds(int q) {
-        if (cache == null) {
-            synchronized (this) {
-                if (cache == null) cache = new WorldEntityCache(source);
-            }
-        }
-        final int size = Math.min(500, Math.max(1, q));
-        final CachedWorld[] worlds = new CachedWorld[size];
-        final ThreadLocalRandom random = ThreadLocalRandom.current();
-        for (int i = 0; i < size; i++) {
-            worlds[i] = cache.findAt(random.nextInt(10000));
-        }
-        return worlds;
-    }
-
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkalex.benchmark;
+
+import java.util.Random;
+import java.util.concurrent.*;
+import javax.annotation.Resource;
+import org.redkale.net.ChannelContext;
+import org.redkale.net.http.*;
+import org.redkale.service.AbstractService;
+import org.redkale.source.*;
+import org.redkalex.benchmark.CachedWorld.WorldEntityCache;
+
+/**
+ *
+ * @author zhangjx
+ */
+@RestService(name = " ", repair = false)
+public class Service extends AbstractService {
+
+    private static final byte[] helloBytes = "Hello, world!".getBytes();
+
+    private final ThreadLocal<RedRandom> rands = ThreadLocal.withInitial(() -> new RedRandom());
+
+    @Resource
+    private DataSource source;
+
+    private WorldEntityCache cache;
+
+    @RestMapping(name = "plaintext")
+    public byte[] getHelloBytes() {
+        return helloBytes;
+    }
+
+    @RestMapping(name = "json")
+    public Message getHelloMessage() {
+        return Message.create("Hello, World!");
+    }
+
+    @RestMapping(name = "db")
+    public CompletableFuture<World> findWorldAsync(ChannelContext context) {
+        return source.findAsync(World.class, context, 1 + randomInt(ThreadLocalRandom.current(), 10000));
+    }
+
+    @RestMapping(name = "queries")
+    public CompletableFuture<World[]> queryWorldAsync(ChannelContext context, int q) {
+        final int size = Math.min(500, Math.max(1, q));
+        final World[] worlds = new World[size];
+        final Random random = rands.get();
+        final CompletableFuture[] futures = new CompletableFuture[size];
+        for (int i = 0; i < size; i++) {
+            final int index = i;
+            futures[index] = source.findAsync(World.class, context, 1 + randomInt(random, 10000)).thenAccept(v -> worlds[index] = v);
+        }
+        return CompletableFuture.allOf(futures).thenApply(v -> worlds);
+    }
+
+    @RestMapping(name = "updates")
+    public CompletableFuture<World[]> updateWorldAsync(ChannelContext context, int q) {
+        final int size = Math.min(500, Math.max(1, q));
+        final World[] worlds = new World[size];
+        final Random random = ThreadLocalRandom.current();
+        final CompletableFuture[] futures = new CompletableFuture[size];
+        for (int i = 0; i < size; i++) {
+            final int index = i;
+            futures[index] = source.findAsync(World.class, context, 1 + randomInt(random, 10000)).thenAccept(v -> worlds[index] = v.randomNumber(1 + randomInt(random, 10000)));
+        }
+        return CompletableFuture.allOf(futures).thenCompose(v -> source.updateAsync(context, World.sort(worlds))).thenApply(v -> worlds);
+    }
+
+    @RestMapping(name = "fortunes")
+    public CompletableFuture<HttpResult<String>> queryFortunes() {
+        return source.queryListAsync(Fortune.class).thenApply((fortunes) -> {
+            fortunes.add(new Fortune(0, "Additional fortune added at request time."));
+            String html = FortunesTemplate.template(Fortune.sort(fortunes)).render().toString();
+            return new HttpResult("text/html; charset=utf-8", html);
+        });
+    }
+
+    @RestMapping(name = "cached-worlds")
+    public CachedWorld[] cachedWorlds(int q) {
+        if (cache == null) {
+            synchronized (this) {
+                if (cache == null) cache = new WorldEntityCache(source);
+            }
+        }
+        final int size = Math.min(500, Math.max(1, q));
+        return cache.random(ThreadLocalRandom.current(), size);
+    }
+
+    protected int randomInt(Random rand, int bound) {
+        long s = rand.nextLong();
+        return (int) ((s < 0 ? -s : s) % bound);
+    }
+
+}