Skip to content

Commit 36a5f38

Browse files
Artem LabazinArtem Labazin
Artem Labazin
authored and
Artem Labazin
committed
Add RPC methods and speed up the server
1 parent c950632 commit 36a5f38

File tree

37 files changed

+898
-203
lines changed

37 files changed

+898
-203
lines changed

CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2222
- Turn on checkstyle JavaDocs module.
2323
- Add updates to the protocol, like new `ControlMessage`.
2424

25+
## [1.6.4](https://github.com/appulse-projects/encon-java/releases/tag/1.6.4) - 2018-09-14
26+
27+
### Added
28+
29+
- `Mailbox.call()` and `Mailbox.receiveRemoteProcedureResult()`, a remote procedure call functionality;
30+
- `Mailbox.exit()` without arguments, for normal mailbox exiting;
31+
- Benchmark's `README.md` section about how to run single/group of becnhmark(s).
32+
33+
### Changed
34+
35+
- Tuned server and client `Netty`'s settings, especially its `WRITE_BUFFER_WATER_MARK` option;
36+
- Now, use `channel.eventLoop().execute(Runnable)` for server's responses, instead of creating composite buffer and single `writeAndFlush` call;
37+
- Benchmark's results;
38+
- Fix samples `pom.xml` files.
39+
2540
## [1.6.3](https://github.com/appulse-projects/encon-java/releases/tag/1.6.3) - 2018-09-11
2641

2742
### Changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ $> mvn clean compile
4646
[INFO] ------------------------------------------------------------------------
4747
[INFO] Reactor Summary:
4848
[INFO]
49-
[INFO] encon 1.6.3 ........................................ SUCCESS [ 1.210 s]
49+
[INFO] encon 1.6.4 ........................................ SUCCESS [ 1.210 s]
5050
[INFO] encon-common ....................................... SUCCESS [ 25.693 s]
5151
[INFO] encon-terms ........................................ SUCCESS [ 27.517 s]
5252
[INFO] encon-config ....................................... SUCCESS [ 18.707 s]
@@ -64,7 +64,7 @@ $> mvn clean compile
6464
[INFO] handler-advanced ................................... SUCCESS [ 11.289 s]
6565
[INFO] load-config ........................................ SUCCESS [ 3.725 s]
6666
[INFO] load-config-spring ................................. SUCCESS [ 6.420 s]
67-
[INFO] benchmark 1.6.3 .................................... SUCCESS [ 5.594 s]
67+
[INFO] benchmark 1.6.4 .................................... SUCCESS [ 5.594 s]
6868
[INFO] ------------------------------------------------------------------------
6969
[INFO] BUILD SUCCESS
7070
[INFO] ------------------------------------------------------------------------

benchmark/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ limitations under the License.
2525
<parent>
2626
<groupId>io.appulse.encon</groupId>
2727
<artifactId>encon-parent</artifactId>
28-
<version>1.6.3</version>
28+
<version>1.6.4</version>
2929
</parent>
3030

3131
<artifactId>benchmark</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/*
2+
* Copyright 2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appulse.encon.benchmark;
18+
19+
import static io.appulse.encon.terms.Erlang.binary;
20+
import static java.lang.Boolean.TRUE;
21+
import static java.util.concurrent.TimeUnit.SECONDS;
22+
import static org.openjdk.jmh.annotations.Level.Trial;
23+
import static org.openjdk.jmh.annotations.Mode.Throughput;
24+
import static org.openjdk.jmh.annotations.Scope.Benchmark;
25+
26+
import java.util.stream.IntStream;
27+
28+
import io.appulse.encon.Node;
29+
import io.appulse.encon.Nodes;
30+
import io.appulse.encon.config.NodeConfig;
31+
import io.appulse.encon.config.ServerConfig;
32+
import io.appulse.encon.mailbox.Mailbox;
33+
import io.appulse.encon.terms.ErlangTerm;
34+
import io.appulse.encon.terms.type.ErlangPid;
35+
36+
import org.openjdk.jmh.annotations.Benchmark;
37+
import org.openjdk.jmh.annotations.BenchmarkMode;
38+
import org.openjdk.jmh.annotations.Measurement;
39+
import org.openjdk.jmh.annotations.OutputTimeUnit;
40+
import org.openjdk.jmh.annotations.Setup;
41+
import org.openjdk.jmh.annotations.State;
42+
import org.openjdk.jmh.annotations.TearDown;
43+
import org.openjdk.jmh.annotations.Threads;
44+
import org.openjdk.jmh.annotations.Warmup;
45+
import org.openjdk.jmh.infra.Blackhole;
46+
import org.openjdk.jmh.infra.ThreadParams;
47+
48+
/**
49+
*
50+
* @since 1.6.3
51+
* @author Artem Labazin
52+
*/
53+
@State(Benchmark)
54+
@OutputTimeUnit(SECONDS)
55+
@Warmup(iterations = 10)
56+
@BenchmarkMode(Throughput)
57+
@Measurement(iterations = 20)
58+
public class Encon_Node2NodeBenchmarks_1WorkerThreads {
59+
60+
Node serverNode;
61+
62+
Mailbox serverMailbox;
63+
64+
ErlangPid serverMailboxPid;
65+
66+
Thread serverThread;
67+
68+
ErlangTerm data;
69+
70+
Node clientNode;
71+
72+
Mailbox[] clientMailboxes;
73+
74+
@Setup(Trial)
75+
public void setup () throws Exception {
76+
serverNode = Nodes.singleNode("node-server-" + System.nanoTime(), NodeConfig.builder()
77+
.shortName(TRUE)
78+
.server(ServerConfig.builder()
79+
.bossThreads(1)
80+
.workerThreads(1)
81+
.build()
82+
)
83+
.build()
84+
);
85+
86+
serverMailbox = serverNode.mailbox().build();
87+
serverMailboxPid = serverMailbox.getPid();
88+
data = binary(new byte[] { 1, 2, 3, 4, 5 });
89+
90+
serverThread = new Thread(() -> {
91+
try {
92+
while (!java.lang.Thread.interrupted()) {
93+
ErlangTerm payload = serverMailbox.receive().getBody();
94+
serverMailbox.send(payload.asPid(), data);
95+
}
96+
} catch (Throwable ex) {
97+
}
98+
});
99+
serverThread.start();
100+
101+
clientNode = Nodes.singleNode("node-client-" + System.nanoTime(), NodeConfig.builder().shortName(TRUE)
102+
.server(ServerConfig.builder()
103+
.bossThreads(1)
104+
.workerThreads(8)
105+
.build()
106+
)
107+
.build());
108+
109+
clientMailboxes = IntStream.range(0, 8)
110+
.boxed()
111+
.map(it -> clientNode.mailbox().build())
112+
.toArray(Mailbox[]::new);
113+
}
114+
115+
@TearDown(Trial)
116+
public void tearDown () {
117+
for (Mailbox mailbox : clientMailboxes) {
118+
mailbox.close();
119+
}
120+
clientNode.close();
121+
122+
serverMailbox.close();
123+
serverNode.close();
124+
125+
serverThread.interrupt();
126+
}
127+
128+
@Threads(1)
129+
@Benchmark
130+
public void client_1 (ThreadParams thredParams, Blackhole blackHole) throws Exception {
131+
Mailbox mailbox = clientMailboxes[0];
132+
mailbox.send(serverMailboxPid, mailbox.getPid());
133+
blackHole.consume(mailbox.receive());
134+
}
135+
136+
@Threads(2)
137+
@Benchmark
138+
public void clients_2 (ThreadParams thredParams, Blackhole blackHole) throws Exception {
139+
Mailbox mailbox = clientMailboxes[thredParams.getThreadIndex()];
140+
mailbox.send(serverMailboxPid, mailbox.getPid());
141+
blackHole.consume(mailbox.receive());
142+
}
143+
144+
@Threads(4)
145+
@Benchmark
146+
public void clients_4 (ThreadParams thredParams, Blackhole blackHole) throws Exception {
147+
Mailbox mailbox = clientMailboxes[thredParams.getThreadIndex()];
148+
mailbox.send(serverMailboxPid, mailbox.getPid());
149+
blackHole.consume(mailbox.receive());
150+
}
151+
152+
@Threads(8)
153+
@Benchmark
154+
public void clients_8 (ThreadParams thredParams, Blackhole blackHole) throws Exception {
155+
Mailbox mailbox = clientMailboxes[thredParams.getThreadIndex()];
156+
mailbox.send(serverMailboxPid, mailbox.getPid());
157+
blackHole.consume(mailbox.receive());
158+
}
159+
}

