leofs
leofs copied to clipboard
[all] prevent gen_servers from getting stuck with lots of messages
Details are described here https://github.com/leo-project/leofs/issues/725#issuecomment-305393080. In order to make such stuck happen as less times as possible, we can make a request to a gen_server more scalable/responsive in specific cases by
- Get the actual work started when there is NO requests to that work
- Wait for the work to be completed when there are already requests to that work
The reference implementation can be found here
- https://github.com/erlang/otp/blob/master/lib/os_mon/src/memsup.erl
The process calling get_memory_usage/1 is spawned ONLY when there is no spawned process and all callers wait for finishing the spawned process and a response sent back to them through reply/3 with pending PIDs.
https://github.com/leo-project/leo_tran might be generic solution to this sort of problems.
Also https://github.com/ferd/pobox should be considered in general cases for safe.