volto icon indicating copy to clipboard operation
volto copied to clipboard

feat!: new implementation for the proxy middleware.

Open mamico opened this issue 2 years ago • 4 comments

After changing the reverse proxy rules that pointed directly to the backend, to utilize Volto proxy middleware, for binary downloading (i.e., images and files), we noticed a significant drop in performance.

I tried to analyze it and improve it by changing the middleware implementations. This is the checklist that I think needs to be verified/completed:

  • [x] have performance comparable to that of Plone.
  • [x] add x-forwarded headers in the request for the backend.
  • [ ] properly proxying important request/response headers (cache, range, ...) to the backend and browser
  • [x] correctly handle authenticated requests
  • [x] correctly handle p.a.redirector.
  • [ ] handle errors correctly (not found, not authorized, ...)
  • [ ] Add documentation and configurability for integrators

What was tested/measured.

I loaded a 92 MB file into Plone (size is not important, but large files make analysis easier) in a Plone vanilla 6.0.6 installation, waitress, without Zeo server.

Plone apache benchmark: http://localhost:8080/Plone/discord-0-0-29.deb/@@download/file/discord-0.0.29.deb,

Volto main (yarn build and node build/server.js), same Plone site http://localhost:3000/discord-0-0-29.deb/@@download/file/discord-0.0.29.deb

Volto this branch (yarn build and node build/server.js), same Plone site http://localhost:3000/discord-0-0-29.deb/@@download/file/discord-0.0.29.deb

image

Plone has the better performance here, this branch is not so far.

Even comparing the memory usage of the Volto process during testing, a much higher consumption is evident in the current implementation, compared to the proposed one.

image

IMO, the main problem with the current implementation is that all the file content is downloaded into memory before being transmitted to the user. This implementation, on the other hand, streams data from the backend to the client.

mamico avatar Oct 08 '23 06:10 mamico

Deploy Preview for volto ready!

Name Link
Latest commit 531e984ef3d2e324f63e98c3bdf47925a3cf93a0
Latest deploy log https://app.netlify.com/sites/volto/deploys/65491449a1f2d0000878970c
Deploy Preview https://deploy-preview-5299--volto.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Oct 08 '23 06:10 netlify[bot]

@mamico Looks like a really good idea at first glance! I will be traveling home and taking a couple days off, but will try to review this soon.

davisagli avatar Oct 08 '23 07:10 davisagli

@davisagli have you had time to try it?

Regarding "properly handling errors (not found, not authorized, ...)," this does not seem easy with http-proxy-middleware, see https://github.com/chimurai/http-proxy-middleware/issues/179.

On the other hand express-http-proxy has an implementation that enables this functionality, see https://github.com/villadora/express-http-proxy/issues/248.

mamico avatar Nov 06 '23 16:11 mamico

Deploy Preview for plone-components canceled.

Name Link
Latest commit 59577fd5ec39b3ae9e24cec3adf74427ce6c7503
Latest deploy log https://app.netlify.com/sites/plone-components/deploys/6720bc5f9131550008243460

netlify[bot] avatar Sep 25 '24 13:09 netlify[bot]