mirror of
https://codeberg.org/scip/pgidler.git
synced 2025-12-18 04:51:02 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e7df1aac7d | |||
| 2e3986f227 | |||
| 581956c8ec | |||
| d2a98920a9 | |||
| d4300204cd |
54
.goreleaser.yaml
Normal file
54
.goreleaser.yaml
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
|
||||||
|
|
||||||
|
version: 2
|
||||||
|
|
||||||
|
before:
|
||||||
|
hooks:
|
||||||
|
- go mod tidy
|
||||||
|
|
||||||
|
gitea_urls:
|
||||||
|
api: https://codeberg.org/api/v1
|
||||||
|
download: https://codeberg.org
|
||||||
|
|
||||||
|
builds:
|
||||||
|
- env:
|
||||||
|
- CGO_ENABLED=0
|
||||||
|
goos:
|
||||||
|
- linux
|
||||||
|
- darwin
|
||||||
|
- freebsd
|
||||||
|
|
||||||
|
archives:
|
||||||
|
- formats: [binary]
|
||||||
|
name_template: >-
|
||||||
|
{{ .ProjectName }}_
|
||||||
|
{{- title .Os }}_
|
||||||
|
{{- if eq .Arch "amd64" }}x86_64
|
||||||
|
{{- else if eq .Arch "386" }}i386
|
||||||
|
{{- else }}{{ .Arch }}{{ end }}
|
||||||
|
{{- if .Arm }}v{{ .Arm }}{{ end }}_{{ .Tag }}
|
||||||
|
wrap_in_directory: true
|
||||||
|
|
||||||
|
changelog:
|
||||||
|
sort: asc
|
||||||
|
filters:
|
||||||
|
exclude:
|
||||||
|
- "^docs:"
|
||||||
|
- "^test:"
|
||||||
|
groups:
|
||||||
|
- title: Improved
|
||||||
|
regexp: '^.*?(feat|add|new)(\([[:word:]]+\))??!?:.+$'
|
||||||
|
order: 0
|
||||||
|
- title: Fixed
|
||||||
|
regexp: '^.*?(bug|fix)(\([[:word:]]+\))??!?:.+$'
|
||||||
|
order: 1
|
||||||
|
- title: Changed
|
||||||
|
order: 999
|
||||||
|
|
||||||
|
release:
|
||||||
|
header: "# Release Notes"
|
||||||
|
footer: >-
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Full Changelog: [{{ .PreviousTag }}...{{ .Tag }}](https://codeberg.org/scip/pgidler/compare/{{ .PreviousTag }}...{{ .Tag }})
|
||||||
28
.woodpecker/build.yaml
Normal file
28
.woodpecker/build.yaml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
matrix:
|
||||||
|
platform:
|
||||||
|
- linux/amd64
|
||||||
|
goversion:
|
||||||
|
- 1.24
|
||||||
|
|
||||||
|
labels:
|
||||||
|
platform: ${platform}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
build:
|
||||||
|
when:
|
||||||
|
event: [push]
|
||||||
|
image: golang:${goversion}
|
||||||
|
commands:
|
||||||
|
- go get
|
||||||
|
- go build
|
||||||
|
|
||||||
|
linter:
|
||||||
|
when:
|
||||||
|
event: [push]
|
||||||
|
image: golang:${goversion}
|
||||||
|
commands:
|
||||||
|
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.5.0
|
||||||
|
- golangci-lint --version
|
||||||
|
- golangci-lint run ./...
|
||||||
|
depends_on: [build]
|
||||||
|
|
||||||
15
.woodpecker/release.yaml
Normal file
15
.woodpecker/release.yaml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# build release
|
||||||
|
|
||||||
|
labels:
|
||||||
|
platform: linux/amd64
|
||||||
|
|
||||||
|
steps:
|
||||||
|
goreleaser:
|
||||||
|
image: goreleaser/goreleaser
|
||||||
|
when:
|
||||||
|
event: [tag]
|
||||||
|
environment:
|
||||||
|
GITEA_TOKEN:
|
||||||
|
from_secret: DEPLOY_TOKEN
|
||||||
|
commands:
|
||||||
|
- goreleaser release --clean --verbose
|
||||||
39
main.go
39
main.go
@@ -32,6 +32,7 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -39,6 +40,8 @@ import (
|
|||||||
flag "github.com/spf13/pflag"
|
flag "github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const version = "v0.0.2"
|
||||||
|
|
||||||
type Tableschema struct {
|
type Tableschema struct {
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
@@ -60,8 +63,9 @@ func main() {
|
|||||||
var optPort int
|
var optPort int
|
||||||
var optMaxconnections int
|
var optMaxconnections int
|
||||||
var optTimeout int
|
var optTimeout int
|
||||||
var optIdleTransaction bool
|
var optIdleTransaction, shversion bool
|
||||||
var ctx context.Context
|
var ctx context.Context
|
||||||
|
var cancel context.CancelFunc
|
||||||
var conn string
|
var conn string
|
||||||
|
|
||||||
flag.StringVarP(&optPasswd, "password", "p", "", "Password of the database user")
|
flag.StringVarP(&optPasswd, "password", "p", "", "Password of the database user")
|
||||||
@@ -70,11 +74,17 @@ func main() {
|
|||||||
flag.StringVarP(&optServer, "server", "s", "localhost", "Server")
|
flag.StringVarP(&optServer, "server", "s", "localhost", "Server")
|
||||||
flag.IntVarP(&optMaxconnections, "client", "c", 500, "Number of concurrent users")
|
flag.IntVarP(&optMaxconnections, "client", "c", 500, "Number of concurrent users")
|
||||||
flag.IntVarP(&optPort, "port", "P", 5432, "TCP Port")
|
flag.IntVarP(&optPort, "port", "P", 5432, "TCP Port")
|
||||||
flag.IntVarP(&optTimeout, "timeout", "t", 0, "Wether to stop the clients after N seconds")
|
flag.IntVarP(&optTimeout, "timeout", "t", 0, "Whether to stop the clients after N seconds")
|
||||||
flag.BoolVarP(&optIdleTransaction, "idletransaction", "i", false, "Wether to stay in idle in transaction state")
|
flag.BoolVarP(&optIdleTransaction, "idletransaction", "i", false, "Wether to stay in idle in transaction state")
|
||||||
|
flag.BoolVarP(&shversion, "version", "v", false, "show version")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if shversion {
|
||||||
|
fmt.Printf("pgidler version %s\n", version)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
if optServer != "" {
|
if optServer != "" {
|
||||||
conn = fmt.Sprintf(NetConnection, optUser, optDatabase, optPasswd, optServer, optPort)
|
conn = fmt.Sprintf(NetConnection, optUser, optDatabase, optPasswd, optServer, optPort)
|
||||||
} else {
|
} else {
|
||||||
@@ -86,12 +96,15 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
db.Close()
|
|
||||||
|
if err := db.Close(); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf("DB Connection works, firing up %d clients\n", optMaxconnections)
|
log.Printf("DB Connection works, firing up %d clients\n", optMaxconnections)
|
||||||
|
|
||||||
if optTimeout > 0 {
|
if optTimeout > 0 {
|
||||||
ctx, _ = context.WithTimeout(context.Background(), time.Duration(optTimeout)*time.Second)
|
ctx, cancel = context.WithTimeout(context.Background(), time.Duration(optTimeout)*time.Second)
|
||||||
log.Printf("Clients will be killed after %d seconds", optTimeout)
|
log.Printf("Clients will be killed after %d seconds", optTimeout)
|
||||||
} else {
|
} else {
|
||||||
ctx = context.TODO()
|
ctx = context.TODO()
|
||||||
@@ -105,6 +118,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
|
if cancel != nil {
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func dbClient(ctx context.Context, conn string, idle bool) {
|
func dbClient(ctx context.Context, conn string, idle bool) {
|
||||||
@@ -125,7 +142,12 @@ func dbClient(ctx context.Context, conn string, idle bool) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer func() {
|
||||||
|
if err := rows.Close(); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
//log.Println("Got rows")
|
//log.Println("Got rows")
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
@@ -133,6 +155,7 @@ func dbClient(ctx context.Context, conn string, idle bool) {
|
|||||||
if err := rows.Scan(&T.Name); err != nil {
|
if err := rows.Scan(&T.Name); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//log.Printf("Got table %s\n", T.Name)
|
//log.Printf("Got table %s\n", T.Name)
|
||||||
|
|
||||||
for i := 0; i < Maxloop; i++ {
|
for i := 0; i < Maxloop; i++ {
|
||||||
@@ -140,7 +163,11 @@ func dbClient(ctx context.Context, conn string, idle bool) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
rows.Close() // ignore result
|
|
||||||
|
// ignore result
|
||||||
|
if err := rows.Close(); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user