Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions e2e-perf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,24 @@
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.arcadedb</groupId>
<artifactId>arcadedb-grpc-client</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.arcadedb.test.performance;

import com.arcadedb.test.support.DatabaseWrapper;
import com.arcadedb.test.support.ServerWrapper;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.logging.LoggingMeterRegistry;
import io.micrometer.core.instrument.logging.LoggingRegistryConfig;
Expand Down Expand Up @@ -84,9 +85,8 @@ public void tearDown() {
@DisplayName("Single server load test")
void singleServerLoadTest() throws InterruptedException, IOException {

String host = "localhost"; // Assuming localhost for the database connection
int port = 2480; // Default ArcadeDB port
DatabaseWrapper db = new DatabaseWrapper(host, port, idSupplier);
ServerWrapper server = new ServerWrapper("localhost", 2480, 50051);
DatabaseWrapper db = new DatabaseWrapper(server, idSupplier);
db.createDatabase();
db.createSchema();

Expand All @@ -111,7 +111,7 @@ void singleServerLoadTest() throws InterruptedException, IOException {
for (int i = 0; i < numOfThreads; i++) {
// Each thread will create users and photos
executor.submit(() -> {
DatabaseWrapper db1 = new DatabaseWrapper(host, port, idSupplier);
DatabaseWrapper db1 = new DatabaseWrapper(server, idSupplier);
db1.addUserAndPhotos(numOfUsers, numOfPhotos);
db1.close();
});
Expand All @@ -120,7 +120,7 @@ void singleServerLoadTest() throws InterruptedException, IOException {
if (numOfFriendship > 0) {
// Each thread will create friendships
executor.submit(() -> {
DatabaseWrapper db1 = new DatabaseWrapper(host, port, idSupplier);
DatabaseWrapper db1 = new DatabaseWrapper(server, idSupplier);
db1.createFriendships(numOfFriendship);
db1.close();
});
Expand All @@ -129,7 +129,7 @@ void singleServerLoadTest() throws InterruptedException, IOException {
if (numOfLike > 0) {
// Each thread will create friendships
executor.submit(() -> {
DatabaseWrapper db1 = new DatabaseWrapper(host, port, idSupplier);
DatabaseWrapper db1 = new DatabaseWrapper(server, idSupplier);
;
db1.createLike(numOfLike);
db1.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import com.arcadedb.test.support.ContainersTestTemplate;
import com.arcadedb.test.support.DatabaseWrapper;
import com.arcadedb.test.support.ServerWrapper;
import io.micrometer.core.instrument.Metrics;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

import java.io.IOException;
import java.time.Duration;
Expand All @@ -17,15 +18,14 @@

public class SingleServerLoadTestIT extends ContainersTestTemplate {

@Test
@DisplayName("Single server load test")
void singleServerLoadTest() throws InterruptedException, IOException {
@ParameterizedTest
@EnumSource(DatabaseWrapper.Protocol.class)
void singleServerLoadTest(DatabaseWrapper.Protocol protocol) throws InterruptedException, IOException {

GenericContainer<?> arcadeContainer = createArcadeContainer("arcade", "none", "none", "any", false, network);
startContainers();
String host = arcadeContainer.getHost();
int port = arcadeContainer.getMappedPort(2480);
DatabaseWrapper db = new DatabaseWrapper(host, port, idSupplier);
createArcadeContainer("arcade", "none", "none", "any", false, network);
ServerWrapper server = startContainers().getFirst();
DatabaseWrapper db = new DatabaseWrapper(server, idSupplier, protocol);
db.createDatabase();
db.createSchema();

Expand All @@ -50,7 +50,7 @@ void singleServerLoadTest() throws InterruptedException, IOException {
for (int i = 0; i < numOfThreads; i++) {
// Each thread will create users and photos
executor.submit(() -> {
DatabaseWrapper db1 = new DatabaseWrapper(host, port, idSupplier);
DatabaseWrapper db1 = new DatabaseWrapper(server, idSupplier, protocol);
db1.addUserAndPhotos(numOfUsers, numOfPhotos);
db1.close();
});
Expand All @@ -59,7 +59,7 @@ void singleServerLoadTest() throws InterruptedException, IOException {
if (numOfFriendship > 0) {
// Each thread will create friendships
executor.submit(() -> {
DatabaseWrapper db1 = new DatabaseWrapper(host, port, idSupplier);
DatabaseWrapper db1 = new DatabaseWrapper(server, idSupplier, protocol);
db1.createFriendships(numOfFriendship);
db1.close();
});
Expand All @@ -68,7 +68,7 @@ void singleServerLoadTest() throws InterruptedException, IOException {
if (numOfLike > 0) {
// Each thread will create friendships
executor.submit(() -> {
DatabaseWrapper db1 = new DatabaseWrapper(host, port, idSupplier);
DatabaseWrapper db1 = new DatabaseWrapper(server, idSupplier, protocol);
;
db1.createLike(numOfLike);
db1.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,31 @@

import com.arcadedb.test.support.ContainersTestTemplate;
import com.arcadedb.test.support.DatabaseWrapper;
import com.arcadedb.test.support.ServerWrapper;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class SingleServerSimpleLoadTestIT extends ContainersTestTemplate {

@Test
@DisplayName("Single server load test")
void singleServerLoadTest() throws InterruptedException, IOException {
@ParameterizedTest
@EnumSource(DatabaseWrapper.Protocol.class)
//to eneable only one protocol use the following annotation
//@EnumSource(value = DatabaseWrapper.Protocol.class, names = "GRPC")
void singleServerLoadTest(DatabaseWrapper.Protocol protocol) throws InterruptedException, IOException {

GenericContainer<?> arcadeContainer = createArcadeContainer("arcade", "none", "none", "any", false, network);
createArcadeContainer("arcade", "none", "none", "any", false, network);

startContainers();
String host = arcadeContainer.getHost();
int port = arcadeContainer.getMappedPort(2480);
DatabaseWrapper db = new DatabaseWrapper(host, port, idSupplier);
List<ServerWrapper> serverWrappers = startContainers();
ServerWrapper server = serverWrappers.getFirst();
DatabaseWrapper db = new DatabaseWrapper(server, idSupplier, protocol);
db.createDatabase();
db.createSchema();

Expand All @@ -38,7 +42,7 @@ void singleServerLoadTest() throws InterruptedException, IOException {
for (int i = 0; i < numOfThreads; i++) {
// Each thread will create users and photos
executor.submit(() -> {
DatabaseWrapper db1 = new DatabaseWrapper(host, port, idSupplier);
DatabaseWrapper db1 = new DatabaseWrapper(server, idSupplier, protocol);
db1.addUserAndPhotos(numOfUsers, numOfPhotos);
db1.close();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
import org.testcontainers.lifecycle.Startables;
import org.testcontainers.utility.MountableFile;

import java.io.*;
import java.nio.file.*;
import java.time.*;
import java.util.*;
import java.util.concurrent.atomic.*;
import java.util.function.*;
import java.io.IOException;
import java.nio.file.Path;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;

public abstract class ContainersTestTemplate {
public static final String IMAGE = "arcadedata/arcadedb:latest";
Expand Down Expand Up @@ -127,11 +128,14 @@ protected void stopContainers() {
/**
* Starts all containers that are not already running.
*/
protected void startContainers() {
protected List<ServerWrapper> startContainers() {
logger.info("Starting all containers");
containers.stream()
.filter(container -> !container.isRunning())
.forEach(container -> Startables.deepStart(container).join());
return containers.stream()
.map(ServerWrapper::new)
.toList();
}

/**
Expand All @@ -144,7 +148,8 @@ protected void startContainers() {
*
* @return A GenericContainer instance representing the ArcadeDB container.
*/
protected GenericContainer<?> createArcadeContainer(String name,
protected GenericContainer createArcadeContainer(
String name,
String serverList,
String quorum,
String role,
Expand Down Expand Up @@ -174,7 +179,7 @@ protected GenericContainer<?> createArcadeContainer(String name,
makeContainersDirectories(name);

GenericContainer<?> container = new GenericContainer<>(IMAGE)
.withExposedPorts(2480, 5432)
.withExposedPorts(2480, 5432, 50051)
.withNetwork(network)
.withNetworkAliases(name)
.withStartupTimeout(Duration.ofSeconds(90))
Expand All @@ -184,7 +189,7 @@ protected GenericContainer<?> createArcadeContainer(String name,

.withEnv("JAVA_OPTS", String.format("""
-Darcadedb.server.rootPassword=playwithdata
-Darcadedb.server.plugins=Postgres:com.arcadedb.postgres.PostgresProtocolPlugin
-Darcadedb.server.plugins=Postgres:com.arcadedb.postgres.PostgresProtocolPlugin,GRPC:com.arcadedb.server.grpc.GrpcServerPlugin
-Darcadedb.server.httpsIoThreads=30
-Darcadedb.bucketReuseSpaceMode=low
-Darcadedb.server.name=%s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.arcadedb.remote.RemoteHttpComponent;
import com.arcadedb.remote.RemoteSchema;
import com.arcadedb.remote.RemoteServer;
import com.arcadedb.remote.grpc.RemoteGrpcDatabase;
import com.arcadedb.remote.grpc.RemoteGrpcServer;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Timer;
import org.slf4j.Logger;
Expand All @@ -20,29 +22,41 @@

public class DatabaseWrapper {
private static final Logger logger = LoggerFactory.getLogger(DatabaseWrapper.class);
private final String host;
private final int port;
private final ServerWrapper server;
private final RemoteDatabase db;
private final Supplier<Integer> idSupplier;
private final Timer photosTimer;
private final Timer usersTimer;
private final Timer friendshipTimer;
private final Timer likeTimer;

public DatabaseWrapper(String host, int port, Supplier<Integer> idSupplier) {
this.host = host;
this.port = port;
this.db = connectToDatabase();
public enum Protocol {HTTP, GRPC}

public DatabaseWrapper(ServerWrapper server, Supplier<Integer> idSupplier, Protocol protocol) {
this.server = server;
this.db = connectToDatabase(protocol);
this.idSupplier = idSupplier;
usersTimer = Metrics.timer("arcadedb.test.inserted.users");
photosTimer = Metrics.timer("arcadedb.test.inserted.photos");
friendshipTimer = Metrics.timer("arcadedb.test.inserted.friendship");
likeTimer = Metrics.timer("arcadedb.test.inserted.like");
}

private RemoteDatabase connectToDatabase() {
RemoteDatabase database = new RemoteDatabase(host,
port,
public DatabaseWrapper(ServerWrapper server, Supplier<Integer> idSupplier) {
this(server, idSupplier, Protocol.HTTP);
}

private RemoteDatabase connectToDatabaseGrpc() {
RemoteGrpcServer gtpcServer = new RemoteGrpcServer(server.host(), server.grpcPort(), "root", PASSWORD, true, List.of());
RemoteGrpcDatabase database = new RemoteGrpcDatabase(gtpcServer, server.host(), server.grpcPort(), server.httpPort(), DATABASE,
"root", PASSWORD);
return database;
}

private RemoteDatabase connectToDatabaseHttp() {
RemoteDatabase database = new RemoteDatabase(
server.host(),
server.httpPort(),
DATABASE,
"root",
PASSWORD);
Expand All @@ -51,22 +65,31 @@ private RemoteDatabase connectToDatabase() {
return database;
}

private RemoteDatabase connectToDatabase(Protocol protocol) {
return switch (protocol) {
case HTTP -> connectToDatabaseHttp();
case GRPC -> connectToDatabaseGrpc();
};
}

public void close() {
db.close();
}

public void createDatabase() {
RemoteServer server = new RemoteServer(host,
port,
RemoteServer httpServer = new RemoteServer(
server.host(),
server.httpPort(),
"root",
PASSWORD);
server.setConnectionStrategy(RemoteHttpComponent.CONNECTION_STRATEGY.FIXED);
httpServer.setConnectionStrategy(RemoteHttpComponent.CONNECTION_STRATEGY.FIXED);

if (server.exists(DATABASE)) {
if (httpServer.exists(DATABASE)) {
logger.info("Dropping existing database {}", DATABASE);
server.drop(DATABASE);
httpServer.drop(DATABASE);
}
server.create(DATABASE);
logger.info("Creating database {}", DATABASE);
httpServer.create(DATABASE);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.arcadedb.test.support;

import org.testcontainers.containers.GenericContainer;

public record ServerWrapper(String host,
int httpPort,
int grpcPort
) {
public ServerWrapper(GenericContainer<?> container) {
this(container.getHost(),
container.getMappedPort(2480),
container.getMappedPort(50051));
}
}
Loading
Loading