Skip to content

Commit

Permalink
test: benchmarks with telemetry (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
crystall-bitquill authored Oct 31, 2024
1 parent 9f0fa65 commit dac2652
Show file tree
Hide file tree
Showing 7 changed files with 508 additions and 121 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"mysql"
],
"scripts": {
"bench": "npx tsx tests/benchmarks.ts",
"bench2": " npx tsx --tsconfig ./tsconfig.json tests/benchmarks.ts",
"check": "prettier . --check --config .prettierrc",
"bench-plugin-manager": "npx tsx tests/plugin_manager_benchmarks.ts",
"bench-plugins": "npx tsx tests/plugin_benchmarks.ts",
"bench-plugin-manager-otel": "npx tsx tests/plugin_manager_telemetry_benchmarks.ts",
"bench-plugins-otel": "npx tsx tests/plugin_telemetry_benchmarks.ts",
"format": "prettier . --write --config .prettierrc",
"integration": "jest --config=jest.integration.config.json --runInBand --verbose",
"debug-integration": "node --inspect-brk=0.0.0.0:5005 ./node_modules/jest/bin/jest.js --config=jest.integration.config.json --runInBand",
Expand Down
100 changes: 0 additions & 100 deletions tests/benchmarks.ts

This file was deleted.

43 changes: 31 additions & 12 deletions tests/plugin_benchmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,25 @@ import { add, complete, configure, cycle, save, suite } from "benny";
import { TestConnectionWrapper } from "./testplugin/test_connection_wrapper";
import { HostInfoBuilder } from "../common/lib/host_info_builder";
import { SimpleHostAvailabilityStrategy } from "../common/lib/host_availability/simple_host_availability_strategy";
import { ClientWrapper } from "../common/lib/client_wrapper";
import { AwsPGClient } from "../pg/lib";
import { NullTelemetryFactory } from "../common/lib/utils/telemetry/null_telemetry_factory";
import { ConnectionProviderManager } from "../common/lib/connection_provider_manager";
import { PgClientWrapper } from "../common/lib/pg_client_wrapper";

const mockConnectionProvider = mock<ConnectionProvider>();
const mockPluginService = mock(PluginService);
const mockClient = mock(AwsPGClient);

const hostInfo = new HostInfoBuilder({ hostAvailabilityStrategy: new SimpleHostAvailabilityStrategy() }).withHost("host").build();

const mockClientWrapper: ClientWrapper = {
client: instance(mockClient),
hostInfo: hostInfo,
properties: new Map<string, any>()
};
const mockClientWrapper = new PgClientWrapper(instance(mockClient), hostInfo, new Map<string, any>());

const telemetryFactory = new NullTelemetryFactory();

when(mockClient.query(anything())).thenReturn();
when(mockPluginService.getCurrentHostInfo()).thenReturn(hostInfo);
when(mockPluginService.getTelemetryFactory()).thenReturn(telemetryFactory);
when(mockPluginService.getCurrentClient()).thenReturn(mockClientWrapper.client);

const connectionString = "my.domain.com";
const pluginServiceManagerContainer = new PluginServiceManagerContainer();
Expand All @@ -57,9 +59,24 @@ WrapperProperties.HOST.set(propsExecute, connectionString);
WrapperProperties.HOST.set(propsReadWrite, connectionString);
WrapperProperties.HOST.set(props, connectionString);

const pluginManagerExecute = new PluginManager(pluginServiceManagerContainer, propsExecute, instance(mockConnectionProvider), null);
const pluginManagerReadWrite = new PluginManager(pluginServiceManagerContainer, propsReadWrite, instance(mockConnectionProvider), null);
const pluginManager = new PluginManager(pluginServiceManagerContainer, props, instance(mockConnectionProvider), null);
const pluginManagerExecute = new PluginManager(
pluginServiceManagerContainer,
propsExecute,
new ConnectionProviderManager(instance(mockConnectionProvider), null),
telemetryFactory
);
const pluginManagerReadWrite = new PluginManager(
pluginServiceManagerContainer,
propsReadWrite,
new ConnectionProviderManager(instance(mockConnectionProvider), null),
telemetryFactory
);
const pluginManager = new PluginManager(
pluginServiceManagerContainer,
props,
new ConnectionProviderManager(instance(mockConnectionProvider), null),
new NullTelemetryFactory()
);

suite(
"Plugin benchmarks",
Expand Down Expand Up @@ -92,20 +109,22 @@ suite(
}),

add("executeStatementBaseline", async () => {
const wrapper = new TestConnectionWrapper(propsExecute, pluginManagerExecute, instance(mockPluginService));
await pluginManagerReadWrite.init();
const wrapper = new TestConnectionWrapper(props, pluginManager, instance(mockPluginService));
await pluginManager.init();
await wrapper.executeQuery(propsExecute, "select 1", mockClientWrapper);
await wrapper.end();
}),

add("executeStatementWithExecuteTimePlugin", async () => {
const wrapper = new TestConnectionWrapper(propsExecute, pluginManagerExecute, instance(mockPluginService));
await pluginManagerReadWrite.init();
await pluginManagerExecute.init();
await wrapper.executeQuery(propsExecute, "select 1", mockClientWrapper);
await wrapper.end();
}),

cycle(),
complete(),
save({ file: "plugin_benchmarks", format: "json", details: true }),
save({ file: "plugin_benchmarks", format: "csv", details: true }),
save({ file: "plugin_benchmarks", format: "chart.html", details: true })
);
41 changes: 35 additions & 6 deletions tests/plugin_manager_benchmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { add, cycle, suite, save, complete, configure } from "benny";
import { ConnectionPlugin, PluginManager } from "../common/lib";
import { PluginServiceManagerContainer } from "../common/lib/plugin_service_manager_container";
import { instance, mock } from "ts-mockito";
import { instance, mock, when } from "ts-mockito";
import { ConnectionProvider } from "../common/lib/connection_provider";
import { HostInfoBuilder } from "../common/lib/host_info_builder";
import { SimpleHostAvailabilityStrategy } from "../common/lib/host_availability/simple_host_availability_strategy";
Expand All @@ -27,10 +27,18 @@ import { HostChangeOptions } from "../common/lib/host_change_options";
import { WrapperProperties } from "../common/lib/wrapper_property";
import { DefaultPlugin } from "../common/lib/plugins/default_plugin";
import { BenchmarkPluginFactory } from "./testplugin/benchmark_plugin_factory";
import { NullTelemetryFactory } from "../common/lib/utils/telemetry/null_telemetry_factory";
import { ConnectionProviderManager } from "../common/lib/connection_provider_manager";
import { PgDatabaseDialect } from "../pg/lib/dialect/pg_database_dialect";
import { NodePostgresDriverDialect } from "../pg/lib/dialect/node_postgres_driver_dialect";

const mockConnectionProvider = mock<ConnectionProvider>();
const mockHostListProviderService = mock<HostListProviderService>();
const mockPluginService = mock(PluginService);
const telemetryFactory = new NullTelemetryFactory();
when(mockPluginService.getTelemetryFactory()).thenReturn(telemetryFactory);
when(mockPluginService.getDialect()).thenReturn(new PgDatabaseDialect());
when(mockPluginService.getDriverDialect()).thenReturn(new NodePostgresDriverDialect());

const pluginServiceManagerContainer = new PluginServiceManagerContainer();
pluginServiceManagerContainer.pluginService = instance(mockPluginService);
Expand All @@ -40,15 +48,25 @@ const propsWithPlugins = new Map<string, any>();

WrapperProperties.PLUGINS.set(propsWithNoPlugins, "");

const pluginManagerWithNoPlugins = new PluginManager(pluginServiceManagerContainer, propsWithNoPlugins, instance(mockConnectionProvider), null);
const pluginManagerWithPlugins = new PluginManager(pluginServiceManagerContainer, propsWithPlugins, instance(mockConnectionProvider), null);
const pluginManagerWithNoPlugins = new PluginManager(
pluginServiceManagerContainer,
propsWithNoPlugins,
new ConnectionProviderManager(instance(mockConnectionProvider), null),
telemetryFactory
);
const pluginManagerWithPlugins = new PluginManager(
pluginServiceManagerContainer,
propsWithPlugins,
new ConnectionProviderManager(instance(mockConnectionProvider), null),
telemetryFactory
);

async function createPlugins(pluginService: PluginService, connectionProvider: ConnectionProvider, props: Map<string, any>) {
const plugins = new Array<ConnectionPlugin>();
for (let i = 0; i < 10; i++) {
plugins.push(await new BenchmarkPluginFactory().getInstance(pluginService, props));
}
plugins.push(new DefaultPlugin(pluginService, connectionProvider, null));
plugins.push(new DefaultPlugin(pluginService, new ConnectionProviderManager(instance(mockConnectionProvider), null)));
return plugins;
}

Expand All @@ -62,12 +80,22 @@ suite(
}),

add("initPluginManagerWithPlugins", async () => {
const manager = new PluginManager(pluginServiceManagerContainer, propsWithPlugins, instance(mockConnectionProvider), null);
const manager = new PluginManager(
pluginServiceManagerContainer,
propsWithPlugins,
new ConnectionProviderManager(instance(mockConnectionProvider), null),
new NullTelemetryFactory()
);
await manager.init(await createPlugins(instance(mockPluginService), instance(mockConnectionProvider), propsWithPlugins));
}),

add("initPluginManagerWithNoPlugins", async () => {
const manager = new PluginManager(pluginServiceManagerContainer, propsWithNoPlugins, instance(mockConnectionProvider), null);
const manager = new PluginManager(
pluginServiceManagerContainer,
propsWithNoPlugins,
new ConnectionProviderManager(instance(mockConnectionProvider), null),
new NullTelemetryFactory()
);
await manager.init();
}),

Expand Down Expand Up @@ -150,5 +178,6 @@ suite(
cycle(),
complete(),
save({ file: "plugin_manager_benchmarks", format: "json", details: true }),
save({ file: "plugin_manager_benchmarks", format: "csv", details: true }),
save({ file: "plugin_manager_benchmarks", format: "chart.html", details: true })
);
Loading

0 comments on commit dac2652

Please sign in to comment.