Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
256ea2f
Adds FbTransactionInfo.GetTransactionId().
fdcastel Oct 25, 2024
7dd65e8
Adds .NET distributed tracing instrumentation.
fdcastel Oct 25, 2024
7fe1327
Add metrics.
fdcastel Oct 26, 2024
2968ea3
Fix NullReferenceException when StartActivity returns null
fdcastel Mar 23, 2026
9b25148
Fix Stopwatch elapsed time conversion
fdcastel Mar 23, 2026
c198a6a
Rename db.system to db.system.name per OTel semantic conventions v1.40+
fdcastel Mar 23, 2026
4781900
Set db.namespace attribute on spans from connection database name
fdcastel Mar 23, 2026
4f83e23
Set error.type attribute on failure spans
fdcastel Mar 23, 2026
78c6d3b
Gate db.query.text and db.query.parameter.* behind opt-in flags
fdcastel Mar 23, 2026
ecdb4cd
Read ActivitySource/Meter version from assembly metadata
fdcastel Mar 23, 2026
49382fb
Fix activity lifecycle: record metrics on error path, prevent stale r…
fdcastel Mar 23, 2026
594a23b
Remove non-standard and deprecated telemetry attributes
fdcastel Mar 23, 2026
f68747f
Add server.port, db.stored_procedure.name; fix server.address in metrics
fdcastel Mar 23, 2026
98f6f6d
Add db.query.summary and db.operation.name for Text commands
fdcastel Mar 23, 2026
4aa1e01
Add debug assertions in TraceCommandStop and TraceCommandException
fdcastel Mar 23, 2026
43d9462
Initialize MetricsConnectionAttributes to empty array
fdcastel Mar 23, 2026
425ae5a
Avoid dictionary allocation in observable metric callbacks
fdcastel Mar 23, 2026
395a907
Add InstrumentAdvice with histogram bucket boundaries on .NET 9+
fdcastel Mar 23, 2026
7402540
Add FbTelemetry public class with ActivitySource and Meter names
fdcastel Mar 23, 2026
36d884f
Add OpenTelemetry integration documentation
fdcastel Mar 23, 2026
ec1c68b
Fix IndexOfAny compilation on all target frameworks
fdcastel Mar 23, 2026
7b3e3a0
Refactor: Benchmarks.
fdcastel Oct 26, 2024
0c4a764
Updates run-benchmark.ps1.
fdcastel May 18, 2025
ed46d7a
Fix solution file: update benchmark project path and folder name
fdcastel Mar 23, 2026
04208fe
Add LargeFetchBenchmark for bulk read throughput across data types
fdcastel Mar 23, 2026
8fa39ed
Extract shared BenchmarkConfig to eliminate duplication
fdcastel Mar 23, 2026
5852c9a
Extract BenchmarkBase with shared ConnectionString and env-var override
fdcastel Mar 23, 2026
3ad15fa
Update benchmark toolchain from .NET 8 to .NET 10
fdcastel Mar 23, 2026
0ecaa3a
Add GitHub Markdown exporter and fastest-to-slowest ordering
fdcastel Mar 23, 2026
671604a
Replace single-value [Params] with constants
fdcastel Mar 23, 2026
32c46bb
Return values from Fetch benchmarks to prevent dead-code elimination
fdcastel Mar 23, 2026
3c3ce6e
Add async benchmark variants for Execute and Fetch
fdcastel Mar 23, 2026
c12627e
Add connection open/close benchmark
fdcastel Mar 23, 2026
6f9e2d8
Add -Disasm and -Profile flags to run-benchmark.ps1
fdcastel Mar 23, 2026
1ec795d
Fix build errors: remove duplicate braces, add missing using
fdcastel Mar 23, 2026
533d57c
Add benchmark documentation
fdcastel Mar 23, 2026
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ bin
obj
out/
.idea
/BenchmarkDotNet.Artifacts
120 changes: 120 additions & 0 deletions docs/benchmark.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Benchmarks

The benchmark project (`FirebirdSql.Data.FirebirdClient.Benchmarks`) measures performance of the Firebird .NET provider using [BenchmarkDotNet](https://benchmarkdotnet.org/).

## Prerequisites

- A running Firebird server accessible at `localhost` (default configuration)
- .NET 10 SDK

## Running Benchmarks

Use the convenience script from the repository root:

```powershell
.\run-benchmark.ps1
```

By default this runs `CommandBenchmark`. To select a different benchmark class:

```powershell
.\run-benchmark.ps1 -Benchmark ConnectionBenchmark
.\run-benchmark.ps1 -Benchmark LargeFetchBenchmark
```

### Advanced Options

Enable JIT disassembly output:

```powershell
.\run-benchmark.ps1 -Disasm
```

Enable ETW profiling (Windows only):

```powershell
.\run-benchmark.ps1 -Profile
```

Options can be combined:

```powershell
.\run-benchmark.ps1 -Benchmark LargeFetchBenchmark -Disasm
```

### Running Directly with BenchmarkDotNet

For full control over BenchmarkDotNet options, pass arguments directly after `--`:

```powershell
dotnet run --project src\FirebirdSql.Data.FirebirdClient.Benchmarks\FirebirdSql.Data.FirebirdClient.Benchmarks.csproj --configuration Release -- --list flat
dotnet run --project src\FirebirdSql.Data.FirebirdClient.Benchmarks\FirebirdSql.Data.FirebirdClient.Benchmarks.csproj --configuration Release -- --filter "*Fetch*"
```

## Connection String

By default the benchmark connects to:

```
database=localhost:benchmark.fdb;user=sysdba;password=masterkey
```

Override this with the `FIREBIRD_BENCHMARK_CS` environment variable:

```powershell
$env:FIREBIRD_BENCHMARK_CS = "database=myhost:benchmark.fdb;user=sysdba;password=masterkey"
.\run-benchmark.ps1
```

## Configuration

All benchmarks share a common configuration (`BenchmarkConfig`):

- **Baseline job**: `ReleaseNuGet` build configuration — references the latest published `FirebirdSql.Data.FirebirdClient` NuGet package.
- **Candidate job**: `Release` build configuration — references the local project source.
- **Runtime**: .NET 10
- **Diagnostics**: Memory allocations (`MemoryDiagnoser`)
- **Export**: GitHub-flavored Markdown table (written to `BenchmarkDotNet.Artifacts/`)
- **Ordering**: Fastest to slowest

The NuGet baseline lets you compare the locally built provider against the published release to detect regressions or measure improvements.

## Available Benchmarks

### `CommandBenchmark`

Measures command execution over two data types (`BIGINT`, `VARCHAR(10) CHARACTER SET UTF8`):

| Benchmark | Description |
|-----------|-------------|
| `Execute` / `ExecuteAsync` | Inserts 100 rows using `ExecuteNonQuery` / `ExecuteNonQueryAsync` |
| `Fetch` / `FetchAsync` | Reads 100 rows using `ExecuteReader` / `ExecuteReaderAsync` |

### `ConnectionBenchmark`

Measures connection pool throughput:

| Benchmark | Description |
|-----------|-------------|
| `OpenClose` / `OpenCloseAsync` | Opens and closes a pooled connection |

### `LargeFetchBenchmark`

Measures bulk read throughput for 100,000 rows across five data types:

| Data Type | Notes |
|-----------|-------|
| `BIGINT` | Fixed-size integer |
| `CHAR(255) CHARACTER SET UTF8` | Fixed-length string |
| `CHAR(255) CHARACTER SET OCTETS` | Fixed-length binary |
| `BLOB SUB_TYPE TEXT CHARACTER SET UTF8` | Text blob |
| `BLOB SUB_TYPE BINARY` | Binary blob |

## Results

BenchmarkDotNet writes results to `BenchmarkDotNet.Artifacts/` in the repository root. This directory is listed in `.gitignore`. Each run produces:

- A summary table in the console
- A GitHub-flavored Markdown file (`.md`) suitable for pasting into issues or pull requests
- An HTML report
- CSV data
80 changes: 80 additions & 0 deletions docs/otel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# OpenTelemetry Integration

The Firebird ADO.NET provider includes built-in support for [OpenTelemetry](https://opentelemetry.io/) distributed tracing and metrics using the native .NET `System.Diagnostics` APIs. No dependency on the OpenTelemetry SDK is required in the provider itself — your application opts in by configuring the appropriate listeners.

## Distributed Tracing

The provider emits `Activity` spans for database command execution using `System.Diagnostics.ActivitySource`.

### Enabling Traces

```csharp
using OpenTelemetry.Trace;

var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSource(FirebirdSql.Data.FirebirdClient.FbTelemetry.ActivitySourceName)
.AddConsoleExporter() // or any other exporter
.Build();
```

The `ActivitySource` name is `"FirebirdSql.Data"`, also available as the constant `FbTelemetry.ActivitySourceName`.

### Span Attributes

Spans follow the [OTel Database Client Semantic Conventions](https://opentelemetry.io/docs/specs/semconv/database/database-spans/):

| Attribute | Description |
|-----------|-------------|
| `db.system.name` | Always `"firebirdsql"` |
| `db.namespace` | The database name from the connection |
| `db.operation.name` | The SQL verb (`SELECT`, `INSERT`, etc.) or `EXECUTE PROCEDURE` |
| `db.collection.name` | The table name (for `TableDirect` commands) |
| `db.stored_procedure.name` | The stored procedure name (for `StoredProcedure` commands) |
| `db.query.summary` | A low-cardinality summary of the operation |
| `db.query.text` | The full SQL text (**opt-in**, see below) |
| `db.query.parameter.*` | Parameter values (**opt-in**, see below) |
| `server.address` | The database server hostname |
| `server.port` | The database server port (only when non-default, i.e. != 3050) |
| `error.type` | The SQLSTATE code (for `FbException`) or exception type name |

### Opt-In Sensitive Attributes

By default, `db.query.text` and `db.query.parameter.*` are **not** collected, as they may contain sensitive data. Enable them explicitly:

```csharp
using FirebirdSql.Data.Logging;

// Enable SQL text in traces
FbLogManager.EnableQueryTextTracing();

// Enable parameter values in traces (and logs)
FbLogManager.EnableParameterLogging();
```

## Metrics

The provider emits metrics via `System.Diagnostics.Metrics.Meter`.

### Enabling Metrics

```csharp
using OpenTelemetry.Metrics;

var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter(FirebirdSql.Data.FirebirdClient.FbTelemetry.MeterName)
.AddConsoleExporter() // or any other exporter
.Build();
```

The `Meter` name is `"FirebirdSql.Data"`, also available as the constant `FbTelemetry.MeterName`.

### Available Metrics

Metrics follow the [OTel Database Client Metrics Semantic Conventions](https://opentelemetry.io/docs/specs/semconv/database/database-metrics/):

| Metric | Type | Unit | Description |
|--------|------|------|-------------|
| `db.client.operation.duration` | Histogram | `s` | Duration of database client operations |
| `db.client.connection.create_time` | Histogram | `s` | Time to create a new connection |
| `db.client.connection.count` | ObservableUpDownCounter | `{connection}` | Current connection count by state (`idle`/`used`) |
| `db.client.connection.max` | ObservableUpDownCounter | `{connection}` | Maximum number of open connections allowed |
23 changes: 23 additions & 0 deletions run-benchmark.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
param(
[ValidateSet('CommandBenchmark','ConnectionBenchmark','LargeFetchBenchmark')]
$Benchmark = 'CommandBenchmark',

[switch]$Disasm,
[switch]$Profile
)

$ErrorActionPreference = 'Stop'

$projectFile = '.\src\FirebirdSql.Data.FirebirdClient.Benchmarks\FirebirdSql.Data.FirebirdClient.Benchmarks.csproj'

$extraArgs = @()
if ($Disasm) { $extraArgs += '--disasm' }
if ($Profile) { $extraArgs += '--profiler', 'ETW' }

# Run selected benchmark
dotnet run `
--project $projectFile `
--configuration 'Release' `
-- `
--filter "*$($Benchmark)*" `
@extraArgs
41 changes: 41 additions & 0 deletions src/FirebirdSql.Data.FirebirdClient.Benchmarks/BenchmarkBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* https://github.com/FirebirdSQL/NETProvider/raw/master/license.txt.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* All Rights Reserved.
*/

//$Authors = Jiri Cincura (jiri@cincura.net)

using System;
using BenchmarkDotNet.Attributes;

namespace FirebirdSql.Data.FirebirdClient.Benchmarks;

public abstract class BenchmarkBase
{
const string DefaultConnectionString = "database=localhost:benchmark.fdb;user=sysdba;password=masterkey";

protected static readonly string ConnectionString =
Environment.GetEnvironmentVariable("FIREBIRD_BENCHMARK_CS") ?? DefaultConnectionString;

protected static void CreateDatabase(int pageSize = 16 * 1024)
{
FbConnection.CreateDatabase(ConnectionString, pageSize, false, true);
}

[GlobalCleanup]
public void GlobalCleanup()
{
FbConnection.ClearAllPools();
FbConnection.DropDatabase(ConnectionString);
}
}
64 changes: 64 additions & 0 deletions src/FirebirdSql.Data.FirebirdClient.Benchmarks/BenchmarkConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* https://github.com/FirebirdSQL/NETProvider/raw/master/license.txt.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* All Rights Reserved.
*/

//$Authors = Jiri Cincura (jiri@cincura.net)

using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Order;
using BenchmarkDotNet.Toolchains;
using BenchmarkDotNet.Toolchains.CsProj;
using BenchmarkDotNet.Toolchains.DotNetCli;
using BenchmarkDotNet.Validators;

namespace FirebirdSql.Data.FirebirdClient.Benchmarks;

class BenchmarkConfig : ManualConfig
{
static readonly IToolchain Net100Toolchain =
CsProjCoreToolchain.From(new NetCoreAppSettings("net10.0", null, ".NET 10"));

public BenchmarkConfig()
{
var baseJob = Job.Default
.WithWarmupCount(3);

AddJob(
baseJob
.WithToolchain(Net100Toolchain)
.WithCustomBuildConfiguration("ReleaseNuGet")
.WithId("NuGet100")
.AsBaseline()
);

AddJob(
baseJob
.WithToolchain(Net100Toolchain)
.WithCustomBuildConfiguration("Release")
.WithId("Core100")
);

AddDiagnoser(MemoryDiagnoser.Default);

AddExporter(MarkdownExporter.GitHub);

Orderer = new DefaultOrderer(SummaryOrderPolicy.FastestToSlowest);

AddValidator(BaselineValidator.FailOnError);
AddValidator(JitOptimizationsValidator.FailOnError);
}
}
Loading
Loading