Rugby Optimizations

I found that sending a fairly large amount of data from a client to the server takes an enormous amount of time while eating 100% CPU time. After a bit of digging, it turns out that Rugby reads data from the client port 16 bytes at a time, once the data has been transferred into the buffer from the client.
This gives horrendous performance on even small files at 10-50 kb in size, taking several seconds for Rugby to finish reading from the port. Furthermore, a function to detect EOD was performing a FIND on the incoming data on each 16 byte read. As this data grows, the FIND operation slows down a lot.

I patched the source to rugby.r to reduce the size of how much data is fed to the FIND function to 50 bytes of data. Then I also use adaptive resizing of how much data is read from the port, starting out at 4096 bytes from after reading Content-Length: (apparently the maximum allowed size) and then scaling down to 16 bytes when nearing the end.

A small test which took 14 seconds to complete on about 170 kb of data on the original rugby.r, now clocks in at 0.2 to 0.3 seconds!

But there is a small catch: The 16 byte alignment seems to be necessary to read, when getting near the end of data in the buffer. If this alignment isn't there, EOD isn't detected and Rugby hangs. I can presently not be 100% sure that the 16 byte alignment is reached every time with the adaptive resizing, so please test the code well.
|