Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2b3905c
Adds FbTransactionInfo.GetTransactionId().
fdcastel Oct 25, 2024
7693055
Adds .NET distributed tracing instrumentation.
fdcastel Oct 25, 2024
4ef4ceb
Add metrics.
fdcastel Oct 26, 2024
caf154c
Fix NullReferenceException when StartActivity returns null
fdcastel Mar 23, 2026
49ac081
Fix Stopwatch elapsed time conversion
fdcastel Mar 23, 2026
a19bd65
Rename db.system to db.system.name per OTel semantic conventions v1.40+
fdcastel Mar 23, 2026
259bf5b
Set db.namespace attribute on spans from connection database name
fdcastel Mar 23, 2026
3863d5b
Set error.type attribute on failure spans
fdcastel Mar 23, 2026
43eff96
Gate db.query.text and db.query.parameter.* behind opt-in flags
fdcastel Mar 23, 2026
18de3ee
Read ActivitySource/Meter version from assembly metadata
fdcastel Mar 23, 2026
1556b05
Fix activity lifecycle: record metrics on error path, prevent stale r…
fdcastel Mar 23, 2026
b3739dc
Remove non-standard and deprecated telemetry attributes
fdcastel Mar 23, 2026
25b2457
Add server.port, db.stored_procedure.name; fix server.address in metrics
fdcastel Mar 23, 2026
25a5bbf
Add db.query.summary and db.operation.name for Text commands
fdcastel Mar 23, 2026
d0e513c
Add debug assertions in TraceCommandStop and TraceCommandException
fdcastel Mar 23, 2026
8007f3d
Initialize MetricsConnectionAttributes to empty array
fdcastel Mar 23, 2026
0cf25aa
Avoid dictionary allocation in observable metric callbacks
fdcastel Mar 23, 2026
55bfb50
Add InstrumentAdvice with histogram bucket boundaries on .NET 9+
fdcastel Mar 23, 2026
6584b87
Add FbTelemetry public class with ActivitySource and Meter names
fdcastel Mar 23, 2026
3b5e155
Add OpenTelemetry integration documentation
fdcastel Mar 23, 2026
e1ad719
Fix IndexOfAny compilation on all target frameworks
fdcastel Mar 23, 2026
96c596d
Refactor: Benchmarks.
fdcastel Oct 26, 2024
dfde2ae
Updates run-benchmark.ps1.
fdcastel May 18, 2025
554807d
Fix solution file: update benchmark project path and folder name
fdcastel Mar 23, 2026
fedb3c9
Add LargeFetchBenchmark for bulk read throughput across data types
fdcastel Mar 23, 2026
bffabe8
Extract shared BenchmarkConfig to eliminate duplication
fdcastel Mar 23, 2026
d60ebd2
Extract BenchmarkBase with shared ConnectionString and env-var override
fdcastel Mar 23, 2026
3ea32fb
Update benchmark toolchain from .NET 8 to .NET 10
fdcastel Mar 23, 2026
eda44be
Add GitHub Markdown exporter and fastest-to-slowest ordering
fdcastel Mar 23, 2026
a66c5fa
Replace single-value [Params] with constants
fdcastel Mar 23, 2026
a150a18
Return values from Fetch benchmarks to prevent dead-code elimination
fdcastel Mar 23, 2026
3a8e509
Add async benchmark variants for Execute and Fetch
fdcastel Mar 23, 2026
c56595f
Add connection open/close benchmark
fdcastel Mar 23, 2026
2359fa3
Add -Disasm and -Profile flags to run-benchmark.ps1
fdcastel Mar 23, 2026
3e12746
Fix build errors: remove duplicate braces, add missing using
fdcastel Mar 23, 2026
9d42b35
Add benchmark documentation
fdcastel Mar 23, 2026
46db5a1
Add CHAR UTF8 coverage to CommandBenchmark and document regression de…
fdcastel May 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
128 changes: 128 additions & 0 deletions docs/benchmark.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# 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** (`NuGet100`): `ReleaseNuGet` build configuration — references a pinned released `FirebirdSql.Data.FirebirdClient` NuGet package (currently `10.3.1`, set in the benchmark `.csproj`).
- **Candidate job** (`Core100`): `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 (unreleased) provider against the **last released version**, so a regression introduced on a branch shows up before it ships. The baseline version is intentionally pinned for reproducible results — bump it to the newest stable release when cutting a release, so "regression vs. last release" stays meaningful.

## Interpreting results

For the fetch and connection benchmarks the **`Mean` is dominated by network/server I/O and is noisy** (look at `StdDev` — it is often a large fraction of the mean). Small or even moderate `Mean` differences between the baseline and candidate jobs are frequently just noise.

The **`Allocated` column (and `Alloc Ratio` vs. the baseline) is the primary signal** for provider-side regressions: managed allocations are deterministic and independent of I/O timing. When comparing the `Core100` (local) job against the `NuGet100` (released) baseline, an `Alloc Ratio` well above `1.00` means the local code allocates more than the last release.

Worked example — issue [#1272](https://github.com/FirebirdSQL/NETProvider/issues/1272): fetching `CHAR(255) CHARACTER SET UTF8` regressed from `369.8 MB` to `4339 MB` allocated (≈11.7×). The allocation column shows the regression far more sharply and reliably than the I/O-bound `Mean` — which is why string/UTF8 `CHAR` types are part of the suite.

## Available Benchmarks

### `CommandBenchmark`

Measures command execution over three data types (`BIGINT`, `VARCHAR(10) CHARACTER SET UTF8`, `CHAR(100) CHARACTER SET UTF8`). The fixed-length `CHAR ... UTF8` type exercises the per-code-point rune handling on both the read (fetch) and write (parameter validate) paths:

| 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