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

autobatch: thread-safe, debounce, max delay and implement Batching

Open MichaelMure opened this issue 4 years ago • 6 comments

Revamp the venerable autobatch in different ways:

  • make it thread safe (test -race is happy)
  • deduplicate writes (avoid writing the same key multiple time), which make it act as a debounce
  • introduce a maximum delay before the write happen, to avoid keeping the pending writes in memory if the count trigger is not reached
  • implement the Batching interface for compatibility with more usecases

MichaelMure avatar Oct 13 '21 15:10 MichaelMure

@whyrusleeping you might be interested in this.

aschmahmann avatar Oct 15 '21 15:10 aschmahmann

I can't comment on Query(), so will comment here. Is the intention of flushing in Query() before issuing the query, to make sure that there are no pending ops before sending the query? If so, then I think that's racy (it unlocks after flushing and re-locks before querying).

This is correct, but at the same time Query can be very long lived (I used some hours-long Query before) so I don't think blocking writes during a Query is reasonable.

MichaelMure avatar Nov 03 '21 08:11 MichaelMure

I can't comment on Query(), so will comment here. Is the intention of flushing in Query() before issuing the query, to make sure that there are no pending ops before sending the query? If so, then I think that's racy (it unlocks after flushing and re-locks before querying).

This is correct, but at the same time Query can be very long lived (I used some hours-long Query before) so I don't think blocking writes during a Query is reasonable.

Ah that makes sense, thanks :)

guseggert avatar Nov 03 '21 13:11 guseggert

@MichaelMure : I've converted this to a draft. If/once you've incorporated feedback, feel free to publish and we'll happily take a look.

BigLep avatar Jan 07 '22 16:01 BigLep

@MichaelMure : are you going to take this, or should we close this for now?

BigLep avatar May 06 '22 15:05 BigLep

@BigLep I'm sure there is value in there but I ended up not using any of this in my project as things took a different turn. I suppose we can close.

MichaelMure avatar May 06 '22 16:05 MichaelMure