Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

fix delete function #606

Merged
merged 1 commit into from
Apr 17, 2017
Merged

fix delete function #606

merged 1 commit into from
Apr 17, 2017

Conversation

woodsaj
Copy link
Member

@woodsaj woodsaj commented Apr 17, 2017

  • when deleting a branch node, we first walk up the tree to delete
    children. As all siblings and the parents are already being deleted,
    there is no need to walk back down the tree removing the children and
    any empty branches.

@woodsaj woodsaj requested review from Dieterbe and replay April 17, 2017 12:13
@woodsaj
Copy link
Member Author

woodsaj commented Apr 17, 2017

just added a benchmark.

Old code

$ go test -v -run None -bench BenchmarkDeletes -benchtime 10s
BenchmarkDeletes-4   	   50000	   2384248 ns/op	 1313605 B/op	      27 allocs/op
PASS
ok  	github.com/raintank/metrictank/idx/memory	123.452s

New Code

$ go test -v -run None -bench BenchmarkDeletes -benchtime 10s
BenchmarkDeletes-4   	 5000000	      4145 ns/op	    1354 B/op	       8 allocs/op
PASS
ok  	github.com/raintank/metrictank/idx/memory	66.588s

Copy link
Contributor

@replay replay left a comment

Choose a reason for hiding this comment

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

That makes a lot of sense. I'm still surprised by how big the performance difference is though, good find

- when deleting a branch node, we first walk up the tree to delete
  children. As all siblings and the parents are already being deleted,
  there is no need to walk back down the tree removing the children and
  any empty branches.
@woodsaj woodsaj merged commit 4646f2d into master Apr 17, 2017
@woodsaj woodsaj deleted the fixDelete branch April 17, 2017 17:58
@@ -279,6 +279,30 @@ func TestDelete(t *testing.T) {
})
}

func TestDeleteWithLotsOfSeries(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should just put 10k or 1M or whatever in the title instead of "lots"

Copy link
Contributor

Choose a reason for hiding this comment

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

also what's the point of doing this many in a unit test anyway? doing it with 100 instead of 100k invokes all the exact same code, but runs the test in 4ms instead of 800ms on my computer.

Copy link
Member Author

Choose a reason for hiding this comment

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

the complexity of the old code was exponential, O(n^2). But this new code is O(n)

With the old code, it would take many minutes to delete 100k items from the index.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed in #609

Copy link
Contributor

Choose a reason for hiding this comment

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

my point is that the purpose of unit tests is testing functionality. if you want to verify performance criteria (such as x must take no more than y time) then that is what benchmarks are for.

data.SetId()
ix.AddOrUpdate(data, 1)
}
Convey("when deleting 1 million series", t, func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

it's 100k.

Copy link
Member Author

Choose a reason for hiding this comment

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

it was 1million, but that broke circleci due to needing too much ram.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed in #609

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants