Skip to content

Commit 3924b15

Browse files
redkalefranz1981
authored andcommitted
Update Cache (TechEmpower#8092)
1 parent de3b729 commit 3924b15

File tree

6 files changed

+65
-48
lines changed

6 files changed

+65
-48
lines changed

frameworks/Java/redkale/conf/application.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<application port="8585">
44

5+
<executor threads="0"/>
56
<properties>
67
<property name="system.property.redkale.http.request.pipeline.sameheaders" value="true"/>
78
<property name="system.property.redkale.http.response.header.server" value="redkale"/>

frameworks/Java/redkale/redkale-graalvm.dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ COPY pom.xml pom.xml
66
RUN mvn package -q
77

88

9-
FROM instructure/graalvm-ce:22-java17
9+
FROM ghcr.io/graalvm/graalvm-ce:ol9-java17-22.3.1
1010
WORKDIR /redkale
1111
COPY conf conf
1212
COPY --from=maven /redkale/target/redkale-benchmark-1.0.0.jar redkale-benchmark.jar
1313

1414
EXPOSE 8080
1515

16-
CMD ["java", "-server", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-XX:AutoBoxCacheMax=40000", "-DAPP_HOME=./", "-jar", "redkale-benchmark.jar"]
16+
CMD ["java", "-server", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-DAPP_HOME=./", "-jar", "redkale-benchmark.jar"]

frameworks/Java/redkale/redkale-native.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ COPY pom.xml pom.xml
66
RUN mvn package -q
77

88

9-
FROM ghcr.io/graalvm/graalvm-ce:ol9-java17-22.3.0-b2
9+
FROM ghcr.io/graalvm/graalvm-ce:ol9-java17-22.3.1
1010
RUN gu install native-image
1111
WORKDIR /redkale
1212
COPY conf conf

frameworks/Java/redkale/redkale.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ RUN mvn package -q
77

88
EXPOSE 8080
99

10-
CMD ["java", "-server", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-XX:AutoBoxCacheMax=80000", "-DAPP_HOME=./", "-jar", "/redkale/target/redkale-benchmark-1.0.0.jar"]
10+
CMD ["java", "-server", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-DAPP_HOME=./", "-jar", "/redkale/target/redkale-benchmark-1.0.0.jar"]

frameworks/Java/redkale/src/main/java/org/redkalex/benchmark/BenchmarkService.java

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77

88
import java.util.*;
99
import java.util.concurrent.*;
10-
import java.util.function.IntFunction;
1110
import java.util.stream.IntStream;
1211
import org.redkale.annotation.*;
1312
import org.redkale.net.http.*;
1413
import org.redkale.service.AbstractService;
1514
import org.redkale.source.DataSource;
16-
import org.redkale.util.AnyValue;
1715

1816
/**
1917
*
@@ -28,37 +26,30 @@ public class BenchmarkService extends AbstractService {
2826
@Resource
2927
private DataSource source;
3028

31-
private WorldCache cache;
32-
33-
@Override
34-
public void init(AnyValue conf) {
35-
this.cache = new WorldCache(source);
36-
}
37-
38-
@RestMapping(name = "plaintext")
39-
public byte[] getHelloBytes() {
29+
@RestMapping(auth = false)
30+
public byte[] plaintext() {
4031
return helloBytes;
4132
}
4233

43-
@RestMapping(name = "json")
44-
public Message getHelloMessage() {
34+
@RestMapping(auth = false)
35+
public Message json() {
4536
return new Message("Hello, World!");
4637
}
4738

48-
@RestMapping(name = "db")
49-
public CompletableFuture<World> findWorldAsync() {
39+
@RestMapping(auth = false)
40+
public CompletableFuture<World> db() {
5041
return source.findAsync(World.class, ThreadLocalRandom.current().nextInt(10000) + 1);
5142
}
5243

53-
@RestMapping(name = "queries")
54-
public CompletableFuture<List<World>> queryWorldAsync(int q) {
44+
@RestMapping(auth = false)
45+
public CompletableFuture<List<World>> queries(int q) {
5546
int size = Math.min(500, Math.max(1, q));
5647
IntStream ids = ThreadLocalRandom.current().ints(size, 1, 10001);
5748
return source.findsListAsync(World.class, ids.boxed());
5849
}
5950

60-
@RestMapping(name = "updates")
61-
public CompletableFuture<List<World>> updateWorldAsync(int q) {
51+
@RestMapping(auth = false)
52+
public CompletableFuture<List<World>> updates(int q) {
6253
int size = Math.min(500, Math.max(1, q));
6354
IntStream ids = ThreadLocalRandom.current().ints(size, 1, 10001);
6455
int[] newNumbers = ThreadLocalRandom.current().ints(size, 1, 10001).toArray();
@@ -67,38 +58,19 @@ public CompletableFuture<List<World>> updateWorldAsync(int q) {
6758
.thenApply(v -> words));
6859
}
6960

70-
@RestMapping(name = "fortunes")
71-
public CompletableFuture<HttpScope> queryFortunes() {
61+
@RestMapping(auth = false)
62+
public CompletableFuture<HttpScope> fortunes() {
7263
return source.queryListAsync(Fortune.class).thenApply(fortunes -> {
7364
fortunes.add(new Fortune(0, "Additional fortune added at request time."));
7465
Collections.sort(fortunes);
7566
return HttpScope.refer("").referObj(fortunes);
7667
});
7768
}
7869

79-
@RestMapping(name = "cached-worlds")
80-
public World[] cachedWorlds(int q) {
70+
@RestMapping(name = "cached-worlds", auth = false)
71+
public CachedWorld[] cachedWorlds(int q) {
8172
int size = Math.min(500, Math.max(1, q));
82-
return cache.random(size);
83-
}
84-
85-
static class WorldCache {
86-
87-
private final IntFunction<World[]> arrayFunc = c -> new World[c];
88-
89-
private final World[] array;
90-
91-
private final IntFunction<World> mapFunc;
92-
93-
public WorldCache(DataSource source) {
94-
List<World> list = source.queryList(World.class);
95-
this.array = list.toArray(new World[list.size()]);
96-
this.mapFunc = c -> array[c];
97-
}
98-
99-
public World[] random(int size) {
100-
IntStream ids = ThreadLocalRandom.current().ints(size, 0, 10000);
101-
return ids.mapToObj(mapFunc).toArray(arrayFunc);
102-
}
73+
IntStream ids = ThreadLocalRandom.current().ints(size, 1, 10001);
74+
return source.finds(CachedWorld.class, ids.boxed());
10375
}
10476
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
*
3+
*/
4+
package org.redkalex.benchmark;
5+
6+
import org.redkale.convert.json.JsonConvert;
7+
import org.redkale.persistence.*;
8+
9+
/**
10+
*
11+
* @author zhangjx
12+
*/
13+
@Entity
14+
@Table(name = "world")
15+
@Cacheable(direct = true, continuousid = true)
16+
public final class CachedWorld {
17+
18+
@Id
19+
private int id;
20+
21+
private int randomNumber;
22+
23+
public int getId() {
24+
return id;
25+
}
26+
27+
public void setId(int id) {
28+
this.id = id;
29+
}
30+
31+
public int getRandomNumber() {
32+
return randomNumber;
33+
}
34+
35+
public void setRandomNumber(int randomNumber) {
36+
this.randomNumber = randomNumber;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return JsonConvert.root().convertTo(this);
42+
}
43+
44+
}

0 commit comments

Comments
 (0)