Skip to content

Bandwidth Mod : Two fixes .. One strike

Jacky Yuen contacted me about a bug in the mod. It didn’t look like the mod’s fault, but …

The issue :

On his windows server (win2003, and XP) the mod was working, but was unable to reach high speeds (1MB/s). (i heard something like this before, and all you need is to change the packet size).
However, that didn’t fix the issue. I tried this on my server, and i was able to get about 500KB/s. Setting the packet size to 16384 gave me 1MB/s. Jacky told me he still had problems, so i tried all windows systems i got around.

Windows 2003 server, and Windows 7 (32bits) showed the problem (max speed was 490KB/s). Windows 7 64bits and Win 2003 SP2 didnt.

The most awesome part, is that if you run Google Chrome, a Flash application, or Windows Media Player, the mod is able to deliver up to 1MB/s.

Took me a while, but i found that Windows doesn’t run a high resolution timer all the time. In the servers with the issue, the timer run every 10 ms.
Whenever you run some of the mentioned apps, they set the timer to the highest speed possible (in my equipment, 1 ms). This setting affects all other applications, so the mod was able to sleep small times to deliver data as it needed.
So, i wrote 2 fixes. The first one, i didn’t wanted to, but i made the mod to set the timer to the highest resolution possible (it is written to the logs if you want to peek). And the second, is to avoid waiting small times to send data. Minimum time to sleep is 200ms now, and data is adjusted for this. (only for windows). Both fixes are under defines that will compile just for windows, so linux users won’t notice any changes.

The good thing, for windows users, is that with this fixes, i’ve been able to get speeds up to 2.45MB/s under windows!. Using apache by itself, i just got 1.2MB/s. Just enabling the mod and setting a high limit, the speed got pumped up.

That’s it. For that at least.

  • I’ve fixed two additional annoying bugs.
  • MinBandWidth -1 was screwing things up sometimes. All because i was using an unsigned integer to store the -1. Yeah, my bad.
  • The limiting handler was leaking memory. A few bytes at a time, but for large files (really, really large) this could mean one of the apache childs consuming almost all memory. Thanks to Christian Spielberger who insisted and helped me to find this. (i was sure there was something.. but my servers recycle apache childs pretty often).
  • Fun Fact : I found the bug while cleaning my test code, and he sent me an email with the exact same solution i came up. Great minds think alike, eh ? :)

Then, i made a status callback for the mod. This callback will show some stats on the running mod, for each memory segment used to limit bandwidth.
Is it a really simple stat, but many people seemed to want it. I received *many* emails asking for this.

This is easy to achieve now :

In your “admin” vhost (if you have one.. If not, any vhost), use a location to set a handler for the callback.

Suppose the vhost for 127.0.0.1 :

<location /modbw>
  SetHandler modbw-handler
</location>

Now you can get information of the mod by visiting https://127.0.0.1/modbw
You can get the same information in csv format at https://127.0.0.1/modbw?csv

Please, test this changes, let me know how it works.
If you have some ideas (i.e. information to add in the stats), contact me. If it can or can’t be done in this branch of the mod, i’ll let you know.

Published inApachemod_bw
Ivn Systems/Software ©2020