-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0bd81b9
commit 7c65bad
Showing
6 changed files
with
259 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?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>com.meteormsg</groupId> | ||
<artifactId>meteor-parent</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
|
||
<artifactId>benchmarks</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
|
||
<jmh.version>1.37</jmh.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.meteormsg</groupId> | ||
<artifactId>meteor-core</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.meteormsg</groupId> | ||
<artifactId>meteor-common</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.meteormsg.transport</groupId> | ||
<artifactId>meteor-jedis</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.openjdk.jmh</groupId> | ||
<artifactId>jmh-core</artifactId> | ||
<version>${jmh.version}</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/org.openjdk.jmh/jmh-generator-annprocess --> | ||
<dependency> | ||
<groupId>org.openjdk.jmh</groupId> | ||
<artifactId>jmh-generator-annprocess</artifactId> | ||
<version>${jmh.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
<configuration> | ||
<source>17</source> | ||
<target>17</target> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>org.openjdk.jmh</groupId> | ||
<artifactId>jmh-generator-annprocess</artifactId> | ||
<version>${jmh.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.2.0</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<finalName>benchmarks</finalName> | ||
<transformers> | ||
<transformer | ||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>org.openjdk.jmh.Main</mainClass> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cd target/ | ||
java -jar benchmarks.jar -rf json |
25 changes: 25 additions & 0 deletions
25
benchmarks/src/main/java/com/meteormsg/benchmarks/MeteorBench.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.meteormsg.benchmarks; | ||
|
||
import org.openjdk.jmh.annotations.*; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@BenchmarkMode({Mode.All}) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
@State(Scope.Thread) | ||
public class MeteorBench { | ||
|
||
public static void main(String[] args) throws RunnerException { | ||
Options options = new OptionsBuilder() | ||
.include(SimpleIncrement.class.getSimpleName()) | ||
.include(ScoresWithMaps.class.getSimpleName()) | ||
.forks(1) | ||
.build(); | ||
|
||
new Runner(options).run(); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
benchmarks/src/main/java/com/meteormsg/benchmarks/ScoresWithMaps.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.meteormsg.benchmarks; | ||
|
||
import com.meteormsg.base.RpcOptions; | ||
import com.meteormsg.base.defaults.LoopbackTransport; | ||
import com.meteormsg.core.Meteor; | ||
import org.openjdk.jmh.annotations.*; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@BenchmarkMode({Mode.All}) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
@State(Scope.Thread) | ||
public class ScoresWithMaps { | ||
|
||
private Meteor meteor; | ||
private PersonalScores scoreboardStub; | ||
|
||
@Param({"1", "10", "50"}) // Example parameter values | ||
private int workerThreads; | ||
|
||
@Setup | ||
public void setup() { | ||
System.out.println("workerThreads: " + workerThreads); | ||
RpcOptions rpcOptions = new RpcOptions(); | ||
rpcOptions.setExecutorThreads(workerThreads); | ||
meteor = new Meteor(new LoopbackTransport(), rpcOptions); | ||
meteor.registerImplementation(new ScoreboardImplementation(), "parkour-leaderboard"); | ||
scoreboardStub = meteor.registerProcedure(PersonalScores.class, "parkour-leaderboard"); | ||
} | ||
|
||
@TearDown | ||
public void tearDown() throws IOException { | ||
meteor.stop(); | ||
} | ||
|
||
@Benchmark | ||
public void benchmarkMethod() { | ||
scoreboardStub.incrementFor("player1"); | ||
} | ||
|
||
public interface PersonalScores { | ||
HashMap<String, Integer> getScores(); | ||
HashMap<String, Integer> incrementFor(String name); | ||
} | ||
|
||
public static class ScoreboardImplementation implements PersonalScores { | ||
private HashMap<String, Integer> scores = new HashMap<>(); | ||
|
||
@Override | ||
public HashMap<String, Integer> getScores() { | ||
return scores; | ||
} | ||
|
||
@Override | ||
public HashMap<String, Integer> incrementFor(String name) { | ||
if (scores.containsKey(name)) { | ||
scores.put(name, scores.get(name) + 1); | ||
} else { | ||
scores.put(name, 1); | ||
} | ||
return scores; | ||
} | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
benchmarks/src/main/java/com/meteormsg/benchmarks/SimpleIncrement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.meteormsg.benchmarks; | ||
|
||
import com.meteormsg.base.RpcOptions; | ||
import com.meteormsg.base.defaults.LoopbackTransport; | ||
import com.meteormsg.core.Meteor; | ||
import org.openjdk.jmh.annotations.*; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@BenchmarkMode({Mode.All}) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
@State(Scope.Thread) | ||
public class SimpleIncrement { | ||
|
||
private Meteor meteor; | ||
private Scoreboard scoreboardStub; | ||
|
||
@Param({"1", "10", "50"}) // Example parameter values | ||
private int workerThreads; | ||
|
||
@Setup | ||
public void setup() { | ||
System.out.println("workerThreads: " + workerThreads); | ||
RpcOptions rpcOptions = new RpcOptions(); | ||
rpcOptions.setExecutorThreads(workerThreads); | ||
meteor = new Meteor(new LoopbackTransport(), rpcOptions); | ||
meteor.registerImplementation(new ScoreboardImplementation(), "parkour-leaderboard"); | ||
scoreboardStub = meteor.registerProcedure(Scoreboard.class, "parkour-leaderboard"); | ||
} | ||
|
||
@TearDown | ||
public void tearDown() throws IOException { | ||
meteor.stop(); | ||
} | ||
|
||
@Benchmark | ||
public void benchmarkMethod() { | ||
scoreboardStub.incrementScore(); | ||
} | ||
|
||
public interface Scoreboard { | ||
int incrementScore(); | ||
int getScore(); | ||
} | ||
|
||
public static class ScoreboardImplementation implements Scoreboard { | ||
private Integer score = 0; | ||
|
||
@Override | ||
public int incrementScore() { | ||
return ++score; | ||
} | ||
|
||
@Override | ||
public int getScore() { | ||
return score; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters