Skip to content

Commit a63e70b

Browse files
committed
fixed PostgreSQL DSN
1 parent dcf97ed commit a63e70b

File tree

5 files changed

+47
-32
lines changed

5 files changed

+47
-32
lines changed

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,21 @@ However I needed to do more complex and fundamental customization, such as addin
1313

1414
I would like to thank Peter Zaitsev, Alexy Kopytov and contributors for inventing great tool [sysbench](https://github.com/akopytov/sysbench).
1515

16-
## How to install
16+
## Install
1717

1818
```
19-
go install github.com/samitani/go-sysbench/cmd/go-sysbench@main
19+
go install github.com/samitani/go-sysbench/cmd/go-sysbench@latest
2020
```
2121

22-
## Incompatibility with sysbench
22+
## Usage
23+
24+
### General Syntax
25+
26+
### Options
2327

24-
* `go-sysbench` supports only `oltp_read_only` and `oltp_read_write` database benchmarks. Linux benchmarks such as `fileio`, `cpu`, `memory` are not supported.
25-
* Some options are not implemented. `go-sysbench oltp_read_write run --help` shows available options.
2628
```
2729
$ go-sysbench oltp_read_write run --help
28-
2025/02/05 22:55:07 Usage:
30+
2025/02/08 12:27:31 Usage:
2931
go-sysbench [OPTIONS] oltp_read_write run [run-OPTIONS]
3032
3133
Help Options:
@@ -47,15 +49,22 @@ Help Options:
4749
--mysql-password= MySQL password [$MYSQL_PWD]
4850
--mysql-db= MySQL database name (default: sbtest)
4951
--mysql-ssl=[on|off] use SSL connections (default: off)
52+
--mysql-ignore-errors= list of errors to ignore, or "all" (default: 1213,1020,1205)
5053
--pgsql-host= PostgreSQL server host (default: localhost)
5154
--pgsql-port= PostgreSQL server port (default: 5432)
5255
--pgsql-user= PostgreSQL user (default: sbtest)
5356
--pgsql-password= PostgreSQL password [$PGPASSWORD]
5457
--pgsql-db= PostgreSQL database name (default: sbtest)
58+
--pgsql-ssl=[on|off] use SSL connections (default: off)
5559
--spanner-project= Spanner Google Cloud project name
5660
--spanner-instance= Spanner instance id
5761
--spanner-db= Spanner database name (default: sbtest)
5862
```
63+
64+
## Incompatibility with sysbench
65+
66+
* `go-sysbench` supports only `oltp_read_only` and `oltp_read_write` database benchmarks. Linux benchmarks such as `fileio`, `cpu`, `memory` are not supported.
67+
* Some options are not implemented. See Options section above.
5968
* Number of reconnects is not reported.
6069
* Lua scripts is not supported. To customize the benchmark scenario, you have to edit the code directly.
6170

benchmark/benchmark.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ type (
1616
Event(context.Context) (uint64, uint64, uint64, uint64, error)
1717
}
1818
CommonOpts struct {
19-
Tables int `long:"tables" description:"number of tables" default:"1"`
20-
TableSize int `long:"table_size" description:"number of rows per table" default:"10000"`
21-
DBDriver string `long:"db-driver" choice:"mysql" choice:"pgsql" choice:"spanner" description:"specifies database driver to use" default:"mysql"` //nolint:staticcheck
22-
ReadWrite bool
19+
Tables int `long:"tables" description:"number of tables" default:"1"`
20+
TableSize int `long:"table_size" description:"number of rows per table" default:"10000"`
21+
DBDriver string `long:"db-driver" choice:"mysql" choice:"pgsql" choice:"spanner" description:"specifies database driver to use" default:"mysql"` //nolint:staticcheck
22+
DBPreparedStmt string `long:"db-ps-mode" choice:"auto" choice:"disable" description:"prepared statements usage mode" default:"auto"` //nolint:staticcheck
23+
ReadWrite bool
2324
}
2425
BenchmarkOpts struct {
2526
CommonOpts

benchmark/oltpbench.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ const (
6060
// Number of DELETE/INSERT combinations per transaction
6161
numDeleteInserts = 1
6262

63-
OptSSLOn = "on"
64-
OptSSLOff = "off"
65-
OptMySQLIgnoreErrsAll = "all"
63+
OptSSLOn = "on"
64+
OptSSLOff = "off"
65+
OptMySQLIgnoreErrsAll = "all"
66+
OptDBPreparedStmtAuto = "auto"
67+
OptDBPreparedStmtDisable = "disable"
6668
)
6769

6870
type (
@@ -296,7 +298,15 @@ func (o *OLTPBench) dsnMySQL() string {
296298
} else {
297299
tlsParam = "false"
298300
}
299-
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?tls=%s", o.opts.MySQLUser, o.opts.MySQLPassword, o.opts.MySQLHost, o.opts.MySQLPort, o.opts.MySQLDB, tlsParam)
301+
/*
302+
if o.opts.DBPreparedStmt == OptDBPreparedStmtDisable {
303+
interpolateParams = "true"
304+
} else {
305+
interpolateParams = "false"
306+
}
307+
*/
308+
309+
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?tls=%s&interpolateParams=%s", o.opts.MySQLUser, o.opts.MySQLPassword, o.opts.MySQLHost, o.opts.MySQLPort, o.opts.MySQLDB, tlsParam, "false")
300310
}
301311

302312
func (o *OLTPBench) dsnPgSQL() string {
@@ -306,8 +316,7 @@ func (o *OLTPBench) dsnPgSQL() string {
306316
} else {
307317
sslParam = "disable"
308318
}
309-
310-
return fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=%s", o.opts.PgSQLUser, o.opts.PgSQLPassword, o.opts.PgSQLHost, o.opts.PgSQLPort, o.opts.PgSQLDB, sslParam)
319+
return fmt.Sprintf("user=%s password=%s host=%s port=%d dbname=%s sslmode=%s", o.opts.PgSQLUser, o.opts.PgSQLPassword, o.opts.PgSQLHost, o.opts.PgSQLPort, o.opts.PgSQLDB, sslParam)
311320
}
312321

313322
func (o *OLTPBench) dsnSpanner() string {

cmd/go-sysbench/main.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@ package main
77
// 11. README に 性能差分について書く
88
// 12. thread fairness の計算
99

10-
// 31. PostgreSQL の DSN のエスケープ
11-
// 32. DSNの生成に各ドライバのモジュールを利用する
10+
// 20. PreparedStatement の実装
1211

13-
// 41. 乱数生成をクエリを投げる前段階で行う
14-
// 42. PreparedStatement の実装
12+
// 31. 乱数生成をクエリを投げる前段階で行う
1513

16-
// 51. カスタムシナリオを書く
14+
// 40. --mysql-ignore-errors の場合 others にカウントする
15+
// 41. 空振りクエリはotherにカウントする
1716

18-
// 60. --mysql-ignore-errors の場合 others にカウントする
19-
// 61. 空振りクエリはotherにカウントする
17+
// 50. README に 日本語を書く
18+
// 51. README に 実行方法について書く
2019

21-
// 70. README に 日本語を書く
22-
// 72. README に 実行方法について書く
23-
// 73. README に フラグの順番の制約
20+
// 60. フラグの順番の制約解除
21+
22+
// 70. [bug] --events が正しく機能しない
2423

2524
import (
2625
"log"

runner/runner.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (r *Runner) Run(bench benchmark.Benchmark) error {
147147
go func() {
148148
defer wg.Done()
149149

150-
var pe error = nil
150+
//var pe error = nil
151151
var eventBegin time.Time
152152

153153
for {
@@ -164,11 +164,8 @@ func (r *Runner) Run(bench benchmark.Benchmark) error {
164164
eventBegin = time.Now()
165165
reads, writes, others, errs, err := bench.Event(ctx)
166166
if err != nil && err != context.DeadlineExceeded && err != context.Canceled {
167-
// ignore same error
168-
if pe == nil || pe.Error() != err.Error() {
169-
pe = err
170-
fmt.Println(err.Error())
171-
}
167+
fmt.Println(err.Error())
168+
cancel()
172169
}
173170
latency := time.Since(eventBegin).Nanoseconds()
174171

0 commit comments

Comments
 (0)