ngx_upstream_jdomain
ngx_upstream_jdomain copied to clipboard
Use shared memory
Would be better to share jdomain state among all workers in order to save on redundant DNS queries and also keep all workers in sync when an update occurs.
I too think this would be really good as it would prevent the inrush of DNS queries after daemon reload.
Any chance @nicholaschiasson that you are going to look into this. I'm happy to help (although I'm not super familiar with nginx).
I would be happy to make some contributions on other matters however, like getting the tests working again
Hi @splitice , unfortunately I haven't had the time to address this. I would appreciate some help for sure. I realized right away with my last change that I broke tests and had been trying to fix that but got sidetracked. If you are willing to help with that of course that would be super appreciated! Just drop a merge request whenever you like.
Won't the zone directive present in upstream module do the job here?
http://nginx.org/en/docs/http/ngx_http_upstream_module.html#zone
If you check the function ngx_http_upstream_zone_copy_peers in ngx_http_upstream_zone_module.c, in the end it sets pointer of peers in ngx_http_upstream_srv_conf_t to a pointer backed by shared memory pool.
We don't have to do much on our end. Just need to store the mutex and shpool from ngx_http_upstream_rr_peers_t
during ngx_http_upstream_init_jdomain (in instance struct I would say) and then use something like ngx_http_upstream_rr_peers_wlock and ngx_http_upstream_rr_peers_unlock for the stored shared pool during ngx_http_upstream_jdomain_resolve_handler while updating the peers.
At that point, instance struct should probably be moved to shared memory pool as well (shpool).
Looks like shared memory pool has init after the modules configuration init where upstream module called upstream_init. So the pointers copied by jdomain won't be the shared ones.