Consistent slowdown in HTTP requests made from inside a container

Expected behavior

A consistent rate of HTTP requests performed from inside a container.

Actual behavior

Approximately every 10th HTTP request will have a 3s delay, believed to be a TCP retransmission error.

Information

I am running a simple python server on the host machine of the docker container. I then have a container with a very simple python (or java) application to send requests to the server. Roughly every 10 requests has a 3s delay.
With both script and server inside a single container I have no issue, with both outside equally there is no slowdown.

Dockerfile:

FROM python:3-windowsservercore-ltsc2016
ADD . .
RUN pip install requests
CMD ["python", "test.py"]

test.py:

import logging
import requests
logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(levelname)-8s %(message)s',
                    datefmt='%Y-%m-%d %H:%M:%S',
                    handlers=[logging.FileHandler(filename='test.log', mode='w'),
                              logging.StreamHandler()]
                    )
logger = logging.getLogger()
requests_log = logging.getLogger('requests.packages.urllib3')
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True

def main():
    ''' Main function '''
    url = 'http://<HOST IP>:666/endpoint'

    for i in range(500):
        requests.get(url=url)
        logger.info('Got response')

if __name__ == '__main__':
    main()

Python server:

import logging
from flask import Flask, request, jsonify
from flask_restful import Resource, Api

logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s %(levelname)-8s %(message)s',
                    datefmt='%Y-%m-%d %H:%M:%S',
                    handlers=[logging.FileHandler(filename='API_demo.log', mode='w'),
                                logging.StreamHandler()]
                    )
logger = logging.getLogger()

app = Flask(__name__)

api = Api(app)

class endpoint(Resource):
    def get(self):
        logger.info('recv')
        return {'success': True}

api.add_resource(endpoint, '/endpoint')

if __name__ == '__main__':
    app.run('<HOST IP>', 666)

Steps to reproduce the behavior

Create container with dockerfile, run the server and container. Every 10th request has a 3s delay.

I’ve been struggling to find a possible reason why, be it network, OS, docker version, python version etc and have not found the cause.

Docker version 18.06.1-ce-win73 (19507)
Any help would be much appreciated!

Cheers!

I don’t see the same behaviour with a docker python alpine image: FROM python:3.7.0-alpine3.8
I’m running the client and server in the same docker network on ubuntu 16.04 LTS.
The 500 requests are handled within 4 seconds.

2 Likes