Compare commits
3 Commits
82400ca0b2
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
705193a999 | ||
|
|
bb203dbdf9 | ||
|
|
515feed98b |
@@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.bel.blue/bel/with"
|
"gitea.bel.blue/bel/with"
|
||||||
@@ -24,10 +25,29 @@ func run(ctx context.Context) error {
|
|||||||
fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
|
fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
|
||||||
c := fs.String("c", "postgresql://pulsegres:pulsegres@localhost:15432", "conn string")
|
c := fs.String("c", "postgresql://pulsegres:pulsegres@localhost:15432", "conn string")
|
||||||
d := fs.Duration("d", time.Second, "interval")
|
d := fs.Duration("d", time.Second, "interval")
|
||||||
|
p := fs.Int("p", 1, "concurrent goroutines")
|
||||||
if err := fs.Parse(os.Args[1:]); err != nil {
|
if err := fs.Parse(os.Args[1:]); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i := 0; i < *p-1; i++ {
|
||||||
|
log.Printf("dialing %v of %v background connections...", i+1, *p-1)
|
||||||
|
func() {
|
||||||
|
connected := &sync.WaitGroup{}
|
||||||
|
connected.Add(1)
|
||||||
|
go with.PSQL(ctx, *c, func(pg *sql.DB) error {
|
||||||
|
connected.Done()
|
||||||
|
with.GoEvery(ctx, *d, func() {
|
||||||
|
if _, err := pg.ExecContext(ctx, `SELECT 1`); err != nil {
|
||||||
|
log.Println("!", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return ctx.Err()
|
||||||
|
})
|
||||||
|
connected.Wait()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
return with.PSQL(ctx, *c, func(pg *sql.DB) error {
|
return with.PSQL(ctx, *c, func(pg *sql.DB) error {
|
||||||
log.Println("staging...")
|
log.Println("staging...")
|
||||||
if _, err := pg.ExecContext(ctx, `
|
if _, err := pg.ExecContext(ctx, `
|
||||||
|
|||||||
Reference in New Issue
Block a user