Skip to content

Commit 78e1380

Browse files
committed
refactor: update load test implementation to use DatabaseWrapper and enhance parameters
wip
1 parent 15bb630 commit 78e1380

File tree

8 files changed

+277
-419
lines changed

8 files changed

+277
-419
lines changed

e2e-perf/src/test/java/com/arcadedb/test/performance/SingleLocalhostServerSimpleLoadTestIT.java

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.arcadedb.test.performance;
22

3-
import com.arcadedb.test.support.LocalhostDatabaseWrapper;
3+
import com.arcadedb.test.support.DatabaseWrapper;
44
import io.micrometer.core.instrument.Metrics;
55
import io.micrometer.core.instrument.logging.LoggingMeterRegistry;
66
import io.micrometer.core.instrument.logging.LoggingRegistryConfig;
@@ -16,6 +16,8 @@
1616

1717
import java.io.IOException;
1818
import java.time.Duration;
19+
import java.time.LocalDateTime;
20+
import java.time.format.DateTimeFormatter;
1921
import java.util.concurrent.ExecutorService;
2022
import java.util.concurrent.Executors;
2123
import java.util.concurrent.TimeUnit;
@@ -82,39 +84,67 @@ public void tearDown() {
8284
@DisplayName("Single server load test")
8385
void singleServerLoadTest() throws InterruptedException, IOException {
8486

85-
LocalhostDatabaseWrapper db = new LocalhostDatabaseWrapper(idSupplier);
87+
String host = "localhost"; // Assuming localhost for the database connection
88+
int port = 2480; // Default ArcadeDB port
89+
DatabaseWrapper db = new DatabaseWrapper(host, port, idSupplier);
8690
db.createDatabase();
8791
db.createSchema();
8892

8993
// Parameters for the test
90-
final int numOfThreads = 5;
91-
final int numOfUsers = 1000000;
92-
final int numOfPhotos = 0;
93-
final int numOfFriendship = 0;
94+
final int numOfThreads = 5; //number of threads to use to insert users and photos
95+
final int numOfUsers = 200000; // Each thread will create 200000 users
96+
final int numOfPhotos = 10; // Each user will have 5 photos
97+
final int numOfFriendship = 100000; // Each thread will create 100000 friendships
98+
final int numOfLike = 100000; // Each thread will create 100000 likes
9499

95100
int expectedUsersCount = numOfUsers * numOfThreads;
96-
int expectedFriendshipCount = numOfFriendship * numOfThreads;
97101
int expectedPhotoCount = expectedUsersCount * numOfPhotos;
98-
102+
int expectedFriendshipCount = numOfFriendship;
103+
int expectedLikeCount = numOfLike;
104+
LocalDateTime startedAt = LocalDateTime.now();
99105
logger.info("Creating {} users using {} threads", expectedUsersCount, numOfThreads);
100-
ExecutorService executor = Executors.newFixedThreadPool(numOfThreads);
106+
logger.info("Expected users: {} - photos: {} - friendships: {} - likes: {}", expectedUsersCount, expectedPhotoCount,
107+
expectedFriendshipCount, expectedLikeCount);
108+
logger.info("Starting at {}", DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(startedAt));
109+
110+
ExecutorService executor = Executors.newFixedThreadPool(10);
101111
for (int i = 0; i < numOfThreads; i++) {
102112
// Each thread will create users and photos
103113
executor.submit(() -> {
104-
LocalhostDatabaseWrapper db1 = new LocalhostDatabaseWrapper(idSupplier);
114+
DatabaseWrapper db1 = new DatabaseWrapper(host, port, idSupplier);
105115
db1.addUserAndPhotos(numOfUsers, numOfPhotos);
106116
db1.close();
107117
});
108118
}
109119

120+
if (numOfFriendship > 0) {
121+
// Each thread will create friendships
122+
executor.submit(() -> {
123+
DatabaseWrapper db1 = new DatabaseWrapper(host, port, idSupplier);
124+
db1.createFriendships(numOfFriendship);
125+
db1.close();
126+
});
127+
}
128+
129+
if (numOfLike > 0) {
130+
// Each thread will create friendships
131+
executor.submit(() -> {
132+
DatabaseWrapper db1 = new DatabaseWrapper(host, port, idSupplier);
133+
;
134+
db1.createLike(numOfLike);
135+
db1.close();
136+
});
137+
}
138+
110139
executor.shutdown();
111140

112141
while (!executor.isTerminated()) {
113142
try {
114143
long users = db.countUsers();
115144
long friendships = db.countFriendships();
116145
long photos = db.countPhotos();
117-
logger.info("Current users: {} - photos: {} - friendships: {}", users, photos, friendships);
146+
long likes = db.countLikes();
147+
logger.info("Current users: {} - photos: {} - friendships: {} - likes: {}", users, photos, friendships, likes);
118148
} catch (Exception e) {
119149
logger.error(e.getMessage(), e);
120150
}
@@ -126,9 +156,18 @@ void singleServerLoadTest() throws InterruptedException, IOException {
126156
}
127157
}
128158

159+
LocalDateTime finishedAt = LocalDateTime.now();
160+
logger.info("Finishing at {}", DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(finishedAt));
161+
logger.info("Total time: {} minutes", Duration.between(startedAt, finishedAt).toMinutes());
162+
163+
Metrics.globalRegistry.getMeters().forEach(meter -> {
164+
logger.info("Meter: {} - {}", meter.getId().getName(), meter.measure());
165+
});
166+
129167
db.assertThatUserCountIs(expectedUsersCount);
130168
db.assertThatPhotoCountIs(expectedPhotoCount);
131169
db.assertThatFriendshipCountIs(expectedFriendshipCount);
170+
db.assertThatLikesCountIs(expectedLikeCount);
132171

133172
}
134173

e2e-perf/src/test/java/com/arcadedb/test/performance/SingleServerLoadTestIT.java

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
import com.arcadedb.test.support.ContainersTestTemplate;
44
import com.arcadedb.test.support.DatabaseWrapper;
5+
import io.micrometer.core.instrument.Metrics;
56
import org.junit.jupiter.api.DisplayName;
67
import org.junit.jupiter.api.Test;
78
import org.testcontainers.containers.GenericContainer;
89

910
import java.io.IOException;
11+
import java.time.Duration;
12+
import java.time.LocalDateTime;
13+
import java.time.format.DateTimeFormatter;
1014
import java.util.concurrent.ExecutorService;
1115
import java.util.concurrent.Executors;
1216
import java.util.concurrent.TimeUnit;
@@ -18,58 +22,91 @@ public class SingleServerLoadTestIT extends ContainersTestTemplate {
1822
void singleServerLoadTest() throws InterruptedException, IOException {
1923

2024
GenericContainer<?> arcadeContainer = createArcadeContainer("arcade", "none", "none", "any", false, network);
21-
2225
startContainers();
23-
24-
DatabaseWrapper db = new DatabaseWrapper(arcadeContainer, idSupplier);
26+
String host = arcadeContainer.getHost();
27+
int port = arcadeContainer.getMappedPort(2480);
28+
DatabaseWrapper db = new DatabaseWrapper(host, port, idSupplier);
2529
db.createDatabase();
2630
db.createSchema();
2731

28-
final int numOfThreads = 5;
29-
final int numOfUsers = 1000;
30-
final int numOfPhotos = 10;
31-
final int numOfFriendship = 1000;
32+
// Parameters for the test
33+
final int numOfThreads = 5; //number of threads to use to insert users and photos
34+
final int numOfUsers = 10000; // Each thread will create 200000 users
35+
final int numOfPhotos = 10; // Each user will have 5 photos
36+
final int numOfFriendship = 1000; // Each thread will create 100000 friendships
37+
final int numOfLike = 1000; // Each thread will create 100000 likes
3238

3339
int expectedUsersCount = numOfUsers * numOfThreads;
34-
int expectedFriendshipCount = numOfFriendship * numOfThreads;
3540
int expectedPhotoCount = expectedUsersCount * numOfPhotos;
36-
41+
int expectedFriendshipCount = numOfFriendship;
42+
int expectedLikeCount = numOfLike;
43+
LocalDateTime startedAt = LocalDateTime.now();
3744
logger.info("Creating {} users using {} threads", expectedUsersCount, numOfThreads);
38-
ExecutorService executor = Executors.newFixedThreadPool(numOfThreads);
45+
logger.info("Expected users: {} - photos: {} - friendships: {} - likes: {}", expectedUsersCount, expectedPhotoCount,
46+
expectedFriendshipCount, expectedLikeCount);
47+
logger.info("Starting at {}", DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(startedAt));
48+
49+
ExecutorService executor = Executors.newFixedThreadPool(10);
3950
for (int i = 0; i < numOfThreads; i++) {
4051
// Each thread will create users and photos
4152
executor.submit(() -> {
42-
DatabaseWrapper db1 = new DatabaseWrapper(arcadeContainer, idSupplier);
53+
DatabaseWrapper db1 = new DatabaseWrapper(host, port, idSupplier);
4354
db1.addUserAndPhotos(numOfUsers, numOfPhotos);
4455
db1.close();
4556
});
57+
}
4658

47-
TimeUnit.SECONDS.sleep(2);
59+
if (numOfFriendship > 0) {
4860
// Each thread will create friendships
4961
executor.submit(() -> {
50-
DatabaseWrapper db1 = new DatabaseWrapper(arcadeContainer, idSupplier);
62+
DatabaseWrapper db1 = new DatabaseWrapper(host, port, idSupplier);
5163
db1.createFriendships(numOfFriendship);
5264
db1.close();
5365
});
5466
}
5567

68+
if (numOfLike > 0) {
69+
// Each thread will create friendships
70+
executor.submit(() -> {
71+
DatabaseWrapper db1 = new DatabaseWrapper(host, port, idSupplier);
72+
;
73+
db1.createLike(numOfLike);
74+
db1.close();
75+
});
76+
}
77+
5678
executor.shutdown();
79+
5780
while (!executor.isTerminated()) {
58-
long users = db.countUsers();
59-
long friendships = db.countFriendships();
60-
long photos = db.countPhotos();
61-
logger.info("Current users: {} - photos: {} - friendships: {}", users, photos, friendships);
62-
// Wait for 2 seconds before checking again
6381
try {
82+
long users = db.countUsers();
83+
long friendships = db.countFriendships();
84+
long photos = db.countPhotos();
85+
long likes = db.countLikes();
86+
logger.info("Current users: {} - photos: {} - friendships: {} - likes: {}", users, photos, friendships, likes);
87+
} catch (Exception e) {
88+
logger.error(e.getMessage(), e);
89+
}
90+
try {
91+
// Wait for 2 seconds before checking again
6492
TimeUnit.SECONDS.sleep(2);
6593
} catch (InterruptedException e) {
6694
Thread.currentThread().interrupt();
6795
}
6896
}
6997

98+
LocalDateTime finishedAt = LocalDateTime.now();
99+
logger.info("Finishing at {}", DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(finishedAt));
100+
logger.info("Total time: {} minutes", Duration.between(startedAt, finishedAt).toMinutes());
101+
102+
Metrics.globalRegistry.getMeters().forEach(meter -> {
103+
logger.info("Meter: {} - {}", meter.getId().getName(), meter.measure());
104+
});
105+
70106
db.assertThatUserCountIs(expectedUsersCount);
71107
db.assertThatPhotoCountIs(expectedPhotoCount);
72108
db.assertThatFriendshipCountIs(expectedFriendshipCount);
109+
db.assertThatLikesCountIs(expectedLikeCount);
73110

74111
}
75112

e2e-perf/src/test/java/com/arcadedb/test/performance/SingleServerSimpleLoadTestIT.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,25 @@ void singleServerLoadTest() throws InterruptedException, IOException {
2020
GenericContainer<?> arcadeContainer = createArcadeContainer("arcade", "none", "none", "any", false, network);
2121

2222
startContainers();
23-
24-
DatabaseWrapper db = new DatabaseWrapper(arcadeContainer, idSupplier);
23+
String host = arcadeContainer.getHost();
24+
int port = arcadeContainer.getMappedPort(2480);
25+
DatabaseWrapper db = new DatabaseWrapper(host, port, idSupplier);
2526
db.createDatabase();
2627
db.createSchema();
2728

2829
final int numOfThreads = 1;
2930
final int numOfUsers = 10000;
30-
final int numOfPhotos = 0;
31-
final int numOfFriendship = 0;
31+
final int numOfPhotos = 10;
3232

3333
int expectedUsersCount = numOfUsers * numOfThreads;
34-
int expectedFriendshipCount = numOfFriendship * numOfThreads;
3534
int expectedPhotoCount = expectedUsersCount * numOfPhotos;
3635

3736
logger.info("Creating {} users using {} threads", expectedUsersCount, numOfThreads);
3837
ExecutorService executor = Executors.newFixedThreadPool(numOfThreads);
3938
for (int i = 0; i < numOfThreads; i++) {
4039
// Each thread will create users and photos
4140
executor.submit(() -> {
42-
DatabaseWrapper db1 = new DatabaseWrapper(arcadeContainer, idSupplier);
41+
DatabaseWrapper db1 = new DatabaseWrapper(host, port, idSupplier);
4342
db1.addUserAndPhotos(numOfUsers, numOfPhotos);
4443
db1.close();
4544
});
@@ -49,9 +48,8 @@ void singleServerLoadTest() throws InterruptedException, IOException {
4948

5049
while (!executor.isTerminated()) {
5150
long users = db.countUsers();
52-
long friendships = db.countFriendships();
5351
long photos = db.countPhotos();
54-
logger.info("Current users: {} - photos: {} - friendships: {}", users, photos, friendships);
52+
logger.info("Current users: {} - photos: {} ", users, photos);
5553
// Wait for 2 seconds before checking again
5654
try {
5755
TimeUnit.SECONDS.sleep(2);
@@ -62,7 +60,6 @@ void singleServerLoadTest() throws InterruptedException, IOException {
6260

6361
db.assertThatUserCountIs(expectedUsersCount);
6462
db.assertThatPhotoCountIs(expectedPhotoCount);
65-
db.assertThatFriendshipCountIs(expectedFriendshipCount);
6663

6764
}
6865

e2e-perf/src/test/java/com/arcadedb/test/support/ContainersTestTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ protected GenericContainer<?> createArcadeContainer(String name,
198198
-Darcadedb.ha.serverList=%s
199199
-Darcadedb.ha.replicationQueueSize=1024
200200
""", name, ha, quorum, role, serverList))
201-
.withEnv("ARCADEDB_OPTS_MEMORY", "-Xms16G -Xmx16G")
201+
.withEnv("ARCADEDB_OPTS_MEMORY", "-Xms8G -Xmx8G")
202202
.waitingFor(Wait.forHttp("/api/v1/ready").forPort(2480).forStatusCode(204));
203203
containers.add(container);
204204
return container;

0 commit comments

Comments
 (0)