{"id":13412083,"url":"https://github.com/sj14/dbbench","last_synced_at":"2025-04-04T15:07:42.356Z","repository":{"id":37390851,"uuid":"158938377","full_name":"sj14/dbbench","owner":"sj14","description":"🏋️ dbbench is a simple database benchmarking tool which supports several databases and own scripts","archived":false,"fork":false,"pushed_at":"2025-03-26T13:54:20.000Z","size":1112,"stargazers_count":105,"open_issues_count":10,"forks_count":19,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-28T14:06:26.460Z","etag":null,"topics":["benchmark","cassandra","cockroachdb","database","golang","hacktoberfest","mariadb","mssql","mysql","postgresql","scylladb","sqlite","stress-testing"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sj14.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-24T13:21:18.000Z","updated_at":"2025-03-26T13:54:23.000Z","dependencies_parsed_at":"2024-02-22T11:28:20.334Z","dependency_job_id":"a92f5313-cd9f-411d-bd5e-32720555980b","html_url":"https://github.com/sj14/dbbench","commit_stats":{"total_commits":481,"total_committers":8,"mean_commits":60.125,"dds":0.4656964656964657,"last_synced_commit":"e0bee94393e79491cb21bfe6b691b66d1e6483ef"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sj14%2Fdbbench","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sj14%2Fdbbench/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sj14%2Fdbbench/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sj14%2Fdbbench/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sj14","download_url":"https://codeload.github.com/sj14/dbbench/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198450,"owners_count":20900080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmark","cassandra","cockroachdb","database","golang","hacktoberfest","mariadb","mssql","mysql","postgresql","scylladb","sqlite","stress-testing"],"created_at":"2024-07-30T20:01:20.828Z","updated_at":"2025-04-04T15:07:42.332Z","avatar_url":"https://github.com/sj14.png","language":"Go","funding_links":[],"categories":["Database","Testing","Go","数据库","sqlite","Data Integration Frameworks","数据库  `go语言实现的数据库`","Generators","Uncategorized"],"sub_categories":["Database Tools","数据库工具","Advanced Console UIs"],"readme":"# dbbench\n\n![Action](https://github.com/sj14/dbbench/workflows/Go/badge.svg)\n[![Go Report Card](https://goreportcard.com/badge/github.com/sj14/dbbench)](https://goreportcard.com/report/github.com/sj14/dbbench)\n[![Coverage Status](https://coveralls.io/repos/github/sj14/dbbench/badge.svg?branch=master)](https://coveralls.io/github/sj14/dbbench?branch=master)\n\n## Table of Contents\n\n- [Description](#description)\n- [Example](#example)\n- [Installation](#installation)\n- [Supported Databases](#supported-Databases-/-Driver)\n- [Usage](#usage)\n- [Custom Scripts](#custom-scripts)\n- [Troubeshooting](#troubleshooting)\n- [Development](#development)\n- [Acknowledgements](#acknowledgements)\n\n## Description\n\n`dbbench` is a simple tool to benchmark or stress test databases. You can use the simple built-in benchmarks or run your own queries.  \n\n**Attention**: This tool comes with no warranty. Don't run it on production databases.\n\n## Example\n\n``` text\n$ dbbench postgres --user postgres --pass example --iter 100000\ninserts 6.199670776s    61996   ns/op\nupdates 7.74049898s     77404   ns/op\nselects 2.911541197s    29115   ns/op\ndeletes 5.999572479s    59995   ns/op\ntotal: 22.85141994s\n```\n\n## Installation\n\n### Precompiled Binaries\n\nBinaries are available for all major platforms. See the [releases](https://github.com/sj14/dbbench/releases) page. Unfortunately, `cgo` is disabled for these builds, which means there is *no SQLite support* ([#1](https://github.com/sj14/dbbench/issues/1)).\n\n### Homebrew\n\nUsing the [Homebrew](https://brew.sh/) package manager for macOS:\n\n```console\nbrew install sj14/tap/dbbench\n```\n\n### Manually\n\nIt's also possible to install the current development snapshot with `go get` (not recommended):\n\n```console\ngo get -u github.com/sj14/dbbench/cmd/dbbench\n```\n\n### Docker\n\n```console\ndocker run ghcr.io/sj14/dbbench:latest\n```\n\nCheck [here](https://github.com/sj14/dbbench/pkgs/container/dbbench) for available images.\n\n## Supported Databases / Driver\n\nDatabases | Driver\n----------|-----------\nCassandra and compatible databases (e.g. ScyllaDB) | github.com/gocql/gocql\nMS SQL and compatible databases (no built-in benchmarks yet) | github.com/denisenkom/go-mssqldb\nMySQL and compatible databases (e.g. MariaDB and TiDB) | github.com/go-sql-driver/mysql\nPostgreSQL and compatible databases (e.g. CockroachDB) | github.com/lib/pq\nSQLite3 and compatible databases | github.com/mattn/go-sqlite3\n\n## Usage\n\n``` text\nAvailable subcommands:\n        cassandra|cockroach|mssql|mysql|postgres|sqlite\n        Use 'subcommand --help' for all flags of the specified command.\nGeneric flags for all subcommands:\n      --clean            only cleanup benchmark data, e.g. after a crash\n      --iter int         how many iterations should be run (default 1000)\n      --noclean          keep benchmark data\n      --noinit           do not initialize database and tables, e.g. when only running own script\n      --run string       only run the specified benchmarks, e.g. \"inserts deletes\" (default \"all\")\n      --script string    custom sql file to execute\n      --sleep duration   how long to pause after each single benchmark (valid units: ns, us, ms, s, m, h)\n      --threads int      max. number of green threads (iter \u003e= threads \u003e 0) (default 25)\n      --version          print version information\n```\n\n## Custom Scripts\n\nYou can run your own SQL statements with the `--script` flag. You can use the auto-generate tables. Beware the file size as it will be completely loaded into memory.\n\nThe script must contain valid SQL statements for your database.\n\nThere are some built-in variables and functions which can be used in the script. It's using the golang [template engine](https://golang.org/pkg/text/template/) which uses the delimiters `{{` and `}}`. Functions are executed with the `call` command and arguments are passed after the function name.\n\n### Benchmark Settings\n\nA new benchmark is created with the `\\benchmark` keyword, followed by either `once` or `loop`. Optional parameters can be added afterwards in the same line.\n\nThe the usage description and the example subsection for more information.\n\nUsage                     | Description                                   |\n--------------------------|-----------------------------------------------|\n`\\benchmark once`                | Execute the following statements (lines) only once (e.g. to create and delete tables).\n`\\benchmark loop`                | Default mode. Execute the following statements (lines) in a loop. Executes them one after another and then starts a new iteration. Add another `\\benchmark loop` to start another benchmark of statements.\n`\\name insert`              | Set a custom name for the DB statement(s), which will be output instead the line numbers (`insert` is an examplay name).\n\n### Statement Substitutions\n\nUsage                     | Description                                   |\n--------------------------|-----------------------------------------------|\n`{{.Iter}}`                 | The iteration counter. Will return `1` when `\\benchmark once`.\n`{{call .RandInt64}}`       | [godoc](https://pkg.go.dev/math/rand/v2#Int64)\n`{{call .RandInt64N 9999}}` | [godoc](https://pkg.go.dev/math/rand/v2#Int64N) (`9999` is an examplary upper limit)\n`{{call .RandUint64}}`       | [godoc](https://pkg.go.dev/math/rand/v2#Uint64)\n`{{call .RandUint64N 9999}}` | [godoc](https://pkg.go.dev/math/rand/v2#Uint64N) (`9999` is an examplary upper limit)\n`{{call .RandFloat32}}`     | [godoc](https://pkg.go.dev/math/rand/v2#Float32)  \n`{{call .RandFloat64}}`     | [godoc](https://pkg.go.dev/math/rand/v2#Float64)\n`{{call .RandExpFloat64}}`  | [godoc](https://pkg.go.dev/math/rand/v2#ExpFloat64)\n`{{call .RandNormFloat64}}` | [godoc](https://pkg.go.dev/math/rand/v2#NormFloat64)\n\n### Example\n\nExemplary `sqlite_bench.sql` file:\n\n``` sql\n-- Create table\n\\benchmark once \\name init\nCREATE TABLE dbbench_simple (id INT PRIMARY KEY, balance DECIMAL);\n\n-- How long takes an insert and delete?\n\\benchmark loop \\name single\nINSERT INTO dbbench_simple (id, balance) VALUES({{.Iter}}, {{call .RandInt64}});\nDELETE FROM dbbench_simple WHERE id = {{.Iter}}; \n\n-- How long takes it in a single transaction?\n\\benchmark loop \\name batch\nBEGIN TRANSACTION;\nINSERT INTO dbbench_simple (id, balance) VALUES({{.Iter}}, {{call .RandInt64}});\nDELETE FROM dbbench_simple WHERE id = {{.Iter}}; \nCOMMIT;\n\n-- Delete table\n\\benchmark once \\name clean\nDROP TABLE dbbench_simple;\n```\n\nIn this script, we create and delete the table manually, thus we will pass the `--noinit` and `--noclean` flag, which would otherwise create this default table for us:\n\n``` text\ndbbench sqlite --script scripts/sqlite_bench.sql --iter 5000 --noinit --noclean\n```\n\noutput:\n\n``` text\n(once) init:    3.404784ms      3404784 ns/op\n(loop) single:  10.568390874s   2113678 ns/op\n(loop) batch:   5.739021596s    1147804 ns/op\n(once) clean:   1.065703ms      1065703 ns/op\ntotal: 16.312319959s\n```\n\n## Troubleshooting\n\n**Error message**\n\n``` text\nfailed to insert: UNIQUE constraint failed: dbbench_simple.id\n```\n\n**Description**\nThe previous data wasn't removed (e.g. because the benchmark was canceled). Try to run the same command again, but with the `--clean` flag attached, which will remove the old data. Then run the original command again.\n\n---\n\n**Error message**\n\n``` text\nfailed to create table: Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub\n```\n\n**Description**  \nCurrently, the released binary builds don't contain SQLite support. You have to compile dbbench manually, either from the particular release source code (recommended) or from the current master branch (not recommended).\n\n## Development\n\nBelow are some examples how to run different databases and the equivalent call of `dbbench` for testing/developing.\n\n### Cassandra\n\n``` text\ndocker run --name dbbench-cassandra -p 9042:9042 -d cassandra:latest\n```\n\n``` text\ndbbench cassandra\n```\n\n### CockroachDB\n\n``` text\n# port 8080 is the webinterface (optional)\ndocker run --name dbbench-cockroach -d -p 26257:26257 -p 8080:8080 cockroachdb/cockroach:latest start --insecure\n```\n\n``` text\ndbbench cockroach\n```\n\n### Microsoft SQL Server\n\n``` text\ndocker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -d microsoft/mssql-server-linux\n```\n\n``` text\ndbbench mssql -user sa -pass 'yourStrong(!)Password'\n```\n\n### MariaDB\n\n``` text\ndocker run --name dbbench-mariadb -p 3306:3306 -d -e MYSQL_ROOT_PASSWORD=root mariadb\n```\n\n``` text\ndbbench mariadb\n```\n\n### MySQL\n\n``` text\ndocker run --name dbbench-mysql -p 3306:3306 -d -e MYSQL_ROOT_PASSWORD=root mysql\n```\n\n``` text\ndbbench mysql\n```\n\n### PostgreSQL\n\n``` text\ndocker run --name dbbench-postgres -p 5432:5432 -d postgres\n```\n\n``` text\ndbbench postgres --user postgres --pass example\n```\n\n### ScyllaDB\n\n``` text\ndocker run --name dbbench-scylla -p 9042:9042 -d scylladb/scylla\n```\n\n``` text\ndbbench scylla\n```\n\n### SQLite\n\n``` text\ndbbench sqlite\n```\n\n### TiDB\n\n``` text\ngit clone https://github.com/pingcap/tidb-docker-compose.git\n```\n\n``` text\ncd tidb-docker-compose \u0026\u0026 docker-compose pull\n```\n\n``` text\ndocker-compose up -d\n```\n\n``` text\ndbbench tidb --pass '' --port 4000\n```\n\n## Acknowledgements\n\nThanks to the authors of Go and those of the directly and indirectly used libraries, especially the driver developers. It wouldn't be possible without all your work.\n\nThis tool was highly inspired by the snippet from user [Fale](https://github.com/cockroachdb/cockroach/issues/23061#issue-300012178) and the tool [pgbench](https://www.postgresql.org/docs/current/pgbench.html). Later, also inspired by [MemSQL's dbbench](https://github.com/memsql/dbbench) which had the name and a similar idea before.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsj14%2Fdbbench","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsj14%2Fdbbench","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsj14%2Fdbbench/lists"}