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

workload: add interleavebench workload #53831

Merged
merged 1 commit into from
Sep 19, 2020

Conversation

yuzefovich
Copy link
Member

@yuzefovich yuzefovich commented Sep 2, 2020

This commit adds interleavebench workload that can be used to benchmark
DELETE queries for interleaved and non-interleaved tables. It supports
different number of levels (minimum 2), custom ratio in number of rows
between levels, and several other parameters.

As an example, for the following initialization

./bin/workload init interleavebench --drop --interleave=false --levels=3 --hierarchy=1,3,2 --ratio=10 --intra-level-ratio=0.5

these queries will be executed:

CREATE TABLE table0_0 (c0 INT, PRIMARY KEY (c0));
CREATE TABLE table1_0 (c0 INT, c1 INT, PRIMARY KEY (c0, c1));
CREATE TABLE table1_1 (c0 INT, c1 INT, PRIMARY KEY (c0, c1));
CREATE TABLE table1_2 (c0 INT, c1 INT, PRIMARY KEY (c0, c1));
CREATE TABLE table2_0 (c0 INT, c1 INT, c2 INT, PRIMARY KEY (c0, c1, c2));
CREATE TABLE table2_1 (c0 INT, c1 INT, c2 INT, PRIMARY KEY (c0, c1, c2));
ALTER TABLE table1_0 ADD CONSTRAINT fk FOREIGN KEY (c0) REFERENCES table0_0(c0) ON DELETE CASCADE;
ALTER TABLE table1_1 ADD CONSTRAINT fk FOREIGN KEY (c0) REFERENCES table0_0(c0) ON DELETE CASCADE;
ALTER TABLE table1_2 ADD CONSTRAINT fk FOREIGN KEY (c0) REFERENCES table0_0(c0) ON DELETE CASCADE;
ALTER TABLE table2_0 ADD CONSTRAINT fk FOREIGN KEY (c0, c1) REFERENCES table1_0(c0, c1) ON DELETE CASCADE;
ALTER TABLE table2_1 ADD CONSTRAINT fk FOREIGN KEY (c0, c1) REFERENCES table1_0(c0, c1) ON DELETE CASCADE;
INSERT INTO table0_0 (SELECT i FROM generate_series(1, 100) AS i);
INSERT INTO table1_0 (SELECT floor((i-1)*0.10)::INT+1, i FROM generate_series(1, 1000) AS i);
INSERT INTO table1_1 (SELECT floor((i-1)*0.20)::INT+1, i FROM generate_series(1, 500) AS i);
INSERT INTO table1_2 (SELECT floor((i-1)*0.40)::INT+1, i FROM generate_series(1, 250) AS i);
INSERT INTO table2_0 (SELECT floor((i-1)*0.01)::INT+1, floor((i-1)*0.10)::INT+1, i FROM generate_series(1, 10000) AS i);
INSERT INTO table2_1 (SELECT floor((i-1)*0.02)::INT+1, floor((i-1)*0.20)::INT+1, i FROM generate_series(1, 5000) AS i);

Then, during run the workload can execute DELETE queries like:

DELETE FROM table0 WHERE c0 IN ($1, $2, ...);

or

DELETE FROM table0 WHERE c0 >= $1 AND c0 < $1 + 1;

The table from which to delete as well as the number of rows to be deleted
by one query can be customized.

The workload does keep track of which rows are deleted in order to issue
non-overlapping deletes. That is why it ignores concurrency flag and
always runs with no concurrency.

Fixes: #53455.

Release note: None

@yuzefovich yuzefovich added the do-not-merge bors won't merge a PR with this label. label Sep 2, 2020
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@yuzefovich
Copy link
Member Author

cc @jordanlewis @asubiotto @ajwerner if you guys have any thoughts here

@yuzefovich yuzefovich changed the title [DNM] workload: add deletebench workload [DNM] workload: add interleavebench workload Sep 2, 2020
@yuzefovich yuzefovich force-pushed the delete-workload branch 3 times, most recently from 03031b0 to 3ee963b Compare September 15, 2020 23:45
@yuzefovich yuzefovich changed the title [DNM] workload: add interleavebench workload workload: add interleavebench workload Sep 15, 2020
@yuzefovich yuzefovich requested review from asubiotto and a team September 15, 2020 23:51
@yuzefovich yuzefovich removed the do-not-merge bors won't merge a PR with this label. label Sep 15, 2020
Copy link
Contributor

@asubiotto asubiotto left a comment

Choose a reason for hiding this comment

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

I'm mostly offering nits. It might be good to get somebody else's eyes on this (maybe somebody that's actually going to use the workload).

Reviewed 2 of 2 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @yuzefovich)


pkg/workload/interleavebench/interleavebench.go, line 35 at r1 (raw file):

	verbose         bool
	interleave      bool
	noFKs           bool

It might be nice to change this to fks to avoid the noFKs = false double negative


