Comments (7)
Hello,
Implement your worker as gen_server, and in code send a message to self() with erlang:send_after, in handle_info catch the message to do the timed operation.
Regards.
from pooler.
yeah, that would work for the ping scenario.
But assume a situation where I would want to invoke a command for all workers to perform a given task in a broadcast manner. What options would I have then?
from pooler.
I find the need to have an additional process who owns riakc_pb_socket process a poor solution. Since it implies a lot of boiler plate to be written or introduce knowledge of 'this is not riakc_pb_socket process but a general wrapper' to whom ever checks out the worker, it's not a big issue to do this I just find it unnecessary and see it as a missing feature.
In the latest client code for Riak there is keep alive option for tcp but that's also a poor substitute if you're behind load balancers who sets up two tcp session on either side of itself.
I'm quite curious to know what paths people have taken here besides the mentioned one.
from pooler.
I've implemented similar health checks by putting that code into the client (the pooled member) itself.
What's the interface you'd like to have for communicating with all pool members? Do you want to apply the same function to each member? How do you want to handle members that are busy? Or do you only want to worry about free members?
from pooler.
Hi Seth
For now free members should be enough. I don't see an equally cheap way of getting out all members as free members. One way would be to take the keys from #pool.all_members dict. If you've got other suggestions I'm open to experiment with it.
call_free_members(PoolName, Fun, Timeout)
Where it applies Fun over all free members taken from #pool record and return the result.
handle_call({call_free_members, Fun}, _From, #pool{free_pids = Pids} = Pool) ->
{reply, {ok, do_call_free_members(Fun, Pids)}, Pool};
do_call_free_members(Fun, Pids) ->
[do_call_free_member(Fun, P) || P <- Pids].
do_call_free_member(Fun, Pid) ->
try {ok, Fun(Pid)}
catch
exit:{Reason, _What} ->
{error, Reason}
end.
I'm just thinking what the consequence of this would be. One obvious consequence is a free member X could be performing Fun while a user takes the same member to perform a task.
Though this would be the same if I were to put such code in pooled member so I don't see this as a big problem.
I'm experimenting a bit now and I can make a PR later on if you're ok with this approach.
from pooler.
That seems like a fairly reasonable approach. On the try/catch
you'll want to not match on the error type since things could crash with throw
, exit
, error
. If an approach as above would help you, I'm up for merging it with some level of tests and docs. :)
from pooler.
Okay. Created PR #52.
from pooler.
Related Issues (20)
- Unit test failed for Erlang Release 17
- Support OTP 18 HOT 4
- metrics? HOT 1
- Unexpected :error_no_members HOT 7
- Build failure with OTP 18.1 HOT 2
- pooler:take_member returns same PID all the time HOT 10
- eredis and pooler - pair not made in heaven HOT 3
- Failed to start member
- Should add API for take_group_member/2? HOT 1
- Use docs instead of dev profile
- pooler:time_as_{millis, micro}/2 tests break with rebar3 on R15B03-1 HOT 2
- "exit with reason killed in context child_terminated" problem HOT 2
- Support: should add a map to choose a pool to start under different conditions in config HOT 1
- :error_no_group when function is called from a separate app HOT 3
- erlang/otp 20 , pooler 1.5.2, can not compile HOT 2
- ERROR REPORT when start with make run HOT 1
- Node Failure Handling, HOT 1
- add_member_retry seems to be not in use anymore
- Add prometheus-style metics API
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pooler.