Skip to content

Commit 9af65f0

Browse files
committed
few optimizations to transfers.go
1 parent e7ee5f3 commit 9af65f0

File tree

1 file changed

+17
-39
lines changed

1 file changed

+17
-39
lines changed

contrib/pg_dtm/tests/transfers.go

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"sync"
88
"math/rand"
9+
"strconv"
910
"time"
1011
"github.com/jackc/pgx"
1112
)
@@ -306,7 +307,7 @@ func writer(id int, cCommits chan int, cAborts chan int, wg *sync.WaitGroup) {
306307
conns = append(conns, conn)
307308
}
308309

309-
start := time.Now()
310+
// start := time.Now()
310311
for myCommits < cfg.Writers.Updates {
311312
amount := 1
312313

@@ -320,43 +321,20 @@ func writer(id int, cCommits chan int, cAborts chan int, wg *sync.WaitGroup) {
320321
}
321322

322323
if cfg.UseDtm {
323-
xid := execQuery(src, "select dtm_begin_transaction()")
324-
exec(dst, "select dtm_join_transaction($1)", xid)
324+
xid := execQuery(src, "select dtm_begin_transaction(); begin transaction isolation level " + cfg.Isolation)
325+
exec(dst, "select dtm_join_transaction(" + strconv.Itoa(xid) + "); begin transaction isolation level " + cfg.Isolation)
325326
}
326327

327-
parallel_exec([]*pgx.Conn{src,dst}, []string{"begin transaction isolation level " + cfg.Isolation, "begin transaction isolation level " + cfg.Isolation})
328+
// parallel_exec([]*pgx.Conn{src,dst}, []string{"begin transaction isolation level " + cfg.Isolation, "begin transaction isolation level " + cfg.Isolation})
328329

329330
ok := true
330-
if (cfg.Writers.UseCursors) {
331-
exec(
332-
src,
333-
"declare cur0 cursor for select * from t where u=$1 for update",
334-
from_acc,
335-
)
336-
exec(
337-
dst,
338-
"declare cur0 cursor for select * from t where u=$1 for update",
339-
to_acc,
340-
)
341-
342-
ok = execUpdate(src, "fetch from cur0") && ok
343-
ok = execUpdate(dst, "fetch from cur0") && ok
344-
345-
ok = execUpdate(
346-
src, "update t set v = v - $1 where current of cur0",
347-
amount,
348-
) && ok
349-
ok = execUpdate(
350-
dst, "update t set v = v + $1 where current of cur0",
351-
amount,
352-
) && ok
353-
} else {
354331

355-
sql1 := fmt.Sprintf("update t set v = v - %d where u=%d", amount, from_acc)
356-
sql2 := fmt.Sprintf("update t set v = v + %d where u=%d", amount, to_acc)
357332

358-
ok = parallel_exec([]*pgx.Conn{src,dst}, []string{sql1,sql2})
359-
}
333+
sql1 := "update t set v = v - " + strconv.Itoa(amount) + " where u=" + strconv.Itoa(from_acc)
334+
sql2 := "update t set v = v + " + strconv.Itoa(amount) + " where u=" + strconv.Itoa(to_acc)
335+
336+
ok = parallel_exec([]*pgx.Conn{src,dst}, []string{sql1,sql2})
337+
360338

361339
if ok {
362340
commit(src, dst)
@@ -368,13 +346,13 @@ func writer(id int, cCommits chan int, cAborts chan int, wg *sync.WaitGroup) {
368346
nAborts += 1
369347
}
370348

371-
if time.Since(start).Seconds() > 1 {
372-
cCommits <- nCommits
373-
cAborts <- nAborts
374-
nCommits = 0
375-
nAborts = 0
376-
start = time.Now()
377-
}
349+
// if time.Since(start).Seconds() > 1 {
350+
// cCommits <- nCommits
351+
// cAborts <- nAborts
352+
// nCommits = 0
353+
// nAborts = 0
354+
// start = time.Now()
355+
// }
378356
}
379357
cCommits <- nCommits
380358
cAborts <- nAborts

0 commit comments

Comments
 (0)