jeremieca
jeremieca

Reputation: 1188

Why do agents have a pool of threads?

In clojure documentation I see that agent use a pool of thread to process data. But I read that (always in documentation) :

The actions of all Agents get interleaved amongst threads in a thread pool. At any point in time, at most one action for each Agent is being executed.

Why does an agent have a pool of thread and not a single thread to process the "queue" of sended function ?

Thanks.

Upvotes: 0

Views: 103

Answers (1)

deprecated
deprecated

Reputation: 5252

An agent does not 'have a pool of threads'. There are two thread pools (for send and send-off actions), to which agent actions get assigned.

This design decision is the optimal choice for CPU-bound tasks, and a best-effort approach for IO-bound tasks.

For the latter case, providing your own pool with send-via will be the optimal choice (assuming you know what you're doing).

Upvotes: 2

Related Questions