go-datastore icon indicating copy to clipboard operation
go-datastore copied to clipboard

Improve performance of Query method

Open kevina opened this issue 9 years ago • 5 comments

In ipfs/go-ipfs#2760 @whyrusleeping said in a line comment:

Yeah, using a channel as an iterator sucks. If one of you wants to work on improving the perf of query that would be great.

We could change the interface to not use a channel, and have it instead just return the next value directly. Then on top of that we could provide a method for turning the direct query result into a channel buffered one for usecases that need it

kevina avatar Jun 26 '16 16:06 kevina

@whyrusleeping I will be happy to look into this and determine where the bottleneck is. It may be as simple as increasing the buffer size. I will also try a direct iterator approach and see if that helps.

kevina avatar Jun 26 '16 16:06 kevina

Here are some performance numbers for doing a key-only query on the leveldb datastore:

plot

The buffer size is the channel buffer size, direct is the results from querying the level-db directly.

And here are some results from the flatfs datastore:

plot

It seams that at least for key-only 128 in the optimal buffer size.

kevina avatar Jun 29 '16 18:06 kevina

@kevina thanks for these graphs, i think youre right, we should buffer the channels at 128 for now. And if we need more perf later, give the option for direct iteration.

whyrusleeping avatar Jun 29 '16 20:06 whyrusleeping

I updated the graph for flatfs queries. It seams there is enough overhead in the filepath.Walk that once the buffer is large enough the overhead of channels and goroutine is insignificant.

kevina avatar Jun 30 '16 03:06 kevina

I pushed the (somewhat hackish) code to create the graphs on the kevina/query-benchmarks for lack of a better place.

kevina avatar Jun 30 '16 19:06 kevina