pkg/workload/interleavebench/interleavebench.go, line 132 at r1 (raw file):

			}
			if float64(b.parentCount)*math.Pow(b.ratio, float64(b.levels-1)) > 1<<33 {
				return errors.Errorf("%d level will have more than %d rows", b.levels-1, 1<<33)

nit: extract 1<<33 into const


pkg/workload/interleavebench/interleavebench.go, line 315 at r1 (raw file):

	// Allow a maximum of 1 connection to the database.
	db.SetMaxOpenConns(1)
	db.SetMaxIdleConns(1)

nit: I would extract a const maxWorkers = 1 and use that throughout (and in the concurrency override in Validate).

Copy link
Contributor

@asubiotto asubiotto left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @yuzefovich)


pkg/workload/interleavebench/interleavebench.go, line 29 at r1 (raw file):

)

type interleaveBench struct {

Is there a description of what this workload does anywhere? I think it would be beneficial to have a top-level explanation comment, maybe on this struct.

Copy link
Member Author

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

I think it's enough for you to take a look - I don't think this tool will be used heavily and will be (hopefully soon) deprecated together with the concept of the interleaved tables, so I think it is ok merging as is if it looks reasonable to you.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @asubiotto)


pkg/workload/interleavebench/interleavebench.go, line 29 at r1 (raw file):

Previously, asubiotto (Alfonso Subiotto Marqués) wrote…

Is there a description of what this workload does anywhere? I think it would be beneficial to have a top-level explanation comment, maybe on this struct.

There is a short description in Description field below. Added a bigger comment as well.


pkg/workload/interleavebench/interleavebench.go, line 35 at r1 (raw file):

Previously, asubiotto (Alfonso Subiotto Marqués) wrote…

It might be nice to change this to fks to avoid the noFKs = false double negative

Done.

Copy link
Contributor

@asubiotto asubiotto left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 1 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained

This commit adds `interleavebench` workload that can be used to benchmark
DELETE queries for interleaved and non-interleaved tables. It supports
different number of levels (minimum 2), custom ratio in number of rows
between levels, and several other parameters.

As an example, for the following initialization
```
./bin/workload init interleavebench --drop --interleave=false --levels=3 --hierarchy=1,3,2 --ratio=10 --intra-level-ratio=0.5
```
these queries will be executed:
```
CREATE TABLE table0_0 (c0 INT, PRIMARY KEY (c0));
CREATE TABLE table1_0 (c0 INT, c1 INT, PRIMARY KEY (c0, c1));
CREATE TABLE table1_1 (c0 INT, c1 INT, PRIMARY KEY (c0, c1));
CREATE TABLE table1_2 (c0 INT, c1 INT, PRIMARY KEY (c0, c1));
CREATE TABLE table2_0 (c0 INT, c1 INT, c2 INT, PRIMARY KEY (c0, c1, c2));
CREATE TABLE table2_1 (c0 INT, c1 INT, c2 INT, PRIMARY KEY (c0, c1, c2));
ALTER TABLE table1_0 ADD CONSTRAINT fk FOREIGN KEY (c0) REFERENCES table0_0(c0) ON DELETE CASCADE;
ALTER TABLE table1_1 ADD CONSTRAINT fk FOREIGN KEY (c0) REFERENCES table0_0(c0) ON DELETE CASCADE;
ALTER TABLE table1_2 ADD CONSTRAINT fk FOREIGN KEY (c0) REFERENCES table0_0(c0) ON DELETE CASCADE;
ALTER TABLE table2_0 ADD CONSTRAINT fk FOREIGN KEY (c0, c1) REFERENCES table1_0(c0, c1) ON DELETE CASCADE;
ALTER TABLE table2_1 ADD CONSTRAINT fk FOREIGN KEY (c0, c1) REFERENCES table1_0(c0, c1) ON DELETE CASCADE;
INSERT INTO table0_0 (SELECT i FROM generate_series(1, 100) AS i);
INSERT INTO table1_0 (SELECT floor((i-1)*0.10)::INT+1, i FROM generate_series(1, 1000) AS i);
INSERT INTO table1_1 (SELECT floor((i-1)*0.20)::INT+1, i FROM generate_series(1, 500) AS i);
INSERT INTO table1_2 (SELECT floor((i-1)*0.40)::INT+1, i FROM generate_series(1, 250) AS i);
INSERT INTO table2_0 (SELECT floor((i-1)*0.01)::INT+1, floor((i-1)*0.10)::INT+1, i FROM generate_series(1, 10000) AS i);
INSERT INTO table2_1 (SELECT floor((i-1)*0.02)::INT+1, floor((i-1)*0.20)::INT+1, i FROM generate_series(1, 5000) AS i);
```

Then, during `run` the workload can execute DELETE queries like:
```
DELETE FROM table0 WHERE c0 IN ($1, $2, ...);
```
or
```
DELETE FROM table0 WHERE c0 >= $1 AND c0 < $1 + 1;
```
The table from which to delete as well as the number of rows to be deleted
by one query can be customized.

The workload does keep track of which rows are deleted in order to issue
non-overlapping deletes. That is why it ignores `concurrency` flag and
always runs with no concurrency.

Release note: None
@yuzefovich
Copy link
Member Author

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented Sep 19, 2020

Build succeeded:

@craig craig bot merged commit d6f9163 into cockroachdb:master Sep 19, 2020
@yuzefovich yuzefovich deleted the delete-workload branch September 19, 2020 02:45
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.

sql: benchmark interleaved tables
3 participants