benchmark/src/main/java/io/appulse/encon/benchmark/Encon_Node2NodeBenchmarks.java benchmark/src/main/java/io/appulse/encon/benchmark/Encon_Node2NodeBenchmarks_2WorkersThreads.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
@Warmup(iterations = 10)
5656
@BenchmarkMode(Throughput)
5757
@Measurement(iterations = 20)
58-
public class Encon_Node2NodeBenchmarks {
58+
public class Encon_Node2NodeBenchmarks_2WorkersThreads {
5959

6060
Node serverNode;
6161

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/*
2+
* Copyright 2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appulse.encon.benchmark;
18+
19+
import static io.appulse.encon.terms.Erlang.binary;
20+
import static java.lang.Boolean.TRUE;
21+
import static java.util.concurrent.TimeUnit.SECONDS;
22+
import static org.openjdk.jmh.annotations.Level.Trial;
23+
import static org.openjdk.jmh.annotations.Mode.Throughput;
24+
import static org.openjdk.jmh.annotations.Scope.Benchmark;
25+
26+
import java.util.stream.IntStream;
27+
28+
import io.appulse.encon.Node;
29+
import io.appulse.encon.Nodes;
30+
import io.appulse.encon.config.NodeConfig;
31+
import io.appulse.encon.config.ServerConfig;
32+
import io.appulse.encon.mailbox.Mailbox;
33+
import io.appulse.encon.terms.ErlangTerm;
34+
import io.appulse.encon.terms.type.ErlangPid;
35+
36+
import org.openjdk.jmh.annotations.Benchmark;
37+
import org.openjdk.jmh.annotations.BenchmarkMode;
38+
import org.openjdk.jmh.annotations.Measurement;
39+
import org.openjdk.jmh.annotations.OutputTimeUnit;
40+
import org.openjdk.jmh.annotations.Setup;
41+
import org.openjdk.jmh.annotations.State;
42+
import org.openjdk.jmh.annotations.TearDown;
43+
import org.openjdk.jmh.annotations.Threads;
44+
import org.openjdk.jmh.annotations.Warmup;
45+
import org.openjdk.jmh.infra.Blackhole;
46+
import org.openjdk.jmh.infra.ThreadParams;
47+
48+
/**
49+
*
50+
* @since 1.6.3
51+
* @author Artem Labazin
52+
*/
53+
@State(Benchmark)
54+
@OutputTimeUnit(SECONDS)
55+
@Warmup(iterations = 10)
56+
@BenchmarkMode(Throughput)
57+
@Measurement(iterations = 20)
58+
public class Encon_Node2NodeBenchmarks_4WorkersThreads {
59+
60+
Node serverNode;
61+
62+
Mailbox serverMailbox;
63+
64+
ErlangPid serverMailboxPid;
65+
66+
Thread serverThread;
67+
68+
ErlangTerm data;
69+
70+
Node clientNode;
71+
72+
Mailbox[] clientMailboxes;
73+
74+
@Setup(Trial)
75+
public void setup () throws Exception {
76+
serverNode = Nodes.singleNode("node-server-" + System.nanoTime(), NodeConfig.builder()
77+
.shortName(TRUE)
78+
.server(ServerConfig.builder()
79+
.bossThreads(1)
80+
.workerThreads(4)
81+
.build()
82+
)
83+
.build()
84+
);
85+
86+
serverMailbox = serverNode.mailbox().build();
87+
serverMailboxPid = serverMailbox.getPid();
88+
data = binary(new byte[] { 1, 2, 3, 4, 5 });
89+
90+
serverThread = new Thread(() -> {
91+
try {
92+
while (!java.lang.Thread.interrupted()) {
93+
ErlangTerm payload = serverMailbox.receive().getBody();
94+
serverMailbox.send(payload.asPid(), data);
95+
}
96+
} catch (Throwable ex) {
97+
}
98+
});
99+
serverThread.start();
100+
101+
clientNode = Nodes.singleNode("node-client-" + System.nanoTime(), NodeConfig.builder().shortName(TRUE)
102+
.server(ServerConfig.builder()
103+
.bossThreads(1)
104+
.workerThreads(8)
105+
.build()
106+
)
107+
.build());
108+
109+
clientMailboxes = IntStream.range(0, 8)
110+
.boxed()
111+
.map(it -> clientNode.mailbox().build())
112+
.toArray(Mailbox[]::new);
113+
}
114+
115+
@TearDown(Trial)
116+
public void tearDown () {
117+
for (Mailbox mailbox : clientMailboxes) {
118+
mailbox.close();
119+
}
120+
clientNode.close();
121+
122+
serverMailbox.close();
123+
serverNode.close();
124+
125+
serverThread.interrupt();
126+
}
127+
128+
@Threads(1)
129+
@Benchmark
130+
public void client_1 (ThreadParams thredParams, Blackhole blackHole) throws Exception {
131+
Mailbox mailbox = clientMailboxes[0];
132+
mailbox.send(serverMailboxPid, mailbox.getPid());
133+
blackHole.consume(mailbox.receive());
134+
}
135+
136+
@Threads(2)
137+
@Benchmark
138+
public void clients_2 (ThreadParams thredParams, Blackhole blackHole) throws Exception {
139+
Mailbox mailbox = clientMailboxes[thredParams.getThreadIndex()];
140+
mailbox.send(serverMailboxPid, mailbox.getPid());
141+
blackHole.consume(mailbox.receive());
142+
}
143+
144+
@Threads(4)
145+
@Benchmark
146+
public void clients_4 (ThreadParams thredParams, Blackhole blackHole) throws Exception {
147+
Mailbox mailbox = clientMailboxes[thredParams.getThreadIndex()];
148+
mailbox.send(serverMailboxPid, mailbox.getPid());
149+
blackHole.consume(mailbox.receive());
150+
}
151+
152+
@Threads(8)
153+
@Benchmark
154+
public void clients_8 (ThreadParams thredParams, Blackhole blackHole) throws Exception {
155+
Mailbox mailbox = clientMailboxes[thredParams.getThreadIndex()];
156+
mailbox.send(serverMailboxPid, mailbox.getPid());
157+
blackHole.consume(mailbox.receive());
158+
}
159+
}

0 commit comments

Comments
 (0)