Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

Pool buffers #119

Open
eulerfx opened this issue Mar 15, 2017 · 0 comments
Open

Pool buffers #119

eulerfx opened this issue Mar 15, 2017 · 0 comments

Comments

@eulerfx
Copy link
Contributor

eulerfx commented Mar 15, 2017

Prototype using .NET BufferManager here. The interface is:

type IBufferPool
val alloc : int -> byte[]
val free : byte[] -> unit

Pooling buffers for requests is trivial because the lifecycle is controlled explicitly by the Chan module - the region is well known.

Pooling buffers for responses is more challenging, because the response lifecycle is in the hands of the user. For example, take the Consumer.stream operation which yields control to the caller.

Some options:

  • Embed a decoder (ConsumerMessageSet -> 'a) into the consumer such that after decoding, the buffers could be freed.
  • Only use pooling in conjunction with Consumer.consume and a contract to free buffers corresponding to the message set after the user provided handler completes.
  • Have ConsumerMessageSet implement IDisposable, along with a finalizer, and urge users to dispose when done.
  • Provide an explicit "finalization queue" such that consumed message set buffers are freed automatically after the fetch cursor is ahead by N, thus assuming the message set would have been used. This can be used in conjunction with the prior option, or without it, foregoing the need to implement IDisposable.
  • Allow the user to configure IBufferPool and have the responsibility to free buffers for `ConsumerMessageSet.
  • Consider linear/affine type system approach as in here. Perhaps, as a linear variant of AsyncSeq which would eschew buffering, thereby giving us a controlled lifecycle for its elements.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant