title: Buffering when serving videos on Flask app in multiple devices
body: <p>I have created a prototype of a website serving two videos via a Flask application. I am currently testing them in flask's dev server but I am facing buffering issues when serving over 3 devices (sometimes with 3 also, but change in buffer size fixed it). Here's what my code looks like:</p>
  
  <pre class="lang-py prettyprint-override"><code>
  def partial_response(path, start, end=None):
      file_size = os.path.getsize(path)
      if(end is None):
          end = start + BUFF_SIZE - 1
      end = min(end, file_size)
      end = min(end, start + BUFF_SIZE - 1)
      length = end - start + 1
  
      #read file
      with open(path, 'rb') as video_file:
          video_file.seek(start)
          bytes = video_file.read(length)
  
      response = Response(
          bytes, 
          206, 
          mimetype=mimetypes.guess_type(path)[0],
          direct_passthrough=True
          )
  
      response.headers.add(
          'Content-Range', 'bytes {0}-{1}/{2}'.format(start, end, file_size)
      )
  
      response.headers.add(
          'Accept-Ranges', 'bytes'
      )
  
      return response
  
  def get_range(req):
      range = req.headers.get('Range')
      print(range)
      m = re.match('bytes=(?P&lt;start&gt;\d+)-(?P&lt;end&gt;\d+)?', range)
      if(m):
          start = int(m.group('start'))
          end = m.group('end')
          if end is not None: 
              end = int(end)
          return [start, end]
      else:
          return [0, None]
  
  @app.route("/two.mp4")
  def two():
      return render_template('watch_video.html', video_name="two.mp4")
  
  @app.route("/static/videos/two.mp4")
  def two_video():
      start, end = get_range(request)
      print(start, end)
      return partial_response("p&lt;ath to two.mp4&gt;", start, end)
  
  if(__name__ == "__main__"):
      app.run(host='0.0.0.0')
  </code></pre>
  
  <p>Can the buffering be due to:</p>
  
  <ol>
  <li>flask and its blocking API? <br></li>
  <li>Buffer size? <br></li>
  <li>Resource capacity of the hosting machine? <br></li>
  <li>Router limitations? <br></li>
  <li>Just bad code? <br></li>
  </ol>
  
  <p>OR may be anything else? I need some guidance.</p>
  
  <p>No of intended devices: 10 <br>
  No of test devices: 5 <br>
  Test video size: 1GB <br></p>