# Writing a module-syncing upstreams from conf-servers

**URL:** <https://www.ruby-forum.com/t/writing-a-module-syncing-upstreams-from-conf-servers/243825>\
**Category:** NGINX\
**Created:** [January 13, 2016, 7:58am UTC](https://www.ruby-forum.com/t/writing-a-module-syncing-upstreams-from-conf-servers/243825 "2016-01-13T07:58:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [January 13, 2016, 7:58am UTC](https://www.ruby-forum.com/t/writing-a-module-syncing-upstreams-from-conf-servers/243825/1 "2016-01-13T07:58:32Z")

</div>

Hi Nginxers,I’m writing a new module that syncs upstreams from  
conf-servers(consul, etcd…). During the nginx offering service, the  
module makes requests to the conf-server(consul, etcd…) to pull  
upstreams backend list if upstreams value has changed and update  
upstreams peers to make new backend servers working.  
The reason I write the module is that: Last the Spring Festival,  
the company need extend the backend resources for the festival, need  
reload the new configuration of nginx, and find that partly requests  
cost much more time during the reloading, suspect it’s caused by  
reloading. The last, I think the fact prove it’s true. The  
contrast between reloading and using module. Other refer:  
[Dynamic Reconfiguration with NGINX Plus | NGINX](https://www.nginx.com/blog/dynamic-reconfiguration-with-nginx-plus/) .On  
the other hand, the module I am writing is mostly different than other  
modules I could learn from, and all my knowledge about nginx is from  
looking at how other modules is written, I’m wondering and hoping if  
anyone could comment on how I designed the module and raise any issues  
if I did anything problematic, wrong, weird or even stupid.  
Any convenience, the module is here:  
[GitHub - weibocom/nginx-upsync-module: For http protocol. nginx-upsync-module, sync upstreams from consul or etcd and so on, dynamiclly modify backend-servers attributes(weight, max\_fails, down...), needn't reload nginx](https://github.com/weibocom/nginx-upsync-module)

As everyone knows every work process has it’s conf, so the module  
realizes that every work-process pulls upstreams independently and  
updates its own peers. I think that’s easy and more reliable. Every  
peers is a array, so every updating need a new array and delete old  
peers, but, when delete old peers needing judge if having old requests  
use that. It’s a little complicated.What do you think?  
work-process flow: startup-\>pull from conf-servers-\>pull success-\>try to  
update-\>work; startup-\>pull from  
conf-servers-\>failed, parse dump file-\>try to update-\>work;I am not sure  
I make that clear, but I really want to get you advise. Any comments,  
suggestions, warnings are welcome.

-----Regards,Xiaokai
