" class="title" title="home again woohoo">Home ?> pages bg right
Posted by Bruce on May 27, 2010

Two fixes..For the price of one :)

Wow.. Didnt hope to release fixes so soon.
Yesterday, Jacky Yuen contacted me about a bug in the mod. It didn’t look like
the mod’s fault, but i took a deeper look.

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, doing this, 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.

A windows 2003 server,
and a Windows 7 (32bits) showed the problem (max speed was 490KB/s)
A 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 doesnt 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
So, i wrote 2 fixes. The first one, i didnt 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. Now i’ll be back working on the next release.

– (previous readme.txt text follows dated 24/May/2010)

Again… It has been a while since i’ve upted the code. (work, personal
life, money issues, the same stuff we all fight daily)
However, that doesn’t mean i forgot about it. I’ve just been working my
*** off. I’ve got many emails with suggestions, some bugs, etc..
I’m doing one of the last updates of this line of mod_bw (0.x). It’s
mainly a couple of bugfix, and a little callback to get stats on the running
mod. I hope it wont break anything.. (of course i’ve tested it a lot).

Ah!, i said this is one of the last updates. Yes. This is because this line
of code is limiting the possibilities of the mod, so i’ve started a new mod_bw
using other set of techniques. (so, it is highly experimental, and uses
completely new instructions). This new branch of the mod was born thanks to
the email sent by Borislav Borislavov (icn.bg), who needed some special features
to be implemented, not possible with the current code.
So, if you wanted the mod to do per-ip limiting, traffic limiting, etc..
keep checking my site. I’ll be releasing a new branch of mod_bw to public soon.
(Unfortunately, it won’t be released under the Apache license yet).

Now, back to this mod :

First, i’ve fixed two 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, was 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 simple stat. However, i received many emails asking for this.

This is easy to achieve :

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

Suppose the vhost for :

    SetHandler modbw-handler

Now you can get information of the mod by visiting
You can get the same information in csv format at

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

Post a Comment

24 Responses to “Two fixes..For the price of one :)”

  1. rasta says:


    I have a problem with the download of large files (>4GB) it never seems to finish if the data flow is:
    Client > perl catalyst app making GET > apache > tomcat

    If I’m going directly to Apache it sometimes finishes, but rarely. Usually it seems to brake nearing the end of the download.

    This does not happen if I switch mod_bw off.

    Our config is:
    RedHat, Apache/2.2.15 (Unix), mod_jk/1.2.37, tomcat 6 and mod_bw 0.8

    BandWidthModule On
    ForceBandWidthModule On
    BandWidth all 102400000
    MaxConnection all 3
    xxx.xxx.xxx.xxx.https: Flags [R.], seq 0, ack 141731072, win 3336, options [nop,nop,TS val 1704710538 ecr 1704710385], length 0

    but this happens regardles of the client used (browser, curl, wget…). So I guess the traffic/flow control gets somehow broken. I can sent you the dump of a last couple of seconds where the client sent an ACK but got not reply and then sends reset (in a couple hundred miliseconds while the other ACK-SEQ exchanges seems to happen immediately but I’m not sure if this is the cause of the reset).

    Any idea what could be wrong? Does anyone else have a problem with files >4GB?


  2. rasta says:

    As for my previous comment – this is fixed in v9.02.
    Thanks Ivan!

  3. stimpy says:

    okay.. ..forget about the maxconnection thing.. ..as I said: Stupid me.. ;)
    But what I still don’t get is the status-site..

  4. Bruce says:

    Looks like your email address is not working (or spam safe xD)
    For the status site, you need to use a Location directive inside the vhost. Such as :

    SetHandler server-status

    Then visit your url/bwserver-status and get some stats.
    Let me know if its working..

Leave a Reply