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

Slow writes for large response body for HTTPS connection #133

Closed
1 of 3 tasks
nav-agarwal opened this issue Oct 20, 2018 · 5 comments · Fixed by #134
Closed
1 of 3 tasks

Slow writes for large response body for HTTPS connection #133

nav-agarwal opened this issue Oct 20, 2018 · 5 comments · Fixed by #134
Labels
bug Something is broken enhancement Improvement

Comments

@nav-agarwal
Copy link

nav-agarwal commented Oct 20, 2018

I'm submitting a ...

  • bug report
  • feature request
  • question about the decisions made in the repository

Describe the bug. What is the current behavior?

Performance Bug
Slow writes observed(<2MB/permin) in case of large response body(around 300MB) when using HTTPS connection

What is the motivation / use case for changing the behavior?
Poor download performance for HTTPS connection on local server

To Reproduce

Steps to reproduce the behavior:

  1. Setup HTTPS cherrypy server
import cherrypy
class Root(object):
   @cherrypy.expose
   def index(self):
       cherrypy.log("Inside index")
       buff = "a" * 1024 * 1024 * 300
       return buff

if __name__ == '__main__':
   config = {
           'server.ssl_certificate': 'cert.pem',
           'server.ssl_private_key': 'privkey.pem',
           'server.ssl_module' : 'pyopenssl',
   }
   cherrypy.config.update(config)
   cherrypy.quickstart(Root())
  1. Make requests
import requests
r = requests.post("https://localhost:8080", verify=False)

Expected behavior
On HTTP connection same requests finishes within seconds

Details
Root Cause:Bug is due to following code in write function of makefile. This function is used for HTTPS connection writes only:
data = data[bytes_sent:]
Here we are copying almost complete buffer after every socket write. In python. slices leads to copy of remaining buffere as strings are immutable.
Possible fix:
Do chunking in small buffers by matining idx till which write has happened

Environment

  • Cheroot version: 6.5.2
  • CherryPy version: 17.4.0
  • Python version: 2.7.13
  • OS: Ubuntu 14.04.5 LTS
  • Browser: -

Additional context
Performance Bug

@webknjaz webknjaz added bug Something is broken enhancement Improvement labels Oct 20, 2018
@webknjaz
Copy link
Member

Hey @nav-agarwal,

Thanks for reporting this! I assume you've made a typo in requests code (you wrote http), am I right?

P.S. Your explanation makes a lot of sense. Would you be interested in submitting that as a PR?

@webknjaz
Copy link
Member

@nav-agarwal try out #134

Also, have you tried Python 3 version? It should be better optimized.

@nav-agarwal
Copy link
Author

@webknjaz :

  1. I have corrected http to https in my request code
  2. I will try to test it with python3 and upload results in couple of days, but my gut feeling is that it will have same problems.

@webknjaz
Copy link
Member

@nav-agarwal are you happy with the latest fix? #137

@nav-agarwal
Copy link
Author

@webknjaz : Fix is working fine. Thanks for the quick fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken enhancement Improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants