Skip to content

Commit b395714

Browse files
committed
Add output of elapsed time to tests
1 parent 1960984 commit b395714

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

contrib/pg_dtm/tests/pg_shard_transfers.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import (
77
"database/sql"
88
"strconv"
99
"math/rand"
10+
"time"
1011
)
1112

1213
const (
1314
TRANSFER_CONNECTIONS = 8
1415
INIT_AMOUNT = 10000
1516
N_ITERATIONS = 10000
16-
N_ACCOUNTS = 100 //2*TRANSFER_CONNECTIONS
17+
N_ACCOUNTS = 2*100000
1718
)
1819

1920
var cfg = "host=127.0.0.1 port=5432 sslmode=disable"
@@ -40,7 +41,7 @@ func prepare_db() {
4041
exec(conn, "drop extension if exists pg_shard CASCADE")
4142
exec(conn, "create extension pg_shard")
4243
exec(conn, "drop table if exists t")
43-
exec(conn, "create table t(u int, v int)")
44+
exec(conn, "create table t(u int primary key, v int)")
4445
exec(conn, "select master_create_distributed_table(table_name := 't', partition_column := 'u')")
4546
exec(conn, "select master_create_worker_shards(table_name := 't', shard_count := 2, replication_factor := 1)")
4647

@@ -56,19 +57,20 @@ func transfer(id int, wg *sync.WaitGroup) {
5657
checkErr(err)
5758
defer conn.Close()
5859

59-
uids1 := []int{1,3,4, 5, 7, 8,10,14}
60-
uids2 := []int{2,6,9,11,12,13,18,21}
61-
6260
for i:=0; i < N_ITERATIONS; i++ {
61+
amount := 1
62+
account1 := rand.Intn(N_ACCOUNTS)
63+
account2 := rand.Intn(N_ACCOUNTS)
6364
exec(conn, "begin")
64-
exec(conn, "update t set v = v + 1 where u="+strconv.Itoa(uids1[rand.Intn(TRANSFER_CONNECTIONS)]))
65-
exec(conn, "update t set v = v - 1 where u="+strconv.Itoa(uids2[rand.Intn(TRANSFER_CONNECTIONS)]))
65+
exec(conn, fmt.Sprintf("update t set v = v - %d where u=%d", amount, account1))
66+
exec(conn, fmt.Sprintf("update t set v = v + %d where u=%d", amount, account2))
67+
6668
// exec(conn, "update t set v = v + 1 where u=1")
6769
// exec(conn, "update t set v = v - 1 where u=2")
6870
exec(conn, "commit")
6971

7072
if i%1000==0 {
71-
fmt.Printf("%u tx processed.\n", i)
73+
fmt.Printf("%d tx processed.\n", i)
7274
}
7375
}
7476

@@ -100,6 +102,8 @@ func main() {
100102

101103
prepare_db()
102104

105+
start := time.Now()
106+
103107
transferWg.Add(TRANSFER_CONNECTIONS)
104108
for i:=0; i<TRANSFER_CONNECTIONS; i++ {
105109
go transfer(i, &transferWg)
@@ -123,7 +127,7 @@ func main() {
123127

124128
// fmt.Println(sum)
125129

126-
fmt.Printf("done\n")
130+
fmt.Printf("Elapsed time %f seconds\n", time.Since(start).Seconds())
127131
}
128132

129133
func exec(conn *sql.DB, stmt string) {

contrib/pg_dtm/tests/transfers-fdw.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const (
1212
TRANSFER_CONNECTIONS = 8
1313
INIT_AMOUNT = 10000
1414
N_ITERATIONS = 10000
15-
N_ACCOUNTS = 100000//TRANSFER_CONNECTIONS
15+
N_ACCOUNTS = 100000
1616
ISOLATION_LEVEL = "repeatable read"
1717
//ISOLATION_LEVEL = "read committed"
1818
)
@@ -170,6 +170,8 @@ func main() {
170170

171171
prepare_db()
172172

173+
start := time.Now()
174+
173175
cCommits := make(chan int)
174176
cAborts := make(chan int)
175177
progressWg.Add(1)
@@ -189,6 +191,8 @@ func main() {
189191

190192
close(cCommits)
191193
progressWg.Wait()
194+
195+
fmt.Printf("Elapsed time %f seconds\n", time.Since(start).Seconds())
192196
}
193197

194198
func exec(conn *pgx.Conn, stmt string, arguments ...interface{}) {

contrib/pg_dtm/tests/transfers.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ func main() {
212212

213213
prepare_db()
214214

215+
start := time.Now()
216+
215217
cCommits := make(chan int)
216218
cAborts := make(chan int)
217219
go progress(TRANSFER_CONNECTIONS * N_ITERATIONS, cCommits, cAborts)
@@ -228,7 +230,7 @@ func main() {
228230
running = false
229231
inspectWg.Wait()
230232

231-
fmt.Printf("done\n")
233+
fmt.Printf("Elapsed time %f seconds\n", time.Since(start).Seconds())
232234
}
233235

234236
func exec(conn *pgx.Conn, stmt string, arguments ...interface{}) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy