Explorar el Código

Update Wildfly to use ZGC and a larger heap and formatting (#5279)

Cody Lerum hace 5 años
padre
commit
afedba1806

+ 29 - 34
frameworks/Java/wildfly-ee/src/main/java/com/techempower/ee7/model/Fortune.java

@@ -9,52 +9,47 @@ import javax.persistence.Id;
 import javax.persistence.NamedQuery;
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Size;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
 
 @NamedQuery(name = "allFortunes", query = "SELECT f FROM Fortune f")
-@XmlRootElement
 @Entity
 public class Fortune implements Comparable<Fortune>, Serializable {
 
-  private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-  private int id;
-  private String message;
+    private int id;
+    private String message;
 
-  public Fortune() {
+    public Fortune() {
 
-  }
+    }
 
-  public Fortune(int id, String message) {
-    this.id = id;
-    this.message = message;
-  }
+    public Fortune(int id, String message) {
+        this.id = id;
+        this.message = message;
+    }
 
-  @XmlElement
-  @Id
-  @GeneratedValue(strategy = GenerationType.AUTO)
-  public int getId() {
-    return id;
-  }
+    @Id
+    @GeneratedValue(strategy = GenerationType.AUTO)
+    public int getId() {
+        return id;
+    }
 
-  public void setId(int id) {
-    this.id = id;
-  }
+    public void setId(int id) {
+        this.id = id;
+    }
 
-  @XmlElement
-  @NotNull
-  @Size(max = 2048)
-  public String getMessage() {
-    return message;
-  }
+    @NotNull
+    @Size(max = 2048)
+    public String getMessage() {
+        return message;
+    }
 
-  public void setMessage(String message) {
-    this.message = message;
-  }
+    public void setMessage(String message) {
+        this.message = message;
+    }
 
-  @Override
-  public int compareTo(Fortune o) {
-    return message.compareTo(o.getMessage());
-  }
+    @Override
+    public int compareTo(Fortune o) {
+        return message.compareTo(o.getMessage());
+    }
 }

+ 18 - 23
frameworks/Java/wildfly-ee/src/main/java/com/techempower/ee7/model/World.java

@@ -7,36 +7,31 @@ import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.validation.constraints.NotNull;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
 
-@XmlRootElement
 @Entity
 public class World implements Serializable {
 
-  private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-  private int id;
-  private int randomNumber;
+    private int id;
+    private int randomNumber;
 
-  @XmlElement
-  @Id
-  @GeneratedValue(strategy = GenerationType.AUTO)
-  public int getId() {
-    return id;
-  }
+    @Id
+    @GeneratedValue(strategy = GenerationType.AUTO)
+    public int getId() {
+        return id;
+    }
 
-  public void setId(int id) {
-    this.id = id;
-  }
+    public void setId(int id) {
+        this.id = id;
+    }
 
-  @XmlElement
-  @NotNull
-  public int getRandomNumber() {
-    return randomNumber;
-  }
+    @NotNull
+    public int getRandomNumber() {
+        return randomNumber;
+    }
 
-  public void setRandomNumber(int randomNumber) {
-    this.randomNumber = randomNumber;
-  }
+    public void setRandomNumber(int randomNumber) {
+        this.randomNumber = randomNumber;
+    }
 }

+ 2 - 1
frameworks/Java/wildfly-ee/src/main/java/com/techempower/ee7/rest/MyApplication.java

@@ -4,4 +4,5 @@ import javax.ws.rs.ApplicationPath;
 import javax.ws.rs.core.Application;
 
 @ApplicationPath("rest")
-public class MyApplication extends Application {}
+public class MyApplication extends Application {
+}

+ 18 - 18
frameworks/Java/wildfly-ee/src/main/java/com/techempower/ee7/tests/Fortunes.java

@@ -15,22 +15,22 @@ import com.techempower.ee7.model.Fortune;
 @Named
 public class Fortunes {
 
-  private static final int ADDITIONAL_FORTUNE_ID = 0;
-  private static final String ADDITIONAL_FORTUNE_CONTENT = "Additional fortune added at request time.";
-  
-  @Inject
-  private EntityManager em;
-
-  private List<Fortune> data;
-
-  @PostConstruct
-  private void postConstruct() {
-    data = em.createNamedQuery("allFortunes", Fortune.class).getResultList();
-    data.add(new Fortune(ADDITIONAL_FORTUNE_ID, ADDITIONAL_FORTUNE_CONTENT));
-    Collections.sort(data);
-  }
-
-  public List<Fortune> getData() {
-    return data;
-  }
+    private static final int ADDITIONAL_FORTUNE_ID = 0;
+    private static final String ADDITIONAL_FORTUNE_CONTENT = "Additional fortune added at request time.";
+
+    @Inject
+    private EntityManager em;
+
+    private List<Fortune> data;
+
+    @PostConstruct
+    private void postConstruct() {
+        data = em.createNamedQuery("allFortunes", Fortune.class).getResultList();
+        data.add(new Fortune(ADDITIONAL_FORTUNE_ID, ADDITIONAL_FORTUNE_CONTENT));
+        Collections.sort(data);
+    }
+
+    public List<Fortune> getData() {
+        return data;
+    }
 }

+ 14 - 18
frameworks/Java/wildfly-ee/src/main/java/com/techempower/ee7/tests/JsonSerialization.java

@@ -4,32 +4,28 @@ import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
 
 @Path("/json")
 public class JsonSerialization {
 
-  private static final String MESSAGE = "Hello, World!";
+    private static final String MESSAGE = "Hello, World!";
 
-  @GET
-  @Produces(MediaType.APPLICATION_JSON)
-  public JsonResponse get() {
-    return new JsonResponse(MESSAGE);
-  }
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    public JsonResponse get() {
+        return new JsonResponse(MESSAGE);
+    }
 
-  @XmlRootElement
-  public class JsonResponse {
+    public class JsonResponse {
 
-    private final String message;
+        private final String message;
 
-    public JsonResponse(String message) {
-      this.message = message;
-    }
+        public JsonResponse(String message) {
+            this.message = message;
+        }
 
-    @XmlElement
-    public String getMessage() {
-      return message;
+        public String getMessage() {
+            return message;
+        }
     }
-  }
 }

+ 15 - 16
frameworks/Java/wildfly-ee/src/main/java/com/techempower/ee7/tests/MultipleQueries.java

@@ -17,25 +17,24 @@ import com.techempower.ee7.util.Helpers;
 @Path("/queries")
 public class MultipleQueries {
 
-  private static final int MIN_QUERIES = 1;
-  private static final int MAX_QUERIES = 500;
+    private static final int MIN_QUERIES = 1;
+    private static final int MAX_QUERIES = 500;
 
-  @Inject
-  private EntityManager em;
+    @Inject
+    private EntityManager em;
 
-  @GET
-  @Produces(MediaType.APPLICATION_JSON)
-  public List<World> get(@QueryParam("queries") final String queries) {
-    final int iterations =
-        Helpers.boundedIntegerFromNullableString(queries, MIN_QUERIES, MAX_QUERIES);
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    public List<World> get(@QueryParam("queries") final String queries) {
+        final int iterations = Helpers.boundedIntegerFromNullableString(queries, MIN_QUERIES, MAX_QUERIES);
 
-    List<World> result = new ArrayList<>(iterations);
+        List<World> result = new ArrayList<>(iterations);
 
-    for (int i = 0; i < iterations; i++) {
-      int id = Helpers.randomWorldId();
-      result.add(em.find(World.class, id));
-    }
+        for (int i = 0; i < iterations; i++) {
+            int id = Helpers.randomWorldId();
+            result.add(em.find(World.class, id));
+        }
 
-    return result;
-  }
+        return result;
+    }
 }

+ 16 - 17
frameworks/Java/wildfly-ee/src/main/java/com/techempower/ee7/tests/PlainText.java

@@ -7,25 +7,24 @@ import javax.ws.rs.core.MediaType;
 
 @Path("/plaintext")
 public class PlainText {
-  private static final String MESSAGE = "Hello, World!";
+    private static final String MESSAGE = "Hello, World!";
 
-  @GET
-  @Produces(MediaType.TEXT_PLAIN)
-  public String get() {
-    return MESSAGE;
-  }
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public String get() {
+        return MESSAGE;
+    }
 
-  @GET
-  @Path("hi")
-  public String get2() {
-    return "Hello WildFly!";
-  }
+    @GET
+    @Path("hi")
+    public String get2() {
+        return "Hello WildFly!";
+    }
 
+    @GET
+    @Path("/bye")
+    public String get3() {
+        return "Bye WildFly!";
+    }
 
-  @GET
-  @Path("/bye")
-  public String get3() {
-    return "Bye WildFly!";
-  }
-  
 }

+ 7 - 8
frameworks/Java/wildfly-ee/src/main/java/com/techempower/ee7/tests/SingleQuery.java

@@ -13,13 +13,12 @@ import com.techempower.ee7.util.Helpers;
 @Path("/db")
 public class SingleQuery {
 
-  @Inject
-  private EntityManager em;
+    @Inject
+    private EntityManager em;
 
-  @GET
-  @Produces(MediaType.APPLICATION_JSON)
-  public World get() {
-    int id = Helpers.randomWorldId();
-    return em.find(World.class, id);
-  }
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    public World get() {
+        return em.find(World.class, Helpers.randomWorldId());
+    }
 }

+ 5 - 16
frameworks/Java/wildfly-ee/src/main/java/com/techempower/ee7/tests/TestActions.java

@@ -1,8 +1,5 @@
 package com.techempower.ee7.tests;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Inject;
 import javax.persistence.EntityManager;
@@ -18,18 +15,10 @@ public class TestActions {
     private EntityManager em;
 
     @Transactional
-    public List<World> updateWorlds(int iterations) {
-        List<World> worlds = new ArrayList<>(iterations);
-
-        for (int i = 0; i < iterations; i++) {
-            int id = Helpers.randomWorldId();
-            worlds.add(em.find(World.class, id));
-        }
-
-        for (World w : worlds) {
-            w.getRandomNumber(); // Mandatory to read for the test
-            w.setRandomNumber(Helpers.randomWorldId());
-        }
-        return worlds;
+    public World updateWorld(int id) {
+        World w = em.find(World.class, id);
+        w.getRandomNumber(); // Mandatory to read for the test
+        w.setRandomNumber(Helpers.randomWorldId());
+        return w;
     }
 }

+ 6 - 9
frameworks/Java/wildfly-ee/src/main/java/com/techempower/ee7/tests/Updates.java

@@ -1,5 +1,6 @@
 package com.techempower.ee7.tests;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import javax.inject.Inject;
@@ -25,15 +26,11 @@ public class Updates {
     @Produces(MediaType.APPLICATION_JSON)
     public List<World> update(@QueryParam("queries") final String queries) {
         final int iterations = Helpers.boundedIntegerFromNullableString(queries, MIN_QUERIES, MAX_QUERIES);
-        int attempts = 0;
-        while (attempts < 10) {
-            try {
-                return actions.updateWorlds(iterations);
-            }
-            catch (Exception e) {
-                attempts++;
-            }
+
+        final List<World> worlds = new ArrayList<>(iterations);
+        for (int i = 0; i < iterations; i++) {
+            worlds.add(actions.updateWorld(Helpers.randomWorldId()));
         }
-        throw new RuntimeException(String.format("Unable to update after %s attempts", attempts));
+        return worlds;
     }
 }

+ 2 - 2
frameworks/Java/wildfly-ee/src/main/java/com/techempower/ee7/util/Helpers.java

@@ -6,7 +6,7 @@ public class Helpers {
 
     /**
      * Random number between 1 and 10,000
-     * 
+     *
      * @return
      */
     public static int randomWorldId() {
@@ -15,7 +15,7 @@ public class Helpers {
 
     /**
      * Returns a bounded integer. min if null or less than bounds. max if greater than bounds
-     * 
+     *
      * @param value
      * @param min
      * @param max

+ 2 - 2
frameworks/Java/wildfly-ee/src/main/resources/META-INF/persistence.xml

@@ -5,8 +5,8 @@
 		<jta-data-source>java:jboss/datasources/helloWorld</jta-data-source>
 		<shared-cache-mode>NONE</shared-cache-mode>
 		<properties>
-			<property name="hibernate.jdbc.batch_size" value="100" />
+			<property name="hibernate.hbm2ddl.auto" value="none"/>
 			<property name="hibernate.dialect" value="MySQL57InnoDB" />
 		</properties>
 	</persistence-unit>
-</persistence>
+</persistence>

+ 1 - 1
frameworks/Java/wildfly-ee/wildfly-ee.dockerfile

@@ -1,6 +1,6 @@
 FROM adoptopenjdk/maven-openjdk13:latest as maven
 ENV wfly=18.0.1.Final
-ENV JAVA_OPTS="-Djava.net.preferIPv4Stack=true -Xms2g -Xmx2g -XX:MaxGCPauseMillis=50"
+ENV JAVA_OPTS="-Djava.net.preferIPv4Stack=true -Xmx24g -XX:+UnlockExperimentalVMOptions -XX:+UseZGC"
 WORKDIR /wildfly
 COPY src src
 COPY pom.xml pom.xml