Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6809421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:05:04+00:00 2026-05-26T20:05:04+00:00

I’ve just read a paper about the Leader/Follower Pattern and if I understood correctly,

  • 0

I’ve just read a paper about the Leader/Follower Pattern and if I understood correctly, I keep my workers in a queue and the first worker takes an incoming request and detaches from the queue.

With a normal work-queue (rabbitmq and beanstalkd, for example) its the other way round: i keep my jobs in a queue and once a worker finishes processing it just takes the first job from the queue.

Is there somehing I’m missing?

So, what are the advantages I should use a Leader/Follower approach instead of a work queue? Or the other way round, in what situations is a work queue suited better?

Bye,
Nico

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:05:05+00:00Added an answer on May 26, 2026 at 8:05 pm

    Leader/Follower is about efficiently dealing with multiple workers. When you have no work (jobs), what are your worker or workers doing? A common, simple approach is to have a single consumer thread dispatch jobs to workers, either by spawning a thread or using a thread pool. The pattern discussed provides an alternative approach that avoid having to synchronize between the dispatcher and the worker by having the (leader) thread that gets the job execute the work task itself. It promotes a waiting worker to the leader position to keep the system responsive.

    Be aware that this article is discussing lower-level mechanisms for waiting for work that do not (easily) support multiple threads waiting on the same “queue” of work. Higher-level constructs like message queues that do support multiple worker threads all performing a blocking read on the same source (AKA competing consumers) may not get the same benefit described. With a higher level of abstraction comes more programming ease, but typically at the cost of the kind of performance that can be gained from a more low-level approach.

    EDIT1:

    Here’s a made-up sample (pseudocode only). Please note that I did not write the article or benchmark it so I cannot truly speak about the performance of one versus the other. But hopefully, this shows the difference in style.

    // in QueueHandler processing loop
    
    while(true)
    {
       // read, blocking until one arrives
       Request req = requestQueue.BlockingRead();
    
       // we have a unit of work now but the QueueHandler should not process it
       //  because if it is long running then no new requests can be handled.
       //  so we spawn / dispatch to a thread
       ThreadPool.QueueWorkItem(req);
       // or new Thread(DoWork(), req).Start;
    
       // at this point we know that the request will get picked up in 
       // an unknown but hopefully very short amount of time by a 
       // waiting (sleeping/blocking) or new thread and it will get passed the 
       // work.  But doing so required the use of thread synchronization 
       // primitives that can cause all processors to flush their caches 
       // and other expensive stuff.
    
    
    } // now loop back up to read the next request
    

    VS

    // in Leader
    
    while(true)
    {
    
       // I'm the leader, blocking read until a request arrives
       Request req = queue.BlockingRead();
    
       // We have a unit of work and we are going to process it ourselves.  
       // But first we notify a follower.
       Followers.PromoteOne();
    
       // work on the request in this thread!
       DoWorkOn(req);
    
       // now that I'm done, wait to the the leader
       Followers.BlockingWaitToBeLeader();
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm making a simple page using Google Maps API 3. My first. One marker
For some reason, after submitting a string like this Jack’s Spindle from a text
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.