// Tests a batch of queries very similar to those that that PGBench runs // in its TPC-B(ish) mode. func runPgbenchQueryParallel(b *testing.B, db *gosql.DB) { if err := pgbench.SetupBenchDB(db, 20000, true /*quiet*/); err != nil { b.Fatal(err) } retryOpts := retry.Options{ InitialBackoff: 1 * time.Millisecond, MaxBackoff: 200 * time.Millisecond, Multiplier: 2, } b.ResetTimer() b.RunParallel(func(pb *testing.PB) { src := rand.New(rand.NewSource(5432)) r := retry.Start(retryOpts) var err error for pb.Next() { r.Reset() for r.Next() { err = pgbench.RunOne(db, src, 20000) if err == nil { break } } if err != nil { b.Fatal(err) } } }) b.StopTimer() }
// Tests a batch of queries very similar to those that that PGBench runs // in its TPC-B(ish) mode. func runPgbenchQuery(b *testing.B, db *gosql.DB) { if err := pgbench.SetupBenchDB(db, 20000, true /*quiet*/); err != nil { b.Fatal(err) } src := rand.New(rand.NewSource(5432)) b.ResetTimer() for i := 0; i < b.N; i++ { if err := pgbench.RunOne(db, src, 20000); err != nil { b.Fatal(err) } } b.StopTimer() }
func main() { accounts := flag.Int("accounts", 100000, "number of accounts to create") createDb := flag.Bool("createdb", false, "attempt to create named db, dropping first if exists (must be able to connect to default db to do so).") flag.Parse() flag.Usage = usage if flag.NArg() != 1 { flag.Usage() os.Exit(2) } var db *gosql.DB var err error if *createDb { name := "" parsed, parseErr := url.Parse(flag.Arg(0)) if parseErr != nil { panic(parseErr) } else if len(parsed.Path) < 2 { // first char is '/' panic("URL must include db name") } else { name = parsed.Path[1:] } db, err = pgbench.CreateAndConnect(*parsed, name) } else { db, err = gosql.Open("postgres", flag.Arg(0)) } if err != nil { panic(err) } defer db.Close() if err := pgbench.SetupBenchDB(db, *accounts, false); err != nil { panic(err) } }