-
Notifications
You must be signed in to change notification settings - Fork 10
Description
From @krancour on October 6, 2016 16:52
Currently, the router does all of the following every ten seconds:
- Find the router's own deployment object.
- Find all routable services.
- Find secrets that contain certificates
All of these are the inputs used to build / compute a model. This model is deep compared to the previously computed model, which is kept in memory. When there are differences, Nginx configuration is re-generated by using the new model as input to a template. Nginx is reloaded with the new configuration.
Note that the model is computed before any comparison is made so that inconsequential changes to k8s resources (those that wouldn't affect the router's configuration) won't trigger an unnecessary Nginx reload.
Here's where there's room to optimize-- I feel like continuously computing the model is wasteful since changes that affect the router's configuration are a relatively rare event. This not only wastes CPU cycles, but depending on how many routable services live in your cluster, this process can be very chatty with the apiserver. This puts an unnecessary load on the network.
A more mature approach to this may be to watch the k8s event stream instead. Only in the event that a k8s resource we're interested in (as determined by a label or well known name) has been added or modified should we care about retrieving those resources and re-computing the model. What's more, because we'd know what changed before re-computing the model, we could also re-compute and replace a portion of the existing model.
cc @arschles -- I feel like if there's any obvious problem with this approach, you'd be the guy to spot it. 😉
Copied from original issue: deis/router#274