swarm-dashboard icon indicating copy to clipboard operation
swarm-dashboard copied to clipboard

Use /events API

Open trajano opened this issue 8 months ago • 0 comments

You noted in the README

The interaction with docker API is a fairly rough implementation and is not very optimized. The server polls the API every 500 ms, publishing the response data to all open WebSockets if it changed since last time. There is probably a better way to look for changes in the Swarm that could be used in the future.

The way I think you can do this is with /events but from my experience, I suggest you use it as a trigger to pull changes asap rather than building from it.

That is to say the logic would be something like

  1. /events?since=0s monitor to start listening for an event record
  2. If event received or 2 seconds (as fallback) have passed pause the monitor
  3. fetch the data and update from whatever is needed
  4. restart the monitor

You can "reconsititute" some of the data using the events but I suggest you skip that notion first because some events may get dropped or the order may not be what you expect. (again based on experience writing this https://github.com/trajano/spring-cloud-demo/blob/rework/gateway/src/main/java/net/trajano/swarm/gateway/discovery/DockerEventWatcher.java)

trajano avatar Oct 21 '23 18:10 trajano