mongodb-erlang icon indicating copy to clipboard operation
mongodb-erlang copied to clipboard

mongo server is stop, Reconnect Increase delay

Open panzixin39 opened this issue 6 years ago • 7 comments

mc_worker.erl init()-> ...... Error -> receive after 3000 -> ok end, %%add proc_lib:init_ack(Error) end.

panzixin39 avatar Jan 07 '19 06:01 panzixin39

why should we wait after error was detected?

comtihon avatar Jan 07 '19 09:01 comtihon

Control the frequency of reconnection,Reducing CPU Occupancy

panzixin39 avatar Jan 07 '19 10:01 panzixin39

I think some top supervisor should be responsible for worker restart delay. Not the worker itself, as it know nothing about will it be restarted or not.

comtihon avatar Jan 08 '19 09:01 comtihon

Reconnection requires delay。Where to change, you are free

panzixin39 avatar Jan 08 '19 10:01 panzixin39

it is not supported out of the box. There are several options:

  • You should use your own supervisor, have mc_worker be a child and restart it with backoff (can be increment). You can try something ready like this or this
  • use standard supervisor, but custom start function - wrapper around mc_worker with try-catch and your delay code. I think it is the easiest and the fastest solution.
  • use standard supervisor + standard worker, but without reconnect. Use your monitor process, which will monitor the pool and shoot a timed restart (start new worker actually) if error encountered.

comtihon avatar Jan 08 '19 18:01 comtihon

I think reconnect with delay is useful, but I can't promise I'll have a time implementing this in the nearest future.

comtihon avatar Jan 08 '19 18:01 comtihon

ok.

panzixin39 avatar Jan 09 '19 01:01 panzixin39