WSGIDaemonProcess output appears to be unaffected by mod_ratelimit output filter
The output/returned data of a WSGI application running in a WSGIDaemonProcess appears to not be effectively throttled by a mod_ratelimit RATE_LIMIT output filter as it should be.
The same file served in the same Apache vhost as a static file through Apache will obey the configured rate limit, while the WSGI application transfer of the same content will run at full wire speed. Examples measured with curl, in a vhost with SetOutputFilter RATE_LIMIT and SetEnv rate-limit 512 to limit transfer speed to 512KB/s:
WSGI app:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 64.0M 100 64.0M 0 0 9362k 0 0:00:06 0:00:06 --:--:-- 10.9M
Apache static file:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 64.0M 100 64.0M 0 0 508k 0 0:02:08 0:02:08 --:--:-- 505k
System: -Ubuntu Trusty x86_64 -Apache 2.4.7-1ubuntu4.18 -mod_wsgi 4.4.21 (but more recent versions do not refer to any similar bugs fixed)
For what it's worth, returning the data from the WSGI app in multiple chunks (yielding 1M chunks from an iterator) makes no difference.
More information: if not using a WSGIDaemonProcess configuration, the mod_ratelimit throttling appears to actually work correctly. So it appears to be specific to this mode of mod_wsgi.
Is there anything else I can do / info I can collect to help with this issue?
When I first dug into the code I couldn't unearth any reason why it would be happening. I haven't had an opportunity to dig further into. it. Just a matter of finding time.
I am not even sure where to suggest you start looking. May well need to take the source code for mod_ratelimit and compile up a special version which can sprinkle with fprintf() statements to dump out details of what it is doing, as same time as also adding debug statements into mod_wsgi.