Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1PC transactions #3364

Merged
merged 3 commits into from
Dec 9, 2015
Merged

1PC transactions #3364

merged 3 commits into from
Dec 9, 2015

Conversation

tbg
Copy link
Member

@tbg tbg commented Dec 9, 2015

resuscitation of #2818.

This change enables 1PC txns for transactions contained in a single batch and
sent to a single Range.

Contrary to the previous incarnation, now the chunk of batch
containing EndTransaction is split and re-sent before any other
redundant requests have been made.

More improvement is possible: If the EndTransaction request were to end up in
the last Batch sent over the course of the multi-range request anyway, it would
not need to be split up into its own chunk. There's no way of knowing that
until the last range descriptor has been looked up though, at which point in
time we've already sent requests, complicating the code. Hence, this
optimization (which amounts to @bdarnell's suggestion in #2818) has been
omitted for now due to the amount of code changes required.

Unfortunately, the improvements here don't directly reflect in SQL
benchmarks because of the way the Txn is used there.
We need to optimize the SQL server to batch up as many commands as it
can (basically until it reads data) and commit in the same round-trip
if possible. Currently the Txn object is used deep down in the individual
operations (for example (*planner).Insert()) so this isn't trivial.
I will file an issue.

Instead, I reused a kv benchmark which runs a 1pc transaction. Without
actual latency however, the effect of this change is minimal. I added a way
to simulate latency (by means of time.Sleep) to TestCluster and benchmarked
using that. The results are, well, not surprising. See second commit.

Review on Reviewable

@tbg tbg changed the title 1pctxn 1PC transactions Dec 9, 2015
@tbg
Copy link
Member Author

tbg commented Dec 9, 2015

TestReplicaGCQueueDropReplica is flaky with this change, I think I have a rough idea why but I'll fix it tomorrow.

@tbg
Copy link
Member Author

tbg commented Dec 9, 2015

I added a commit which fixes the flaky test.

the test's success was dependent on application order across
multiple nodes and now influences this order appropriately.

for _, test := range []struct {
put1, put2, et roachpb.Key
// -1 is used as separator between requests for simplicity.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear what this is referring to. Stale comment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, removed.

@bdarnell
Copy link
Contributor

bdarnell commented Dec 9, 2015

LGTM

resuscitation of cockroachdb#2818.

This change enables 1PC txns for transaction contained in a single batch and
sent to a single Range.

Contrary to the previous incarnation, now the chunk of batch
containing EndTransaction is split and re-sent before any other
redundant requests have been made.

More improvement is possible: If the EndTransaction request were to end up in
the last Batch sent over the course of the multi-range request anyway, it would
not need to be split up into its own chunk. There's no way of knowing that
until the last range descriptor has been looked up though, at which point in
time we've already sent requests, complicating the code. Hence, this
optimization (which amounts to @bdarnell's suggestion in cockroachdb#2818) has been
omitted for now due to the amount of code changes required.

Unfortunately, the improvements here don't directly reflect in SQL
benchmarks because of the way the Txn is used there.
We need to optimize the SQL server to batch up as many commands as it
can (basically until it reads data) and commit in the same round-trip
if possible. Currently the Txn object is used deep down in the individual
operations (for example `(*planner).Insert()`) so this isn't trivial.
I will file an issue.
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
tbg added a commit that referenced this pull request Dec 9, 2015
@tbg tbg merged commit cbb4a65 into cockroachdb:master Dec 9, 2015
@tbg tbg deleted the 1pctxn branch December 9, 2015 19:56
@tbg tbg mentioned this pull request Jan 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants