Explain “Leader/Follower” Pattern

后端 未结 5 1014
野趣味
野趣味 2020-12-12 15:15

I can\'t seem to find a good and accessible explanation of \"Leader/Follower\" pattern. All explanations are simply completely meaningless as in 1.

Can anyone explai

5条回答
  •  不思量自难忘°
    2020-12-12 15:49

    I think the most 'hands on' example is phusian passenger and a rails application. (Kind of misleading passenger is actually a mod_rails apache process that manages many ruby apps that are sleeping/parked).

    So you develop a rails app or sinatra app. Then deploy it on a webserver with passenger installed.

    The leader is actually the Passenger load balancer. The passenger is someone visiting a webpage. The taxi cabs are the sleeping instances of your rails app in the passenger device pool.

    When you set this pool to be 45 (database.yml in rails app). Your saying I want 45 taxis ready to serve the webpages. When someone visites a virtual host passenger delegates the request to one of the 45 waiting rails apps. The apps don't have to communicate with eachother because they're all connected to the same database backend (or multiple is possible too if you do replication of your data).

    http://www.modrails.com/.

    The cool thing is that even though the seperate processes might take a while to process a request the total system is really efficient/fast because you have 45 of them ready to handle the requests. So even if the first taxi (rails app) isn't back from it's ride (serving a requested page) the second waiting instance in line can be used for a next request. As soon as the first finishes it also goes back to the queue and this way you can be responsive and get easily 4000+ pagereq./sec even though a single rails app can only handle 400req/sec. Ofcourse there are limitations (memory etc for the pool size, otherwise you could take a poool size of 200000 rails apps) but in practice this works very well...

提交回复
热议问题