" 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. Rigoku says:

    Nice work master… :P

    PD: Y los tragos cuando?? xD

  2. Bruce says:

    Cuando se haga tiempo, nos ponemos de acuerdo ;)

  3. shinn says:

    sorry to post here, but another main link can’t be comment.

    i have windows + apache 2.2.8 + mod_bw v0.91, i want to limit bandwidth to flash video(.flv), but the result not match the Configuration.

    My Configuration to make a real slow download speed for test:
    BandwidthModule On
    AddOutputFilterByType MOD_BW text/html text/plain application/x-httpd-php flv-application/octet-stream video/x-flv
    BandWidth all 1024
    MinBandWidth all 512
    MaxConnection all 2

    html,php: 92k/76 sec, correct.
    flv:9583k/120 sec, wrong, download as 80k per second.

    another question, “MaxConnection all 2″ means 2 connections per ip or per vhost?


  4. Bruce says:

    Don’t be sorry. That’s the purpose of the blog :D

    For the first question , i think your apache install doesn’t know the mime type video/x-flv. Could you check that your httpd.conf is including a valid mime.types file, and that last file has the entry for that mime type ? (I’ve tested your configuration, and it worked fine. Got flv downloading reaaaal sloooow)

    For the second : MaxConnections means connections per vhost. This module (up to 1.00) will not be able to do per ip limiting. Next version will be able to do this, and it is under heavy testing now. (i hope to release it before July).

  5. shinn says:

    It’s working, the reason is i have do a stupid thing.
    html on localhost but flv link to internet.

    hope i can see it soon, thanks.

  6. Dan says:

    ap_get_server_banner() is not available until httpd/2.2.4 it should use ap_get_server_version() (or whatever equiv) instead when mod_bw.so is built/running under 2.0

    1) httpd v2.0.63

    2) 1st lines in httpd.conf:

    ExtendedStatus On
    LoadModule bw_module modules/mod_bw.so

    3) problem:

    root@dan [/usr/local/apache]# ./bin/apachectl configtest
    Syntax error on line 2 of /usr/local/apache/conf/httpd.conf:
    Cannot load /usr/local/apache/modules/mod_bw.so into server: /usr/local/apache/modules/mod_bw.so: undefined symbol: ap_get_server_banner
    root@dan [/usr/local/apache]#

    Note: I hope this is the correct place for this report. The place where says “If you have any comments, bug reports, feature request, etc, post it right here.” there is no link …

  7. Bruce says:

    Thanks Dan!
    This is the correct place to tell. (i meant the webpage with “here”) :)

    I’ll set up a http v2.0 to test and make a fix.

  8. pd says:

    You forgot to call timeEndPeriod. :)

  9. Bruce says:

    Let’s say it was on purpose :X

  10. sheppert says:

    will there be any update in the near future?

Leave a Reply