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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:23:40+00:00 2026-06-04T10:23:40+00:00

I am working on a Python backend web server that grabs realtime data from

  • 0

I am working on a Python backend web server that grabs realtime data from a paid 3rd party API.
I need to query this API very fast (about 150 queries per 10 seconds). Therefore, I created a small proof of concept that spawns 200 threads and writes urls to a queue. The threads then read from the url from the queue and send the HTTP request. The 3rd party API returns a value called delay, which is how long it took their server to process the request.
Here is the POC code that just downloads all the urls (not repeatedly).

_http_pool = urllib3.PoolManager()

def getPooledResponse(url):
    return _http_pool.request("GET", url, timeout=30)

class POC:
    _worker_threads = []
    WORKER_THREAD_COUNT = 200
    q = Queue.Queue()

    @staticmethod
    def worker():
        while True:
            url = POC.q.get()
            t0 = datetime.datetime.now()
            r = getPooledResponse(item)
            print "thread %s took %d seconds to process the url (service delay %d)" % (threading.currentThread().ident, (datetime.datetime.now() - t0).seconds, getDelayFromResponse(r))
            POC.q.task_done()

    @staticmethod
    def run():
          # start the threads if we have less than the desired amount
          if len(POC._worker_threads) < POC.WORKER_THREAD_COUNT:
              for i in range(POC.WORKER_THREAD_COUNT - len(POC._worker_threads)):
                  t = threading.Thread(target=POC.worker)
                  t.daemon = True
                  t.start()
                  POC._worker_threads.append(t)

          # put the urls in the queue
          for url in urls:
              POC.q.put(url)
              # sleep for just a bit so that the requests don't get sent out together (this is a limitation of the API I am using)
              time.sleep(0.3)   
POC.run()

When I run this, the first few results are returned with a reasonable delay:

thread 140544300453053 took 2 seconds to process the url (service delay 1.782)

However, after about 10-20 seconds I get these kinds of things:

thread 140548049958656 took 23 seconds to process the url (service delay 1.754)

In other words, even though the server returns with a small delay, my threads take longer to complete…

How do I test to see where the other 21 running seconds are spent?

Thanks!

  • 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-04T10:23:42+00:00Added an answer on June 4, 2026 at 10:23 am

    You should use a profiler on the code.

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

Sidebar

Related Questions

I am currently working on a complex web interface and backend, that will need
I need to have an at-home project now that I'm working on Python/Django at
I'm working on a backend for an open source Python ORM. The library includes
I'm working with django-piston to attempt to create an API that supports oAuth. I
I have a working Python based program that I want to run as a
I have a working Python script that executes an external command and calls Popen.communicate()
I am using django-1.2 and python-2.6 and I am using mysql server. After working
I'm thinking of switching from using PHP to Python for web applications, but I
I'm writing a reasonably complex web application. The Python backend runs an algorithm whose
I'm working on a project that runs off Google App Engine (Python) which stores

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.