Skip to content

Commit

Permalink
"benchmark" 1px txn with simulated latency
Browse files Browse the repository at this point in the history
name                                old time/op  new time/op  delta
SingleRoundtripTxnWithLatency_0-8   2.42ms ± 0%  1.65ms ± 0%   ~     (p=1.000 n=1+1)
SingleRoundtripTxnWithLatency_10-8  25.3ms ± 0%  13.2ms ± 0%   ~     (p=1.000 n=1+1)

Both changes are not statistically relevant due to the high cost of a single
operation, but the second number is actually consistent (the first will
fluctuate somewhat).
Their value is mostly in showing the benefit of 1pc transactions end-to-end
from the KV client.

before:
PASS
BenchmarkSingleRoundtripTxnWithLatency_0-8 	   20000	   2418298 ns/op
BenchmarkSingleRoundtripTxnWithLatency_10-8	    1000	  25316220 ns/op
ok  	github.com/cockroachdb/cockroach/kv	89.027s
PASS

after:
BenchmarkSingleRoundtripTxnWithLatency_0-8 	   10000	   1647978 ns/op
BenchmarkSingleRoundtripTxnWithLatency_10-8	    2000	  13190856 ns/op
ok  	github.com/cockroachdb/cockroach/kv	44.214s
  • Loading branch information
tbg committed Dec 9, 2015
1 parent bc8f1aa commit 7dd474c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
5 changes: 5 additions & 0 deletions kv/local_test_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package kv

import (
"net"
"time"

"golang.org/x/net/context"

Expand Down Expand Up @@ -57,6 +58,7 @@ type LocalTestCluster struct {
Sender *TxnCoordSender
distSender *DistSender
Stopper *stop.Stopper
Latency time.Duration // sleep for each RPC sent
tester util.Tester
}

Expand All @@ -82,6 +84,9 @@ func (ltc *LocalTestCluster) Start(t util.Tester) {
getArgs func(addr net.Addr) proto.Message, getReply func() proto.Message,
_ *rpc.Context) ([]proto.Message, error) {
// TODO(tschottdorf): remove getReply().
if ltc.Latency > 0 {
time.Sleep(ltc.Latency)
}
br, pErr := ltc.stores.Send(context.Background(), *getArgs(nil).(*roachpb.BatchRequest))
if br == nil {
br = &roachpb.BatchResponse{}
Expand Down
21 changes: 16 additions & 5 deletions kv/txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,18 @@ func TestTxnDBBasics(t *testing.T) {
}
}

// BenchmarkTxnWrites benchmarks a number of transactions writing to the
// same key back to back, without using Prepare/Flush.
func BenchmarkTxnWrites(b *testing.B) {
s := createTestDB(b)
// benchmarkSingleRoundtripWithLatency runs a number of transactions writing to
// the same key back to back in a single round-trip. Latency is simulated
// by pausing before each RPC sent.
func benchmarkSingleRoundtripWithLatency(b *testing.B, latency time.Duration) {
s := &LocalTestCluster{}
s.Latency = latency
s.Start(b)
defer s.Stop()
defer b.StopTimer()
key := roachpb.Key("key")
b.ResetTimer()
for i := 0; i < b.N; i++ {
s.Manual.Increment(1)
if tErr := s.DB.Txn(func(txn *client.Txn) error {
b := txn.NewBatch()
b.Put(key, fmt.Sprintf("value-%d", i))
Expand All @@ -121,6 +124,14 @@ func BenchmarkTxnWrites(b *testing.B) {
}
}

func BenchmarkSingleRoundtripTxnWithLatency_0(b *testing.B) {
benchmarkSingleRoundtripWithLatency(b, 0)
}

func BenchmarkSingleRoundtripTxnWithLatency_10(b *testing.B) {
benchmarkSingleRoundtripWithLatency(b, 10*time.Millisecond)
}

// disableOwnNodeCertain is used in tests which want to verify uncertainty
// related logic on single-node installations. In regular operation, trans-
// actional requests automatically have the "own" NodeID marked as free from
Expand Down

0 comments on commit 7dd474c

Please sign in to comment.