Simple use of jobs application failing

Ulf Wiger ulf@REDACTED
Sun Nov 14 19:55:34 CET 2021


In jobs, `max_size` has to do with how large the queue is allowed to get.
What you appear to be looking for is `counter`.

Example:
Eshell V10.7.2.8  (abort with ^G)
1> application:ensure_all_started(jobs).
{ok,[jobs]}
2> jobs:add_queue(kalle, [{standard_counter,3}]).
ok
3> [spawn(fun() -> jobs:ask(kalle), io:fwrite("--> ~p: ~p~n", [time(),
self()]), timer:sleep(3000), exit(normal) end) || _ <- lists:seq(1,10)].
--> {19,53,29}: <0.128.0>
--> {19,53,29}: <0.129.0>
--> {19,53,29}: <0.130.0>
[<0.128.0>,<0.129.0>,<0.130.0>,<0.131.0>,<0.132.0>,
 <0.133.0>,<0.134.0>,<0.135.0>,<0.136.0>,<0.137.0>]
--> {19,53,32}: <0.131.0>
--> {19,53,32}: <0.133.0>
--> {19,53,32}: <0.132.0>
--> {19,53,35}: <0.134.0>
--> {19,53,35}: <0.135.0>
--> {19,53,35}: <0.136.0>
--> {19,53,38}: <0.137.0>

>From the docs:
"{standard_counter, C} - equivalent to [{regulators,[{counter,[{limit,C},
{modifiers,[{cpu,10},{memory,10}]}]}]}]"

(Usually, one doesn't specify the modifiers)

BR,
Ulf

On Sat, Nov 13, 2021 at 6:12 PM bengt <cean.ebengt@REDACTED> wrote:

> Greetings,
>
> I would like to allow at most 3 processes to call a gen_server at the same
> time. I could check the message queue length, but why not use jobs (
> https://github.com/uwiger/jobs) ?
>
> Jobs is already in use by something I depend on, so it should be working.
> I test from the (iex) shell. As can be seen below I am making a mistake
> somewhere. Probably config, so how should I configure to only get 3 of the
> 5 jobs:ask/1 to be approved and queued? Or I have misunderstood the use,
> and an explanation of how to achieve the 3 caller limitation would be
> appreciated.
>
>  :jobs.add_queue(:kalle,  [{:max_size, 3}])
>   for _ <- [1,2,3,4,5], do: :jobs.ask(:kalle)
>   IO.inspect :jobs.queue_info(:kalle)
>
>    name: :kalle,
>    max_size: 3,
>    approved: 5,
>    queued: 5,
>    latest_dispatch: 378734152926266,
>    mod: :jobs_queue,
>    type: :fifo,
>    group: :undefined,
>    regulators: [],
>    max_time: :undefined,
>    check_interval: :infinity,
>    oldest_job: :undefined,
>    timer: :undefined,
>    link_ref: :undefined,
>    check_counter: 0,
>    empty: false,
>    depleted: false,
>    waiters: [],
>    stateful: :undefined,
>    st: {:st, #Reference<0.2285429207.3584425985.10312>},
>    producers: []
>
> Best Wishes,
> bengt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20211114/70c243de/attachment.htm>


More information about the erlang-questions mailing list