title: Response time using aiohttp increases over time
body: <p>I have an API "localhost/service" that takes on average 2s to return when requested serially and about 8s when I set up 10 threads to request it in parallel. I wanted to replicate those numbers using asyncio, without threads. The way I decided to do that was following this <a href="https://pawelmhm.github.io/asyncio/python/aiohttp/2016/04/22/asyncio-aiohttp.html" rel="nofollow noreferrer">article's</a> code and setting the semaphore to 10. for the first 20 or so requests I get response times of 8s but after that the response times start increasing quite dramatically. I keep requesting the server using postman on the side and its consistently returning response times of 8s while this script using asyncio is reporting times of over a minute per request. What am I doing wrong here?</p>
  
  <pre><code>import time
  import asyncio
  from aiohttp import ClientSession
  
  async def fetch(url, session):
      start = time.monotonic()
      async with session.get(url) as response:
          end = round(time.monotonic() - start, 4)
          print("response time: {}".format(end))
          return await response.read()
  
  
  async def bound_fetch(sem, url, session):
      # Getter function with semaphore.
      async with sem:
          await fetch(url, session)
  
  
  async def run(r):
      url = 'http://localhost:8080/service'
      tasks = []
      # create instance of Semaphore
      sem = asyncio.Semaphore(10)
  
      # Create client session that will ensure we dont open new connection
      # per each request.
      async with ClientSession() as session:
          for i in range(r):
              # pass Semaphore and session to every GET request
              task = asyncio.ensure_future(bound_fetch(sem, url.format(i), session))
              tasks.append(task)
  
          responses = asyncio.gather(*tasks)
          await responses
  
  number = 10000
  loop = asyncio.get_event_loop()
  
  future = asyncio.ensure_future(run(number))
  loop.run_until_complete(future)
  </code></pre>