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

Add Eio.Pool #602

Merged
merged 1 commit into from
Aug 23, 2023
Merged

Add Eio.Pool #602

merged 1 commit into from
Aug 23, 2023

Conversation

talex5
Copy link
Collaborator

@talex5 talex5 commented Aug 15, 2023

This is similar to Lwt_pool.

It provides a similar API to @darrenldl's draft in #566, but:

  • Internally it uses a single Cells queue, which should be more efficient.
  • It uses @patricoferris's suggestion of removing the switch.

I removed the clear function for now. According to https://sherlocode.com/?q=Lwt_pool.clear, the only user of Lwt_pool.clear is Lwt's own tests!

The docs note some complications regarding switches. We should probably try to make this simpler in future. e.g.

  • It would be good to run alloc with a temporary switch: if it fails then everything is released, but if it succeeds then the resource gets adopted by the pool switch.
  • Currently, switches can't be shared between domains, which makes using a pool across domains more difficult than it should be.

Instead of providing validate, dispose and alloc functions, we could just expose the slot and let the user deal with it. That would give maximum flexibility.

@talex5 talex5 added the enhancement New feature or request label Aug 15, 2023
@talex5 talex5 mentioned this pull request Aug 16, 2023
@avsm
Copy link
Contributor

avsm commented Aug 18, 2023

I am curious to see what the version that exposes the slot looks like, to avoid all the callbacks for the lifetime management...

@talex5
Copy link
Collaborator Author

talex5 commented Aug 18, 2023

I am curious to see what the version that exposes the slot looks like, to avoid all the callbacks for the lifetime management...

The simplest case would be just:

type 'a t
val create : int -> 'a t
val use : 'a t -> ('a ref -> 'b) -> 'b

When using the pool you get a slot (initially empty) and it's up to you to create a new resource and store it in the slot. That would mostly force people to create their own wrappers around pool.

Alternatively, the wrapper could be passed to create:

type 'a t

