Sqlbench runs benchmarks on an SQL database

sqlbench runs benchmarks on an SQL database. Right now this works for PostgreSQL and SQLite.

You can install it with go install zgo.at/sqlbench@latest; by default it required cgo and a C compiler to build for SQLite, but if you're only interested in PostgreSQL you can use CGO_ENABLED=0 go install zgo.at/sqlbench@latest.


See the output of sqlbench -h for detailed help and all flags, but in brief, to run the testdata:

% sqlbench -concurrent 4 \
    -db     sqlite+/tmp/test.sqlite3 \
    -setup  testdata/schema.sql \
    -setup  cpu_usage:testdata/data.csv \
    -params testdata/params.csv \
    -query  'select * from cpu_usage where host=? and ts>=? and ts<=?'

Wall time:      9 ms
Run time:      27 ms
Min:            0 ms
Max:            1 ms
Median:         0 ms
Mean:           0 ms

Distribution:
    ≤ 0 ms → 194  ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 97.0%
    ≤ 0 ms →   3   1.5%
    ≤ 1 ms →   1   0.5%
    ≤ 1 ms →   2   1.0%

    Wall time:     66 ms
    Run time:     251 ms
    Min:            1 ms
    Max:           34 ms
    Median:         1 ms
    Mean:           1 ms

The database will be set up with the SQL schema in testdata/schema.sql, populated with the CSV file testdata/data.csv, and it will run the query once for every entry in testdata/params.csv. -concurrent 4 tells sqlbench to run four queries concurrently.

You can use PostgreSQL with e.g. -db postgres+dbname=test:

% sqlbench -concurrent 4 \
    -db     postgres+dbname=test \
    -setup  testdata/schema.sql \
    -setup  cpu_usage:testdata/data.csv \
    -params testdata/params.csv \
    -query  'select * from cpu_usage where host=? and ts>=? and ts<=?'

Wall time:     58 ms
Run time:     218 ms
Min:            1 ms
Max:           15 ms
Median:         1 ms
Mean:           1 ms

Distribution:
    ≤  2 ms → 194  ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 97.0%
    ≤ 13 ms →   1   0.5%
    ≤ 14 ms →   1   0.5%
    ≤ 15 ms →   4  ▬ 2.0%
Owner
Similar Resources

Prometheus metrics for Go database/sql via VictoriaMetrics/metrics

sqlmetrics Prometheus metrics for Go database/sql via VictoriaMetrics/metrics Features Simple API. Easy to integrate. Install Go version 1.16+ go get

Dec 16, 2022

Attach hooks to any database/sql driver

sqlhooks Attach hooks to any database/sql driver. The purpose of sqlhooks is to provide a way to instrument your sql statements, making really easy to

Jan 6, 2023

A go Library for scan database/sql rows to struct、slice、other types. And it support multiple databases connection management

ploto A go Library for scan database/sql rows to struct、slice、other types. And it support multiple databases connection management It's not an ORM. wo

Nov 3, 2022

Go database/sql

Go database/sql 源码阅读 基于 release-branch.go1.17 Benchmark 连接池测试 简单介绍 database/sql 库,包括结构体和主要的方法 介绍主要函数的调用逻辑 用OneNote看源码:Link 介绍最近几个版本的commit changes 结合实

Dec 18, 2021

Lightweight SQL database written in Go for prototyping and playing with text (CSV, JSON) data

gopicosql Lightweight SQL database written in Go for prototyping and playing wit

Jul 27, 2022

BigQuery database/sql golang driver

BigQuery SQL Driver This library is compatible with Go 1.17+ Please refer to CHA

Dec 7, 2022

A minimal, single-table No-SQL database.

SimpleDB SimpleDB is a very basic No-SQL database format for long-term data storage in Golang. It is WIP, has a LOT of drawbacks, and definitely is no

Jan 16, 2022

Otelsql - OpenTelemetry SQL database driver wrapper for Go

Otelsql - OpenTelemetry SQL database driver wrapper for Go

OpenTelemetry SQL database driver wrapper for Go Add a OpenTelemetry wrapper to

Dec 15, 2022

A go package to add support for data at rest encryption if you are using the database/sql.

go-lockset A go package to add support for data at rest encryption if you are using the database/sql to access your database. Installation In your Gol

Jan 30, 2022
SQLFlow is a compiler that compiles a SQL program to a workflow that runs on Kubernetes.
SQLFlow is a compiler that compiles a SQL program to a workflow that runs on Kubernetes.

SQLFlow is a compiler that compiles a SQL program to a workflow that runs on Kubernetes. The input is a SQL program that writt

Jan 9, 2023
write APIs using direct SQL queries with no hassle, let's rethink about SQL

SQLer SQL-er is a tiny portable server enables you to write APIs using SQL query to be executed when anyone hits it, also it enables you to define val

Jan 7, 2023
Parses a file and associate SQL queries to a map. Useful for separating SQL from code logic

goyesql This package is based on nleof/goyesql but is not compatible with it any more. This package introduces support for arbitrary tag types and cha

Oct 20, 2021
Go-sql-reader - Go utility to read the externalised sql with predefined tags

go-sql-reader go utility to read the externalised sql with predefined tags Usage

Jan 25, 2022
sqlx is a library which provides a set of extensions on go's standard database/sql library

sqlx is a library which provides a set of extensions on go's standard database/sql library. The sqlx versions of sql.DB, sql.TX, sql.Stmt, et al. all leave the underlying interfaces untouched, so that their interfaces are a superset on the standard ones. This makes it relatively painless to integrate existing codebases using database/sql with sqlx.

Jan 7, 2023
Dumpling is a fast, easy-to-use tool written by Go for dumping data from the database(MySQL, TiDB...) to local/cloud(S3, GCP...) in multifarious formats(SQL, CSV...).

?? Dumpling Dumpling is a tool and a Go library for creating SQL dump from a MySQL-compatible database. It is intended to replace mysqldump and mydump

Nov 9, 2022
Additions to Go's database/sql for super fast performance and convenience.

gocraft/dbr (database records) gocraft/dbr provides additions to Go's database/sql for super fast performance and convenience. $ go get -u github.com/

Jan 1, 2023
Interceptors for database/sql

sqlmw sqlmw provides an absurdly simple API that allows a caller to wrap a database/sql driver with middleware. This provides an abstraction similar t

Dec 27, 2022
OpenTelemetry instrumentation for database/sql

otelsql It is an OpenTelemetry instrumentation for Golang database/sql, a port from https://github.com/open-telemetry/opentelemetry-go-contrib/pull/50

Dec 28, 2022
Scan database/sql rows directly to structs, slices, and primitive types

Scan Scan standard lib database rows directly to structs or slices. For the most comprehensive and up-to-date docs see the godoc Examples Multiple Row

Dec 28, 2022