8000 Added performance benchmark by karelklima · Pull Request #132 · karelklima/ldkit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added performance benchmark #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
64 changes: 64 additions & 0 deletions performance/benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Performance benchmark

This test suite runs a series of performance tests against local triplestore and
publishes results into the `results.json` file.

A test specification consists of a key with three numbers, e.g. `10 0 5`, which
represent the complexity of LDkit schema that is being used for the performance
test. The first number represents the number of simple properties in the schema,
the second represents a number of array properties (each array has three
elements), and the third represents a number of object properties in the schema
(each object has three properties on its own). For example, the `10 0 5` test
includes a LDkit schema with 10 simple properties and 5 object properties,
having 15 properties in total.

Each test case measures the execution time of querying 1000 entities according
to the schema for both LDkit and direct query of the triplestore, so that the
two times can be compared.

## Test results

The rest results contained in the `results.json` show average execution time for
various test cases. The test was performed on a PC with Intel Core i7-5500U CPU
@ 2.40 GHz and 8 GB RAM running Windows 10. Local installation of GraphDB
version 11.0 was used as the triplestore.

## Running the benchmark

Deno and GraphDB are required to run the test scenarios. Instead of GraphDB,
another triplestore may be used.

### 1) Install Deno

Windows:

```
irm https://deno.land/install.ps1 | iex
```

MacOS/Linux:

```
curl -fsSL https://deno.land/install.sh | sh
```

### 2) Install GraphDB

[GraphDB Desktop installation](https://graphdb.ontotext.com/documentation/11.0/graphdb-desktop-installation.html)

### 3) Populate the triplestore with data

```
deno task populate
```

The script will create 10000 entities that will be used for the performance
test.

### 4) Run the performance tests

```
deno task test
```

The results of the test are saved into `results.json` file.
17 changes: 17 additions & 0 deletions performance/benchmark/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const QUERY_SOURCE = "http://localhost:7200/repositories/bench";
export const UPDATE_SOURCE = `${QUERY_SOURCE}/statements`;

export async function directQuery(
body: string,
): Promise<string> {
const response = await fetch(QUERY_SOURCE, {
method: "POST",
headers: {
"accept": "application/n-triples",
"content-type": `application/sparql-query; charset=UTF-8`,
},
body,
});
const text = await response.text();
return text;
}
10 changes: 10 additions & 0 deletions performance/benchmark/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"imports": {
"ldkit": "../../mod.ts"
},
"tasks": {
"test": "deno run --allow-net --allow-env --allow-write ./test.ts",
"populate": "deno run --allow-net --allow-env ./populate.ts"
},
"lock": false
}
61 changes: 61 additions & 0 deletions performance/benchmark/mocks.ts
8000
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Schema } from "ldkit";

const x = (value: string) => `https://x/${value}`;

const uuid = () => crypto.randomUUID();

const id = () => x(uuid());

export type Entity = { [key: string]: string | string[] | Entity };

export function createEntity(
simpleProperties: number,
arrayProperties: number,
objectProperties: number,
) {
const entity: Entity = {
$id: id(),
};

for (let i = 1; i <= simpleProperties; i++) {
entity[`simpleProperty${i}`] = uuid();
}

for (let i = 1; i <= arrayProperties; i++) {
entity[`arrayProperty${i}`] = [uuid(), uuid(), uuid()];
}

for (let i = 1; i <= objectProperties; i++) {
entity[`objectProperty${i}`] = createEntity(3, 0, 0);
}

return entity;
}

export function createSchema(
simpleProperties: number,
arrayProperties: number,
objectProperties: number,
type: string = "Entity",
) {
const schema: Schema = {
"@type": x(type),
};

for (let i = 1; i <= simpleProperties; i++) {
schema[`simpleProperty${i}`] = x(`simpleProperty${i}`);
}
for (let i = 1; i <= arrayProperties; i++) {
schema[`arrayProperty${i}`] = {
"@id": x(`arrayProperty${i}`),
"@array": true,
};
}
for (let i = 1; i <= objectProperties; i++) {
schema[`objectProperty${i}`] = {
"@id": x(`objectProperty${i}`),
"@schema": createSchema(3, 0, 0, `SubEntity`),
};
}
return schema;
}
44 changes: 44 additions & 0 deletions performance/benchmark/populate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { createLens } from "ldkit";
import { UPDATE_SOURCE } from "./common.ts";
import { createEntity, createSchema, Entity } from "./mocks.ts";

console.log(
"This script will generate performance test data in the repository.",
);
console.log(
"It will create 10,000 entities with 10 simple properties, 10 array properties, and 10 object properties.",
);

console.log(`Repository URL: ${UPDATE_SOURCE}`);

const shouldProceed = confirm(
"Do you want to proceed?",
);

if (!shouldProceed) {
console.log("Aborted.");
Deno.exit(0);
}

console.log("Should proceed:", shouldProceed);

const EntitySchema = createSchema(10, 10, 10);

const UpdateEntities = createLens(EntitySchema, {
sources: [UPDATE_SOURCE],
});

const iterations = 10;
for (let x = 1; x <= iterations; x++) {
console.log(`Creating 1000 entities, iteration ${x}/${iterations}`);
console.log("Generating entities...");
const entities: Entity[] = [];
for (let i = 0; i < 1000; i++) {
entities.push(createEntity(10, 10, 10));
}
console.log("Inserting entities...");
// deno-lint-ignore no-explicit-any
await UpdateEntities.insert(...entities as any);
}

console.log("DONE");
Loading
0