{"id":20049597,"url":"https://github.com/iwanbk/gosqlbencher","last_synced_at":"2025-06-30T06:04:20.551Z","repository":{"id":57611983,"uuid":"148161409","full_name":"iwanbk/gosqlbencher","owner":"iwanbk","description":"Tool to benchmark Go SQL ecosystem: query, Go database/sql funcs usage, driver, and the server","archived":false,"fork":false,"pushed_at":"2019-02-02T06:44:03.000Z","size":512,"stargazers_count":9,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-05T11:42:05.413Z","etag":null,"topics":["benchmark","golang","mysql","postgresql","sql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iwanbk.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}},"created_at":"2018-09-10T13:41:21.000Z","updated_at":"2024-03-02T15:44:47.000Z","dependencies_parsed_at":"2022-08-27T10:10:45.472Z","dependency_job_id":null,"html_url":"https://github.com/iwanbk/gosqlbencher","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/iwanbk/gosqlbencher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iwanbk%2Fgosqlbencher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iwanbk%2Fgosqlbencher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iwanbk%2Fgosqlbencher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iwanbk%2Fgosqlbencher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iwanbk","download_url":"https://codeload.github.com/iwanbk/gosqlbencher/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iwanbk%2Fgosqlbencher/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260665166,"owners_count":23044266,"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","golang","mysql","postgresql","sql"],"created_at":"2024-11-13T11:51:13.139Z","updated_at":"2025-06-19T01:38:48.826Z","avatar_url":"https://github.com/iwanbk.png","language":"Go","readme":"# gosqlbencher\n\n[![Build Status](https://travis-ci.org/iwanbk/gosqlbencher.svg?branch=master)](https://travis-ci.org/iwanbk/gosqlbencher)\n[![Go Report Card](https://goreportcard.com/badge/github.com/iwanbk/gosqlbencher)](https://goreportcard.com/report/github.com/iwanbk/gosqlbencher)\n[![codecov](https://codecov.io/gh/iwanbk/gosqlbencher/branch/master/graph/badge.svg)](https://codecov.io/gh/iwanbk/gosqlbencher)\n\nTool to benchmark Go SQL ecosystem: query, [database/sql](https://golang.org/pkg/database/sql/)funcs usage, driver, and the server.\n\n## Why using this tool \n\nWhy using this tool instead of existing tools like pgbench and SysBench?\n\nGo's [database/sql](https://golang.org/pkg/database/sql/) package has it's own behaviour that different with \nboth `pgbench` and `SysBench`. It already has it's own connection pool and also has it's own way to manage\nthe database connection and prepared statements.\n\n## Things to observe/benchmark\n\nThere are many things we could observe/benchmark with this tool\n\n#### Database server\n\nPlay with your DB server settings and benchmark it againts your query.\n\n#### Database query\n\n##### Test various queries like exec, query, and query_row.\n\nSupported DB queries:\n- [x] Exec\n- [x] ExecContext\n- [x] Query\n- [x] QueryContext\n- [ ] QueryRow\n- [ ] QueryRowContext\n- [ ] Transaction\n\nTODO : scan the result of `Query%` queries.\n\n##### Test between using prepared statement, placeholder, and plain query.\n\nSupported query modes:\n- prepared statement:\n  - create it once on the initialization\n  - create it on each query\n- using placeholder (e.g.: `$1` in postgresql)\n- plain query (e.g. using Go's `%d` and `%s`)\n\n#### Driver\n\nEasily switch between supported drivers and see the difference.\n\nSupported drivers:\n- [x] github.com/lib/pq (driver_name : postgres)\n- [x] github.com/jackc/pgx (driver_name : pgx)\n- [x] github.com/ziutek/mymysql (driver name: mymysql)\n- [x] github.com/go-sql-driver/mysql (driver name: mysql)\n- [] github.com/mattn/go-sqlite3\n\n#### Database Settings\n\n- see how [SetMaxOpenConns](golang.org/pkg/database/sql/#DB.SetMaxOpenConns) affect the performance\n\n#### Number of concurrent goroutines/requests\n\n`num_worker` option set the number of goroutines which execute the queries.\nIn web application, it simulates the number of concurrent requests you have at any given time.\n\n#### Go Profiling Data\n\nIt could generate Go profiling data with `prof-mode` option, so we could have better insight about how SQL package work under various scenarios.\n\n## Configuration\n\nThe `gosqlbencher` configuration is called `plan` file. It is called `plan` instead of `config` because it is not a mere config, it contatins the benchmarking procedures to be executed by `gosqlbencher`.\n\nThe best docs for the configuration right now is the `godoc` page for [`Plan`](https://godoc.org/github.com/iwanbk/gosqlbencher/plan#Plan).\n\nThere are also benchmark plan examples in [examples](./examples) directory.\n\n## How It Works\n\n1. Query is benchmarked by allowing query to be specified in the plan file. It supports two mode on substituing the value in query:\n- placholder: something like `$1` in postgresql or `?` in mysql is supported\n- standard Go `fmt`: using `%d` for integer or `%s` for string\n\nThe value will then be generated `randomly` or `sequentially` on execution, it depends on the plan file.\n\n2. [database/sql](https://golang.org/pkg/database/sql/) funcs usage is benchmarked by supporting below query execution:\n- prepare on initialization: query will be executed in prepared statement, which will only be created on initialization\n- prepare: prepared statement will be executed right before executing the query\n- SQL placholder usage\n- Plain query without SQL placeholder, possibly using Go formatting\n\n3. Driver could be specified as well in the plan file, so we could easily see the performance between drivers.\n\nSee [driver](#driver) section to see the list of available drivers\n\n4. Database Settings\n\nCurrent database setting supported is only max open connections, which can be configured in the plan file.\n\n## Quick Start\n\nBuild\n```bash\ngo build -v\n```\n\nSee the help\n\n```bash\n$ ./gosqlbencher -h\nUsage of ./gosqlbencher:\n  -plan string\n        gosqlbencher plan file (default \"plan.yaml\")\n  -prof-dir string\n        dir where profiling files are written (default \"prof\")\n  -prof-mode string\n        profiling mode:block,cpu, mem, mutex\n\n```\n\nStart postgresql server using the provided docker compose\n```\n$ docker-compose -f examples/docker-compose-postgresql.yaml up -d --build\nCreating network \"examples_default\" with the default driver\nCreating postgres-gosqlbencher ... done\n```\n\nCreate test table and execute `insert` test\n```bash\n$ ./gosqlbencher -plan=examples/insert.plan.postgre.yaml \n```\n\nExecute various `select` tests\n```bash\n ./gosqlbencher -plan=examples/query.plan.postgre.yaml \n```\n\nProfiling the CPU for SQL query, with prepared statement created on each query\n```bash\n$ $ ./gosqlbencher -plan=examples/query.plan.postgre.profile.yaml -prof-mode=cpu -prof-dir=prof\n```\nIt currently has limitation to only able to profile one query\n\nCreate pdf version of the profiling data\n```\ngo tool pprof -pdf prof/cpu.pprof \u003e ~/Desktop/cpuprof.pdf\n```\nCheck the `pdf` in `~/Desktop/cpuprof.pd`\n\nTry different scenario in the `plan` file and compare the profiling data \u0026 performance, for example:\n- set different number of `max_open_conns`\n- set `prepare_on_init` to `true`: it usually will improve the performance\n\n## TODO\n\n- add support for sqlite\n- plan file validation","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiwanbk%2Fgosqlbencher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiwanbk%2Fgosqlbencher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiwanbk%2Fgosqlbencher/lists"}