Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request | request.files access is too slow. #3546

Closed
kshitij12345 opened this issue Mar 27, 2020 · 4 comments
Closed

Request | request.files access is too slow. #3546

kshitij12345 opened this issue Mar 27, 2020 · 4 comments

Comments

@kshitij12345
Copy link

kshitij12345 commented Mar 27, 2020

Expected Behavior

I am getting very slow access to request.files['file'].
Below is a part of the code.

@app.route('/perspective_transform/', methods = ['POST'])
def perspective_transform():
    print(request)
    with Timer(prefix='API Execution'):
        with Timer(prefix='Loading Image File'):
            file = request.files['file']
            
        with Timer(prefix='Read File'):
            img_bytes = file.read()

        with Timer(prefix='Loading Args'):
            vertices = request.form.get('vertices')

        # Some other processing code
    return response

I would think that once request reaches the Python function, all data is available at that point.
Surprisingly most of the time is spent at file = request.files['file']
Based on my assumption it should be quick. Also the print(request) doesn't take any time at all.
The file that I am trying to get is generally in the range 1Mb to 2Mb.
On some occassion it takes very very long.
Is this the expected behavior?
Any way to mitigate it?

Loading Image File took 0.423 seconds
Read File took 0.001 seconds
Loading Args took 0.000 seconds
API Execution took 0.736 seconds

Environment

  • Python version: 3.7
  • Flask version: 1.1.1
  • Werkzeug version: 1.0.0
@davidism
Copy link
Member

Duplicate of pallets/werkzeug#875

@davidism davidism marked this as a duplicate of pallets/werkzeug#875 Mar 27, 2020
@cauffe

This comment has been minimized.

@ThiefMaster
Copy link
Member

@cauffe Don't do that again.

@kshitij12345
Copy link
Author

@davidism Thanks for the reference and quick reply.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants