Skip to content

Commit a34de71

Browse files
committed
JBTM-4014-perf-test draft
1 parent d0b3cf6 commit a34de71

File tree

5 files changed

+405
-1
lines changed

5 files changed

+405
-1
lines changed

narayana/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
<module>ArjunaJTS/jts</module>
8888
<module>ArjunaJTA/jta</module>
8989
<module>ArjunaCore/arjuna</module>
90+
<module>stm</module>
9091
<module>tools</module>
9192
</modules>
9293

@@ -175,4 +176,4 @@
175176
</dependency>
176177
</dependencies>
177178
</dependencyManagement>
178-
</project>
179+
</project>

narayana/stm/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
mvn clean package
3+
java -jar target/benchmarks.jar
4+
5+
6+
I created 3 benchmarks (see https://github.com/jbosstm/performance/pull/185):
7+
LocalJTABenchmark.benchmark: starts a JTA txn and enlists a single XAResource and commits
8+
STMBenchmark.baseLineBenchmark: adds two integers together
9+
STMBenchmark.benchmark: starts an AtomicAction and increments and decrements two integers backed by transaction memory
10+
11+
I ran the benchmarks three times taking the best result from each.
12+
13+
Comparing the the % difference between the pr/2414 and main branches I found that
14+
15+
LocalJTABenchmark.benchmark: pr/2414 is 10% better
16+
STMBenchmark.baseLineBenchmark pr/2414 is 0.2% worse
17+
STMBenchmark.benchmark: pr/2414 is 0.25% worse
18+
19+
So if the LocalJTABenchmark result is repeatable then I think 10% gain is significant.
20+

narayana/stm/pom.xml

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>org.jboss.narayana.stm</groupId>
6+
<artifactId>stm-benchmark</artifactId>
7+
<version>7.3.1.Final-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>JMH benchmarks: stm vs local jta</name>
11+
12+
<dependencies>
13+
<dependency>
14+
<groupId>org.openjdk.jmh</groupId>
15+
<artifactId>jmh-core</artifactId>
16+
<version>${jmh.version}</version>
17+
</dependency>
18+
<dependency>
19+
<groupId>org.openjdk.jmh</groupId>
20+
<artifactId>jmh-generator-annprocess</artifactId>
21+
<version>${jmh.version}</version>
22+
<scope>provided</scope>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.jboss.narayana.arjunacore</groupId>
26+
<artifactId>arjunacore</artifactId>
27+
<version>${project.version}</version>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.jboss.narayana.jta</groupId>
31+
<artifactId>jta</artifactId>
32+
<version>${project.version}</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.jboss.narayana.stm</groupId>
36+
<artifactId>stm</artifactId>
37+
<version>${project.version}</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>jakarta.transaction</groupId>
41+
<artifactId>jakarta.transaction-api</artifactId>
42+
<version>2.0.1</version>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>org.jboss</groupId>
47+
<artifactId>jboss-transaction-spi</artifactId>
48+
<version>7.6.1.Final</version>
49+
<exclusions>
50+
<exclusion>
51+
<groupId>org.jboss.logging</groupId>
52+
<artifactId>jboss-logging-spi</artifactId>
53+
</exclusion>
54+
</exclusions>
55+
</dependency>
56+
</dependencies>
57+
58+
<properties>
59+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
60+
<jmh.version>1.37</jmh.version>
61+
<javac.target>1.8</javac.target>
62+
<uberjar.name>benchmarks</uberjar.name>
63+
</properties>
64+
65+
<build>
66+
<plugins>
67+
<plugin>
68+
<groupId>org.apache.maven.plugins</groupId>
69+
<artifactId>maven-compiler-plugin</artifactId>
70+
<version>3.8.0</version>
71+
<configuration>
72+
<compilerVersion>${javac.target}</compilerVersion>
73+
<source>${javac.target}</source>
74+
<target>${javac.target}</target>
75+
</configuration>
76+
</plugin>
77+
<plugin>
78+
<groupId>org.apache.maven.plugins</groupId>
79+
<artifactId>maven-shade-plugin</artifactId>
80+
<version>3.2.1</version>
81+
<executions>
82+
<execution>
83+
<phase>package</phase>
84+
<goals>
85+
<goal>shade</goal>
86+
</goals>
87+
<configuration>
88+
<finalName>${uberjar.name}</finalName>
89+
<transformers>
90+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
91+
<mainClass>org.openjdk.jmh.Main</mainClass>
92+
</transformer>
93+
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
94+
</transformers>
95+
<filters>
96+
<filter>
97+
<!--
98+
Shading signed JARs will fail without this.
99+
http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar
100+
-->
101+
<artifact>*:*</artifact>
102+
<excludes>
103+
<exclude>META-INF/*.SF</exclude>
104+
<exclude>META-INF/*.DSA</exclude>
105+
<exclude>META-INF/*.RSA</exclude>
106+
</excludes>
107+
</filter>
108+
</filters>
109+
</configuration>
110+
</execution>
111+
</executions>
112+
</plugin>
113+
</plugins>
114+
<pluginManagement>
115+
<plugins>
116+
<plugin>
117+
<artifactId>maven-clean-plugin</artifactId>
118+
<version>2.5</version>
119+
</plugin>
120+
<plugin>
121+
<artifactId>maven-deploy-plugin</artifactId>
122+
<version>2.8.1</version>
123+
</plugin>
124+
<plugin>
125+
<artifactId>maven-install-plugin</artifactId>
126+
<version>2.5.1</version>
127+
</plugin>
128+
<plugin>
129+
<artifactId>maven-jar-plugin</artifactId>
130+
<version>2.4</version>
131+
</plugin>
132+
<plugin>
133+
<artifactId>maven-javadoc-plugin</artifactId>
134+
<version>2.9.1</version>
135+
</plugin>
136+
<plugin>
137+
<artifactId>maven-resources-plugin</artifactId>
138+
<version>2.6</version>
139+
</plugin>
140+
<plugin>
141+
<artifactId>maven-site-plugin</artifactId>
142+
<version>3.3</version>
143+
</plugin>
144+
<plugin>
145+
<artifactId>maven-source-plugin</artifactId>
146+
<version>2.2.1</version>
147+
</plugin>
148+
<plugin>
149+
<artifactId>maven-surefire-plugin</artifactId>
150+
<version>2.17</version>
151+
</plugin>
152+
</plugins>
153+
</pluginManagement>
154+
</build>
155+
</project>
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package org.jboss.narayana.stm;
2+
3+
import com.arjuna.ats.arjuna.common.CoreEnvironmentBean;
4+
import com.arjuna.ats.arjuna.common.CoreEnvironmentBeanException;
5+
import com.arjuna.common.internal.util.propertyservice.BeanPopulator;
6+
import org.openjdk.jmh.annotations.Benchmark;
7+
import org.openjdk.jmh.annotations.Fork;
8+
import org.openjdk.jmh.annotations.Level;
9+
import org.openjdk.jmh.annotations.Measurement;
10+
import org.openjdk.jmh.annotations.OutputTimeUnit;
11+
import org.openjdk.jmh.annotations.Scope;
12+
import org.openjdk.jmh.annotations.Setup;
13+
import org.openjdk.jmh.annotations.State;
14+
import org.openjdk.jmh.annotations.Warmup;
15+
16+
import javax.transaction.xa.XAException;
17+
import javax.transaction.xa.XAResource;
18+
import javax.transaction.xa.Xid;
19+
import java.lang.reflect.InvocationTargetException;
20+
import java.util.concurrent.TimeUnit;
21+
22+
public class LocalJTABenchmark {
23+
@State(Scope.Benchmark)
24+
static
25+
public class LocalJTABenchmarkState {
26+
XAResource xaResource;
27+
String connectionString;
28+
jakarta.transaction.TransactionManager tm;
29+
30+
@Setup(Level.Invocation)
31+
public void doSetup() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, CoreEnvironmentBeanException {
32+
tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
33+
if (tm == null) {
34+
throw new RuntimeException("Error - could not get transaction manager!");
35+
}
36+
// xaResource = new DummyXA(false);//state.creator.create(state.connectionString, false);
37+
xaResource = new XAResource() {
38+
@Override
39+
public void commit(Xid xid, boolean onePhase) throws XAException {
40+
}
41+
42+
@Override
43+
public void end(Xid xid, int flags) throws XAException {
44+
}
45+
46+
@Override
47+
public void forget(Xid xid) throws XAException {
48+
}
49+
50+
@Override
51+
public int getTransactionTimeout() throws XAException {
52+
return 0;
53+
}
54+
55+
@Override
56+
public boolean isSameRM(XAResource xares) throws XAException {
57+
return false;
58+
}
59+
60+
@Override
61+
public int prepare(Xid xid) throws XAException {
62+
return 0;
63+
}
64+
65+
@Override
66+
public Xid[] recover(int flag) throws XAException {
67+
return new Xid[0];
68+
}
69+
70+
@Override
71+
public void rollback(Xid xid) throws XAException {
72+
}
73+
74+
@Override
75+
public boolean setTransactionTimeout(int seconds) throws XAException {
76+
return false;
77+
}
78+
79+
@Override
80+
public void start(Xid xid, int flags) throws XAException {
81+
}
82+
};
83+
84+
BeanPopulator.getDefaultInstance(CoreEnvironmentBean.class).setNodeIdentifier("1");
85+
}
86+
}
87+
88+
@Benchmark
89+
@OutputTimeUnit(TimeUnit.SECONDS)
90+
@Fork(2)
91+
@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
92+
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
93+
public void benchmark(LocalJTABenchmarkState state) throws Exception {
94+
state.tm.begin();
95+
96+
jakarta.transaction.Transaction theTransaction = state.tm.getTransaction();
97+
98+
if (theTransaction != null) {
99+
if (!theTransaction.enlistResource(state.xaResource)) {
100+
System.err.println("Error - could not enlist resource in transaction!");
101+
state.tm.rollback();
102+
103+
System.exit(0);
104+
}
105+
106+
state.tm.commit();
107+
} else {
108+
System.err.println("Error - could not get transaction!");
109+
try {
110+
state.tm.rollback();
111+
} catch (Exception e) {
112+
System.exit(0);
113+
}
114+
}
115+
}
116+
}

0 commit comments

Comments
 (0)