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 4242634
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:28:08+00:00 2026-05-21T03:28:08+00:00

I have a 3-step producer/consumer setup. Client creates JSON-encoded dictionaries and sends them to

  • 0

I have a 3-step producer/consumer setup.

Client creates JSON-encoded dictionaries and sends them to PipeServer via a named pipe

Here are my threading.Thread subclasses:

PipeServer creates a named pipe and places messages into a queue unprocessed messages

Processor gets items from unprocessed messages, processes them (via a lambda function argument), and puts them into a queue processed messages

Printers gets items from processed messages, acquires a lock, prints the message, and releases the lock.

In the test script, I have one PipeServer, one Processor, and 4 Printers:

pipe_name = '\\\\.\\pipe\\testpipe'
pipe_server = pipetools.PipeServer(pipe_name, unprocessed_messages)

json_loader = lambda x: json.loads(x.decode('utf-8'))
processor = threadedtools.Processor(unprocessed_messages,
                                    processed_messages,
                                    json_loader)

print_servers = []
for i in range(4):
    print_servers.append(threadedtools.Printer(processed_messages,
                                         output_lock,
                                         'PRINTER {0}'.format(i)))

pipe_server.start()
processor.start()
for print_server in print_servers:
    print_server.start()

Question: in this kind of multi-step setup, how do I think through optimizing the number of Printer vs. Processor threads I should have? For example, how do I know if 4 is the optimal number of Printer threads to have? Should I have more processors?

I read through the Python Profilers docs, but didn’t see anything that would help me think through these kinds of tradeoffs.

  • 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-21T03:28:09+00:00Added an answer on May 21, 2026 at 3:28 am

    Generally speaking, you want to optimize for the maximum throughput of your slowest component. In this case, it sounds like either Client or Printer. If it’s the Client, you want just enough Printers and Processors to be able to keep up with new messages (maybe that’s just one!). Otherwise you’ll be wasting resources on threads you don’t need.

    If it’s Printers, then you need to optimize for the IO that’s occurring. A few variables to take into account:

    • How many locks can you have simultaneously?
    • Do you have to maintain the lock for the length of a printing transaction?
    • How long does a printing operation take?

    If you can only have one lock, then you should only have one thread, so on and so forth.

    You then want to test with real world operation (it’s difficult to predict what combination of RAM, disk and network activity will slow you down). Instrument your code so you can see how many threads are idle at any given time. Then create a test case that processes data into the system at maximum throughput. Start with an arbitrary number of threads for each component. If Client, Processor, or Printer threads are always busy, add more threads. If some threads are always idle, take some away.

    You may need to retune if you move the code to a different hardware environment – different number of processors, more memory, different disk can all have an effect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a step in my application where a user repeatedly hears three spoken
I have this step definition: Given /^I am not logged in$/ do visit '/users/sign_out'
I have many jobs that have a step to send 1 specific email out
I have a three-step process that is entirely reliant upon JavaScript and Ajax to
I have completed every step in XMonad's tutorial for Mac. However, I cannot start
I have a multi-step BackgroundWorker process. I use a marquee progress bar because several
I have a multi-step form where the form on Step3 submits to Step4.php. Step4
I have the following step: Then I should see an error message with identical
I have got a the following problem: I have got multi-step form where in
have one time consuming step that flattens a bunch of files. basically i'd like

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.