0
0
Fork 0
mirror of https://github.com/matrix-org/dendrite synced 2024-11-14 22:01:13 +01:00
dendrite/mediaapi
Neil Alexander 6d4bd5d890
Rate limiting changes (#2519)
* Rate limiting changes

This makes the following changes:

* For logged in users, the rate limiting now applies to the device session rather than the remote IP address;
* For non-logged in users, the rate limiting continues to apply to remote address as it does today;
* It is now possible to add user IDs to the `exempt_user_ids` option under `rate_limiting` to exclude bots from rate limiting;
* Admin and appservice users are now exempt from rate limiting by default.

* Fix build with media API
2022-06-07 14:24:04 +01:00
..
fileutils - Removed double imports (#1989) 2021-09-08 17:31:03 +01:00
routing Rate limiting changes (#2519) 2022-06-07 14:24:04 +01:00
storage Global database connection pool (for monolith mode) (#2411) 2022-05-03 16:35:06 +01:00
thumbnailer 🏗️ mediaapi/thumbnailer: fix build with bimg (#2440) 2022-05-09 17:51:30 +01:00
types Refactor media storage layer, add tests (#2352) 2022-04-14 13:32:48 +01:00
bimg-96x96-crop.jpg use go module for dependencies (#594) 2019-05-21 21:56:55 +01:00
mediaapi.go Define component interfaces based on consumers (1/2) (#2423) 2022-05-05 13:17:38 +01:00
nfnt-96x96-crop.jpg use go module for dependencies (#594) 2019-05-21 21:56:55 +01:00
README.md Update Docker files and remove references to gb (#703) 2019-05-22 10:44:25 +01:00

Media API

This server is responsible for serving /media requests as per:

http://matrix.org/docs/spec/client_server/r0.2.0.html#id43

Scaling libraries

nfnt/resize (default)

Thumbnailing uses https://github.com/nfnt/resize by default which is a pure golang image scaling library relying on image codecs from the standard library. It is ISC-licensed.

It is multi-threaded and uses Lanczos3 so produces sharp images. Using Lanczos3 all the way makes it slower than some other approaches like bimg. (~845ms in total for pre-generating 32x32-crop, 96x96-crop, 320x240-scale, 640x480-scale and 800x600-scale from a given JPEG image on a given machine.)

See the sample below for image quality with nfnt/resize:

bimg (uses libvips C library)

Alternatively one can use go build -tags bimg to use bimg from https://github.com/h2non/bimg (MIT-licensed) which uses libvips from https://github.com/jcupitt/libvips (LGPL v2.1+ -licensed). libvips is a C library and must be installed/built separately. See the github page for details. Also note that libvips in turn has dependencies with a selection of FOSS licenses.

bimg and libvips have significantly better performance than nfnt/resize but produce slightly less-sharp images. bimg uses a box filter for downscaling to within about 200% of the target scale and then uses Lanczos3 for the last bit. This is a much faster approach but comes at the expense of sharpness. (~295ms in total for pre-generating 32x32-crop, 96x96-crop, 320x240-scale, 640x480-scale and 800x600-scale from a given JPEG image on a given machine.)

See the sample below for image quality with bimg: