Which erlang pool is suitable?

I hope this pool has the ability (or options) to automatically reduce the amount of work time when free for the maximum wait timeout.

I read the doc poolboy

and worker_pool

and found that there is only an option for the maximum number of workers, but no option to reduce it.

Does this exist or how to modify them?

+3


source to share


2 answers


poolboy automatically reduces the number of workers if there is no work for them.

You get a worker to do some work with checkout

from the pool, and you release the worker with the help checking

, alternatively, you attach a work on transaction

that automatically checks the worker and after it completes it checks the worker.

When you start the pool, poolboy automatically creates several working sizes, waiting for some work to be done.

When you call checkout

, the pullboy tries to get one of the already running workers, if all the workers are already checking because they are doing some work, it checks its max_overflow configuration and starts creating workers to handle the load until it reaches max_overflow.

When an employee is released, if there are more jobs, they are killed.



So if you are creating a pool like

{pool, [
        {size, 100},
        {max_overflow, 900}
]}

      

It will start 100 processes at once, and if you check (with checkout

or transaction

) more than 100 workers at the same time, then for new checks it will start creating processes until they reach a total of 1000 processes (100 created from the first moment and a maximum overflow of 900 processes), if you keep checking more processes, it will start giving timeout errors (unless you call the check with infinity

, in which case it will block until the worker gets free to complete the task, note, that you can also call the worker without blocking the caller).

Now if you need more behavior than this, for example, keep running the overflow until it's 10 minutes of inactivity, you will need to make your own code, in which case you can just get the source code of the pull-boy (which lends itself easily to is executed, the main code is at https://github.com/devinus/poolboy/blob/master/src/poolboy.erl and its only 350 lines of code) and update the worker release according to your needs

+6


source


https://github.com/seth/pooler also has this capability. See https://github.com/seth/pooler#culling-stale-members section .



0


source







All Articles