barrel_parallel (barrel_docdb v1.1.1)

View Source

Parallel execution utilities for barrel_docdb

Provides bounded parallel map operations using a static worker pool. Workers are pre-spawned and reused, eliminating per-operation spawn overhead. Similar to PostgreSQL's background worker pool approach.

Summary

Functions

Get default number of workers (scheduler count)

Parallel filtermap with default concurrency

Parallel filtermap with bounded concurrency, preserves order

Parallel map with default concurrency

Parallel map with bounded concurrency, preserves order

Start the worker pool with default worker count

Start the worker pool with specified worker count

Stop the worker pool

Functions

get_default_workers()

-spec get_default_workers() -> pos_integer().

Get default number of workers (scheduler count)

handle_call(Request, From, State)

handle_cast(Msg, State)

handle_info(Info, State)

init(WorkerCount)

pfiltermap(Fun, Items)

-spec pfiltermap(fun((A) -> boolean() | {true, B}), [A]) -> [B] when A :: term(), B :: term().

Parallel filtermap with default concurrency

pfiltermap(Fun, Items, MaxWorkers)

-spec pfiltermap(fun((A) -> boolean() | {true, B}), [A], pos_integer()) -> [B]
                    when A :: term(), B :: term().

Parallel filtermap with bounded concurrency, preserves order

pmap(Fun, Items)

-spec pmap(fun((A) -> B), [A]) -> [B] when A :: term(), B :: term().

Parallel map with default concurrency

pmap(Fun, Items, MaxWorkers)

-spec pmap(fun((A) -> B), [A], pos_integer()) -> [B] when A :: term(), B :: term().

Parallel map with bounded concurrency, preserves order

start_link()

-spec start_link() -> {ok, pid()} | {error, term()}.

Start the worker pool with default worker count

start_link(WorkerCount)

-spec start_link(pos_integer()) -> {ok, pid()} | {error, term()}.

Start the worker pool with specified worker count

stop()

-spec stop() -> ok.

Stop the worker pool

terminate(Reason, State)