[undertow-dev] ResponseRateLimitingHandler questions

ralf_boogie_blues at bluewin.ch ralf_boogie_blues at bluewin.ch
Sun Nov 2 10:30:40 EST 2014


Hi Stuart
Thanks a lot for the ResponseRateLimitingHandler. I played a little bit with this handler and do have some questions.
I added some trace logs in order to understand the logic. Of course, I didn't understand everything;-) May you will correct me.
First, I tested the download response with a 1 MBytes file. The response limit was set to 100000 Bytes/s. This should download the whole file in about 10s but the result was 18s.
Then, I started to dig into the handler.
How I cReated the handler.
final ResponseRateLimitingHandler responseLimiter = new ResponseRateLimitingHandler(proxy, 100000, 1, TimeUnit.SECONDS);
The trace logs showed me this (with the settings above):
the handler writes chunks as big as the buffer is defined, I think on my machine 16KBytes.
it repeats this until the bytes written are greater than the rate limit.
then, the handler calculates the time to sleep until the next chunks can be written.
Problem 1: The handler writes always more than the specified limit. Because of this, the handler calculates n * units for the time to sleep. So, in my test the handler slept always 2s instead of 1s.
Problem 2: The size of the chunks is probably too static. I think the chunks should be size relatively to the rate limit.
I changed the handler slightly in this way:
I introduced along to the existing parameters also a chunkSize.
canSend(): if (byteCount < (bytes - chunks)) {     return true;    }  // it doesn't write anymore than allowed
handleWritten(long written): nextSendTime = startTime + time;  // instead of: nextSendTime = startTime + (units * time);
writeFinal and transferFrom writes not more than bytes <= chunkSize.
This changes gave me the expected result of about 10s download time.
This is quite a long mail :-) It could be still a mistake I did. Let me know what you think.
Regards, Ralf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20141102/b8151106/attachment.html 


More information about the undertow-dev mailing list