module type RESOURCE = sig
  type t
  val use_slot : t ref -> (t -> 'b) -> 'b
end

val create : (module RESOURCE) -> int -> 'a t

val use : 'a t -> ('a -> 'b) -> 'b

This is similar to `Lwt_pool`.
@talex5 talex5 merged commit 1bba7b1 into ocaml-multicore:main Aug 23, 2023
5 checks passed
@talex5 talex5 deleted the pool branch August 23, 2023 08:17
talex5 added a commit to talex5/opam-repository that referenced this pull request Aug 29, 2023
CHANGES:

New features / API changes:

- Replace objects with variants (@talex5 @patricoferris ocaml-multicore/eio#553 ocaml-multicore/eio#605 ocaml-multicore/eio#608, reviewed by @avsm).
  Some potential users found object types confusing, so we now use an alternative scheme for OS resources.
  For users of the resources, the only thing that changes is the types:

  - Instead of taking an argument of type `#foo`, you should now take `_ foo`.
  - Instead of returning a value of type `foo`, you should now return `foo_ty Eio.Resource.t`.

  To provide your own implementation of an interface, you now provide a module rather than an object.
  For example, to provide your own source flow, use `Eio.Flow.Pi.source (module My_source)`.

  If you want to define your own interfaces, see the `Eio.Resource` module documentation.

- Add `Eio.Pool` (@talex5 @darrenldl ocaml-multicore/eio#602, reviewed by @patricoferris).
  A lock-free pool of resources. This is similar to `Lwt_pool`.

- Add `Eio.Lazy` (@talex5 ocaml-multicore/eio#609, reviewed by @SGrondin).
  If one fiber tries to force a lazy value while another is already doing it,
  this will wait for the first one to finish rather than raising an exception (as `Stdlib.Lazy` does).

- Add `Eio.Path.native` (@talex5 ocaml-multicore/eio#603, reviewed by @patricoferris).
  This is useful when interacting with non-Eio libraries, for spawning sub-processes, and for displaying paths to users.

- Add `Flow.single_write` (@talex5 ocaml-multicore/eio#598).

- Add `Eio.Flow.Pi.simple_copy` (@talex5 ocaml-multicore/eio#611).
  Provides an easy way to implement the `copy` operation when making your own sink.

- Eio_unix: add FD passing (@talex5 ocaml-multicore/eio#522).
  Allows opening a file and passing the handle over a Unix-domain socket.

- Add `Process.run ?is_success` to control definition of success (@SGrondin ocaml-multicore/eio#586, reviewed by @talex5).

- Add `Eio_mock.Domain_manager` (@talex5 ocaml-multicore/eio#610).
  This mock domain manager runs everything in a single domain, allowing tests to remain deterministic.

- Add `Eio.Debug.with_trace_prefix` (@talex5 ocaml-multicore/eio#610).
  Allows prefixing all `traceln` output. The mock domain manager uses this to indicate which fake domain is running.

Bug fixes:

- Fork actions must not allocate (@talex5 ocaml-multicore/eio#593).
  When using multiple domains, child processes could get stuck if they forked while another domain held the malloc lock.

- eio_posix: ignore some errors writing to the wake-up pipe (@talex5 ocaml-multicore/eio#600).
  If the pipe is full or closed, the wake-up should simply be ignored.

Build/test fixes:

- Fix some MDX problems on Windows (@polytypic ocaml-multicore/eio#597).

- The README depends on kcas (@talex5 ocaml-multicore/eio#606).

- Clarify configuration for lib_eio_linux and enable tests on other arches (@dra27 ocaml-multicore/eio#592).

- eio_linux tests: skip fixed buffer test if not available (@talex5 ocaml-multicore/eio#604).

- eio_windows: update available line to win32 (@talex5 ocaml-multicore/eio#588 ocaml-multicore/eio#591).
talex5 added a commit to talex5/opam-repository that referenced this pull request Aug 29, 2023
CHANGES:

New features / API changes:

- Replace objects with variants (@talex5 @patricoferris ocaml-multicore/eio#553 ocaml-multicore/eio#605 ocaml-multicore/eio#608, reviewed by @avsm).
  Some potential users found object types confusing, so we now use an alternative scheme for OS resources.
  For users of the resources, the only thing that changes is the types:

  - Instead of taking an argument of type `#foo`, you should now take `_ foo`.
  - Instead of returning a value of type `foo`, you should now return `foo_ty Eio.Resource.t`.

  To provide your own implementation of an interface, you now provide a module rather than an object.
  For example, to provide your own source flow, use `Eio.Flow.Pi.source (module My_source)`.

  If you want to define your own interfaces, see the `Eio.Resource` module documentation.

- Add `Eio.Pool` (@talex5 @darrenldl ocaml-multicore/eio#602, reviewed by @patricoferris).
  A lock-free pool of resources. This is similar to `Lwt_pool`.

- Add `Eio.Lazy` (@talex5 ocaml-multicore/eio#609, reviewed by @SGrondin).
  If one fiber tries to force a lazy value while another is already doing it,
  this will wait for the first one to finish rather than raising an exception (as `Stdlib.Lazy` does).

- Add `Eio.Path.native` (@talex5 ocaml-multicore/eio#603, reviewed by @patricoferris).
  This is useful when interacting with non-Eio libraries, for spawning sub-processes, and for displaying paths to users.

- Add `Flow.single_write` (@talex5 ocaml-multicore/eio#598).

- Add `Eio.Flow.Pi.simple_copy` (@talex5 ocaml-multicore/eio#611).
  Provides an easy way to implement the `copy` operation when making your own sink.

- Eio_unix: add FD passing (@talex5 ocaml-multicore/eio#522).
  Allows opening a file and passing the handle over a Unix-domain socket.

- Add `Process.run ?is_success` to control definition of success (@SGrondin ocaml-multicore/eio#586, reviewed by @talex5).

- Add `Eio_mock.Domain_manager` (@talex5 ocaml-multicore/eio#610).
  This mock domain manager runs everything in a single domain, allowing tests to remain deterministic.

- Add `Eio.Debug.with_trace_prefix` (@talex5 ocaml-multicore/eio#610).
  Allows prefixing all `traceln` output. The mock domain manager uses this to indicate which fake domain is running.

Bug fixes:

- Fork actions must not allocate (@talex5 ocaml-multicore/eio#593).
  When using multiple domains, child processes could get stuck if they forked while another domain held the malloc lock.

- eio_posix: ignore some errors writing to the wake-up pipe (@talex5 ocaml-multicore/eio#600).
  If the pipe is full or closed, the wake-up should simply be ignored.

Build/test fixes:

- Fix some MDX problems on Windows (@polytypic ocaml-multicore/eio#597).

- The README depends on kcas (@talex5 ocaml-multicore/eio#606).

- Clarify configuration for lib_eio_linux and enable tests on other arches (@dra27 ocaml-multicore/eio#592).

- eio_linux tests: skip fixed buffer test if not available (@talex5 ocaml-multicore/eio#604).

- eio_windows: update available line to win32 (@talex5 ocaml-multicore/eio#588 ocaml-multicore/eio#591).
nberth pushed a commit to nberth/opam-repository that referenced this pull request Jun 18, 2024
CHANGES:

New features / API changes:

- Replace objects with variants (@talex5 @patricoferris ocaml-multicore/eio#553 ocaml-multicore/eio#605 ocaml-multicore/eio#608, reviewed by @avsm).
  Some potential users found object types confusing, so we now use an alternative scheme for OS resources.
  For users of the resources, the only thing that changes is the types:

  - Instead of taking an argument of type `#foo`, you should now take `_ foo`.
  - Instead of returning a value of type `foo`, you should now return `foo_ty Eio.Resource.t`.

  To provide your own implementation of an interface, you now provide a module rather than an object.
  For example, to provide your own source flow, use `Eio.Flow.Pi.source (module My_source)`.

  If you want to define your own interfaces, see the `Eio.Resource` module documentation.

- Add `Eio.Pool` (@talex5 @darrenldl ocaml-multicore/eio#602, reviewed by @patricoferris).
  A lock-free pool of resources. This is similar to `Lwt_pool`.

- Add `Eio.Lazy` (@talex5 ocaml-multicore/eio#609, reviewed by @SGrondin).
  If one fiber tries to force a lazy value while another is already doing it,
  this will wait for the first one to finish rather than raising an exception (as `Stdlib.Lazy` does).

- Add `Eio.Path.native` (@talex5 ocaml-multicore/eio#603, reviewed by @patricoferris).
  This is useful when interacting with non-Eio libraries, for spawning sub-processes, and for displaying paths to users.

- Add `Flow.single_write` (@talex5 ocaml-multicore/eio#598).

- Add `Eio.Flow.Pi.simple_copy` (@talex5 ocaml-multicore/eio#611).
  Provides an easy way to implement the `copy` operation when making your own sink.

- Eio_unix: add FD passing (@talex5 ocaml-multicore/eio#522).
  Allows opening a file and passing the handle over a Unix-domain socket.

- Add `Process.run ?is_success` to control definition of success (@SGrondin ocaml-multicore/eio#586, reviewed by @talex5).

- Add `Eio_mock.Domain_manager` (@talex5 ocaml-multicore/eio#610).
  This mock domain manager runs everything in a single domain, allowing tests to remain deterministic.

- Add `Eio.Debug.with_trace_prefix` (@talex5 ocaml-multicore/eio#610).
  Allows prefixing all `traceln` output. The mock domain manager uses this to indicate which fake domain is running.

Bug fixes:

- Fork actions must not allocate (@talex5 ocaml-multicore/eio#593).
  When using multiple domains, child processes could get stuck if they forked while another domain held the malloc lock.

- eio_posix: ignore some errors writing to the wake-up pipe (@talex5 ocaml-multicore/eio#600).
  If the pipe is full or closed, the wake-up should simply be ignored.

Build/test fixes:

- Fix some MDX problems on Windows (@polytypic ocaml-multicore/eio#597).

- The README depends on kcas (@talex5 ocaml-multicore/eio#606).

- Clarify configuration for lib_eio_linux and enable tests on other arches (@dra27 ocaml-multicore/eio#592).

- eio_linux tests: skip fixed buffer test if not available (@talex5 ocaml-multicore/eio#604).

- eio_windows: update available line to win32 (@talex5 ocaml-multicore/eio#588 ocaml-multicore/eio#591).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants