feat: Initial release
Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
parent
37d5c2b1f7
commit
d1e3da5189
13 changed files with 442 additions and 0 deletions
73
main.go
Normal file
73
main.go
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
// AppName to store application name
|
||||
var AppName string = "benchito"
|
||||
|
||||
// AppVersion to set version at compilation time
|
||||
var AppVersion string = "9999"
|
||||
|
||||
// GitCommit to set git commit at compilation time (can be empty)
|
||||
var GitCommit string
|
||||
|
||||
// GoVersion to set Go version at compilation time
|
||||
var GoVersion string
|
||||
|
||||
func main() {
|
||||
|
||||
config := NewConfig()
|
||||
|
||||
version := flag.Bool("version", false, "Print version and exit")
|
||||
configFile := flag.String("config", "", "Configuration file")
|
||||
flag.StringVar(&config.Driver, "driver", "postgres", "Database driver (postgres or mysql)")
|
||||
flag.IntVar(&config.Connections, "connections", 1, "Number of concurrent connections to the database")
|
||||
flag.StringVar(&config.Query, "query", "SELECT /* "+AppName+" */ NOW();", "Query to execute for the benchmark")
|
||||
flag.DurationVar(&config.Duration, "duration", 1*time.Second, "Duration of the benchmark")
|
||||
flag.BoolVar(&config.Reconnect, "reconnect", false, "Force database reconnection between each queries")
|
||||
flag.StringVar(&config.DSN, "dsn", "", "Database cpnnection string")
|
||||
flag.StringVar(&config.Host, "host", "", "Host address of the database")
|
||||
flag.IntVar(&config.Port, "port", 0, "Port of the database")
|
||||
flag.StringVar(&config.User, "user", "", "Username of the database")
|
||||
flag.StringVar(&config.Password, "password", "", "Password of the database")
|
||||
flag.StringVar(&config.Database, "database", "", "Database name")
|
||||
flag.StringVar(&config.TLS, "tls", "", "TLS configuration")
|
||||
flag.Parse()
|
||||
|
||||
if *version {
|
||||
showVersion()
|
||||
return
|
||||
}
|
||||
|
||||
if *configFile != "" {
|
||||
err := config.Read(*configFile)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to read configuration file: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
config.ParseDSN()
|
||||
|
||||
benchmark, err := NewBenchmark(config.Connections, config.Duration, config.Driver, config.DSN, config.Query, config.Reconnect)
|
||||
if err != nil {
|
||||
log.Fatalf("Cannot perform benchmark: %v", err)
|
||||
}
|
||||
benchmark.Run()
|
||||
log.Printf("Queries: %.0f", benchmark.Queries())
|
||||
log.Printf("Queries per second: %.0f", benchmark.QueriesPerSecond())
|
||||
}
|
||||
|
||||
func showVersion() {
|
||||
if GitCommit != "" {
|
||||
AppVersion = fmt.Sprintf("%s-%s", AppVersion, GitCommit)
|
||||
}
|
||||
fmt.Printf("%s version %s (compiled with %s)\n", AppName, AppVersion, GoVersion)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue