func benchmarkProfileEvents(ctx context.Context, conn clickhouse.Conn) error {
for i := 0; i < 10_000; i++ {
err := conn.Exec(ctx, fmt.Sprintf(`INSERT INTO test_profile_events VALUES (
%d, '%s', [1, 2, 3, 4, 5, 6, 7, 8, 9], now()
)`, i, "Golang SQL database driver"), false)
if err != nil {
return err
}
}
return nil
}
func BenchmarkProfileEvents(b *testing.B) {
conn, err := tests.GetConnectionTCP("issues", nil, nil, nil)
ctx := context.Background()
require.NoError(b, err)
const ddl = `CREATE TABLE test_profile_events (Col1 UInt64, Col2 String, Col3 Array(UInt8), Col4 DateTime) Engine ReplacingMergeTree() ORDER BY Col1`
err = conn.Exec(ctx, ddl)
require.NoError(b, err)
defer func() {
conn.Exec(ctx, "DROP TABLE IF EXISTS test_profile_events")
}()
for k := 0; k < b.N; k++ {
require.NoError(b, benchmarkProfileEvents(ctx, conn))
}
}
BenchmarkProfileEvents-12 1 11126073667 ns/op 276147480 B/op 2349943 allocs/op
BenchmarkProfileEvents-12 1 11343169583 ns/op 85091152 B/op 860664 allocs/op
Observed
ClickHouse Go driver still scans profile events even when a
profileEventslistener is not set, causing unnecessary memory allocationsExpected behaviour
Ideally profile events could be disabled via a session setting, but
log_profile_events: 0doesn't seem to help here. Even iflog_profile_eventsis set to1, the Go driver shouldn't scan events if there's no listener.Code example
Example test
Details
Environment
clickhouse-goversion: v2.40.3CREATE TABLEstatements for tables involved: See test aboveMemory profile showing allocations
Benchmark results
Memory profile when skipping scanning profile events when a listener is not set
Benchmark results