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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:44:53+00:00 2026-06-16T18:44:53+00:00

I have this code and have noticed when specifying more than 1 thread, performance

  • 0

I have this code and have noticed when specifying more than 1 thread, performance suffers. The concept here is simple, setup a Queue in multiprocessing, access it from each thread, equally– note I am using an easily divisible queue size here.

import time
from  multiprocessing import Process, Queue

def worker(q,x):
    for i in range(x):
        message = q.get()


if __name__ == "__main__":

    workers=[]
    threads=1
    x = int(1000000/threads) #break up the work for each thread
    q = Queue()

    for i in range(threads):
        p=Process(target=worker, args=(q,x))
        workers.append(p)


    print('creating queue')
    for num in range(1000000):
        q.put("MESSAGE")

    start_time = time.time()

    print('starting jobs')
    for p in workers:
        p.start()

    print('waiting until jobs finish')
    for p in workers:
        p.join()

    end_time = time.time()

    duration = end_time - start_time
    msg_per_sec = 1000000 / duration

    print ("Duration: %s" % duration)
    print ("Messages Per Second: %s" % msg_per_sec)

I have made a different script with multiprocessing threads performing urllib requests and it shows that scaling processors helps speed things up, so what am I doing wrong here; is it that I am accessing queue from all of the processes and am essentially blocking?

  • 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-06-16T18:44:55+00:00Added an answer on June 16, 2026 at 6:44 pm

    The issue is that your workers are not doing any useful work. All the time is spent getting stuff off the queue. The queue is shared and all access to it is serialized, hence no speedup.

    Once the workers start taking some CPU or I/O time to process each message, things should start improving.

    See Amdahl’s Law.

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

Sidebar

Related Questions

I've noticed a weird discrepancy in C++. Say I have this code: const char
I have this piece of code here below: $fq.= + (fritidsboende_uth_from:[$fritids_uth_from TO *] AND
I have a really simple class, and within the implementation I have this code:
I have this piece of code that basically checks if one or more files
In my app I have this code. I noticed, that content-type fails to be
I noticed that a lot of tutorial instructions often have this code: $sql=SELECT *
I have this code <div id=main style=background:#aaaaaa;float:left;height:160px;margin:5px;position:relative;display:block;width:630px;> <div id=1 class=item style=background:#ffaacc;float:left;width:200px;height:150px;margin:5px;position:absolute;left:0px;top:0px;> </div> <div id=2
I have this code : void Main() { System.Timers.Timer t = new System.Timers.Timer (1000);
I have this code for changing the image of a button: - (void)mouseEntered:(NSEvent *)event
I have this code in XAML <Grid x:Name=LayoutRoot Background=Transparent> <Grid.RowDefinitions> <RowDefinition Height=Auto/> <RowDefinition Height=*/>

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.