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

engine: page defragmentation #202

Closed
wants to merge 8 commits into from
Closed

engine: page defragmentation #202

wants to merge 8 commits into from

Conversation

ayzu
Copy link
Collaborator

@ayzu ayzu commented Jul 12, 2020

Implement a benchmark for page defragmentation operation (part of #183)

@SUMUKHA-PK
Copy link
Collaborator

Hey thanks for the PR!

Im not sure about the addition of use of the PR but we dont allow panics in the code - please ensure the CI passes :D

@SUMUKHA-PK
Copy link
Collaborator

Join can check out of one of the pinned issues to join our slack too!

@ayzu
Copy link
Collaborator Author

ayzu commented Jul 12, 2020

Hey thanks for the PR!

Im not sure about the addition of use of the PR but we dont allow panics in the code - please ensure the CI passes :D

Hey! That's was fast - you replied even before the CI finished :)

Thanks, fixed

@ayzu ayzu requested review from Abby3017 and SUMUKHA-PK July 12, 2020 16:40
@ayzu
Copy link
Collaborator Author

ayzu commented Jul 12, 2020

Join can check out of one of the pinned issues to join our slack too!

sorry, not sure that I got it. I joined the slack, btw

@SUMUKHA-PK
Copy link
Collaborator

Haha yes our slack bot notified me.

@TimSatke is actually the code owner for this part, it'll be reviewed by him :D

Copy link
Contributor

@tsatke tsatke left a comment

Choose a reason for hiding this comment

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

Please have a look at https://github.com/tomarrell/lbadd/blob/master/CODING_GUIDELINES.md .

Code looks good. Major flaws were probably due to lack of knowledge of features, such as RawData instead of copying the page data yourself.

  • We use the assert package of https://github.com/stretchr/testify for testing and benchmarks.
  • Use of random in tests must always be explicitly seeded (probably gonna add that to the coding guidelines).
  • Ordering: const -> var -> struct -> exported methods -> unexported methods -> exported functions -> unexported functions

@@ -0,0 +1,63 @@
package page
Copy link
Contributor

Choose a reason for hiding this comment

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

Please read the contribution and coding guidelines.

pageSize = int(math.Round(2 * float64(Size) / 3)) // two-thirds of the max size
)

func generateRecordCell(b *testing.B) RecordCell {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ordering: exported before unexported

Comment on lines +57 to +60
copy(bytes, data)
page := &Page{ // have to recreate a page with initial data
data: bytes,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably not be part of the benchmark, exclude it with b.StopTimer() and b.StartTimer() respectively

Comment on lines +19 to +20
keySize := 1 + rand.Intn(maxKeySize-1)
recordSize := 1 + rand.Intn(maxRecordSize-1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use an explicitely seeded random source, to be sure that the test is always reproducible, regardless of someone else seeding the whole rand package or not.


func generatePage(b *testing.B) *Page {
b.Helper()
p, err := load(make([]byte, pageSize))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why only use a page with 2 thirds of the total size? Is that benchmark still representative if the page is smaller than 16K?


for i := 0; i < b.N; i++ {
copy(bytes, data)
page := &Page{ // have to recreate a page with initial data
Copy link
Contributor

Choose a reason for hiding this comment

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

Use Load rather than this. This does work, however, if the page implementation changes, this probably doesn't work any more (e.g. adding locks or cell caches as maps etc)

Comment on lines +23 to +25
if err != nil {
b.Fatal(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We tend to use stretchr/testify for tests.
You could easily rewrite this as

assert := assert.New(b)
...
_, err := rand.Read(key)
assert.NoError(err)
...

And you would get rid of a lot of err checks like this.

}

func generatePage(b *testing.B) *Page {
b.Helper()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this a helper, but generateCell isn't?

Comment on lines +43 to +46
record := generateRecordCell(b)
for err = p.StoreRecordCell(record); err != ErrPageFull; err = p.StoreRecordCell(record) {
record = generateRecordCell(b)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
record := generateRecordCell(b)
for err = p.StoreRecordCell(record); err != ErrPageFull; err = p.StoreRecordCell(record) {
record = generateRecordCell(b)
}
for {
rec := generateRecordCell(b)
if err := p.StoreRecordCell(rec); err != nil {
assert.Equal(ErrPageFull, err)
break
}
}

Comment on lines +51 to +57
data := generatePage(b).data
bytes := make([]byte, len(data))
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
copy(bytes, data)
Copy link
Contributor

Choose a reason for hiding this comment

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

page.RawData() does exactly that, return a copy of the page data. That way, you don't need to access unexported fields.

@tsatke tsatke changed the title bench: page defragmentation engine: page defragmentation Jul 15, 2020
@tsatke
Copy link
Contributor

tsatke commented Aug 5, 2020

Closing this as defragmentation will disappear. Page is defragmented upon delete, not when someone calls it.

@tsatke tsatke closed this Aug 5, 2020
@tsatke tsatke deleted the bench-defragment branch August 5, 2020 07:26
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.

3 participants