Trevoke / dwarlixir

A dwarf-fortress clone / MUD / side project in Elixir
MIT License
50 stars 0 forks source link

Event system #10

Open Trevoke opened 7 years ago

Trevoke commented 7 years ago

Controllers need to be notified of events like something giving birth or something dying or something leaving the loc or something entering the loc

Trevoke commented 7 years ago

Idea from the MUD Coders Slack - might be slightly overkill, not sure.

You have a few layers in this setup: user input and ticks are event publishers, which broadcast to subscription managers, which select the interested subscribees and send them events, which then match on the specific event details to process them, and possibly publish new events of their own.

Number of messages isn’t the problem, it’s time spent processing them. There are about 3 places where backpressure could accrue.

You’re going to want to use Registry (https://hexdocs.pm/elixir/master/Registry.html) to implement pub/sub and GenStage (https://hexdocs.pm/gen_stage/GenStage.html) to manage the backpressure. This trades off the risk of the system getting overwhelmed and crashing under impossible load, for the still problematic introduction of lag under impossible load. So you probably want to make your tickers aware of backpressure to get EVE-online style time dilation, and set up some sort of throttling on user input event generation to prevent bad actors from clogging your event pipeline.