Last active
July 19, 2021 07:01
-
-
Save x4m/8b6025995eedf29bf588727375014dfc to your computer and use it in GitHub Desktop.
stress vxid->xid->2px
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/jackc/pgx" | |
"math/rand" | |
"time" | |
) | |
var timeToExit = false | |
func main() { | |
go doInserts(0) | |
go doInserts(100000) | |
go doInserts(200000) | |
time.Sleep(time.Second * 10) | |
timeToExit = true | |
time.Sleep(time.Second) | |
} | |
func doInserts(start int) { | |
cs := "host=127.0.0.1 port=5432 user=x4mmm database=postgres" | |
ci, err := pgx.ParseConnectionString(cs) | |
panic_err(err) | |
conn, err := pgx.Connect(ci) | |
panic_err(err) | |
for i := start; ; i++ { | |
if timeToExit { | |
return | |
} | |
is := fmt.Sprintf("%d", i) | |
_, err = conn.Exec("begin;") | |
time.Sleep(time.Millisecond * 50) | |
panic_err(err) | |
_, err = conn.Exec(fmt.Sprintf( //"begin;"+ | |
"insert into t1 values(%d);"+ // select pg_sleep(0.1);"+ | |
" PREPARE TRANSACTION 'x"+is+"'; ", | |
rand.Int31())) | |
panic_err(err) | |
_, err := conn.Exec(" COMMIT PREPARED 'x" + is + "';") | |
panic_err(err) | |
} | |
} | |
func panic_err(err error) { | |
if err != nil { | |
panic(err) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/jackc/pgx" | |
"math/rand" | |
"time" | |
) | |
var timeToExit = false | |
func main() { | |
go doInserts(0) | |
go doInserts(100000) | |
go doInserts(200000) | |
time.Sleep(time.Second * 10) | |
timeToExit = true | |
time.Sleep(time.Second) | |
} | |
func doInserts(start int) { | |
cs := "host=127.0.0.1 port=5432 user=x4mmm database=postgres" | |
ci, err := pgx.ParseConnectionString(cs) | |
panic_err(err) | |
conn, err := pgx.Connect(ci) | |
panic_err(err) | |
for i := start; ; i++ { | |
if timeToExit { | |
return | |
} | |
is := fmt.Sprintf("%d", i) | |
_, err = conn.Exec(fmt.Sprintf("begin; select pg_sleep(0.1);"+ | |
"insert into t1 values(%d); select pg_sleep(0.01);"+ | |
" PREPARE TRANSACTION 'x"+is+"'; ", | |
rand.Int31())) | |
panic_err(err) | |
_, err := conn.Exec(" COMMIT PREPARED 'x" + is + "';") | |
panic_err(err) | |
} | |
} | |
func panic_err(err error) { | |
if err != nil { | |
panic(err) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/jackc/pgx" | |
"math/rand" | |
"time" | |
) | |
var timeToExit = false | |
func main() { | |
go doInserts(0) | |
go doInserts(100000) | |
go doInserts(200000) | |
time.Sleep(time.Second * 10) | |
timeToExit = true | |
time.Sleep(time.Second) | |
} | |
func doInserts(start int) { | |
cs := "host=127.0.0.1 port=5432 user=x4mmm database=postgres" | |
ci, err := pgx.ParseConnectionString(cs) | |
panic_err(err) | |
conn, err := pgx.Connect(ci) | |
panic_err(err) | |
for i := start; ; i++ { | |
if timeToExit { | |
return | |
} | |
is := fmt.Sprintf("%d", i) | |
_, err = conn.Exec(fmt.Sprintf("begin;"+ | |
"insert into t1 values(%d); select pg_sleep(0.1);"+ | |
" PREPARE TRANSACTION 'x"+is+"'; ", | |
rand.Int31())) | |
panic_err(err) | |
_, err := conn.Exec(" COMMIT PREPARED 'x" + is + "';") | |
panic_err(err) | |
} | |
} | |
func panic_err(err error) { | |
if err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment