You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Raul Dias <ra...@dias.com.br> on 2003/12/10 17:35:13 UTC
[MP2] Bandwidth Meterer
Hi,
I am trying to write a Bandwidth Meter with mod_perl 2.
However, the speed which a filter reads/write the data does not
correspond to the speed which the data will flow thru the network.
Is there a way to let $f->print($buffer) BLOCK until the data has flow
thru the network? Or some similar process to get the actual delay which
the data flows?
Thanks,
Raul Dias
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: [MP2] Bandwidth Meterer
Posted by Stas Bekman <st...@stason.org>.
Raul Dias wrote:
[...]
> AFAIU the way that the apache 2 filter work, there is a core filter that
> is the last one to receive the buckets and is responsible to deploy it
> to the network socket.
>
> I am assuming that apache2 filter model can work like regular shell
> pipes like:
>
> reader | filter1 | filter_n | core_out
>
> In this traditional model, filter_n will write to STDOUT and block until
> core_out reads the data from STDIN.
> core_out will start by reading from the STDIN (and BLOCKING until there
> is data to read), and the send them to the network socket.
> In a normal operation, writing to a TCP socket will also block until an
> ACK has being received.
> Until the ACK is gotten, core_out will not read from the STDIN and so
> filter_n will be BLOCKED when it tries to write to STDOUT.
> (of course, core_out could be doing select to avoid blocking and
> buffering the STDIN).
>
> In a model like this, it becomes easier to measure the bandwith.
But Apache filters don't work like shell pipes. There is no pipeline, since
there is only one process that moves its control from one filter to another.
This section explains how the blocking works:
http://perl.apache.org/docs/2.0/user/handlers/filters.html#Blocking_Calls
> Now, using $f->read() / $f->print($buffer) it seems that the generated
> buckets are buffered regardless of how many are generated.
>
> This way even a large file passes thru the filter in a few miliseconds
> while it might take some seconds to be fully downloaded in the
> destination.
>
> So a mechanism for signaling when the output bucket brigade has being
> consumed by the next filter (core out) would be enought (or a start for
> doing what is needed).
>
> By reading the filters chapter in the user's manual, it looks like that
> $r->rflush() sould be the answer. However It did not seem to resolve
> and by this message
> http://marc.theaimsgroup.com/?l=apache-modperl&m=103847990813285&w=2 it
> is not working yet.
I think that is working now, have you tried that? (this message is 1 year
old). If it doesn't you have to step through with debugger and find the filter
that doesn't handle FLUSH buckets correctly.
I think that's the only way you could try to achive what you are planning to.
But it depends on how well behaved filters are. If any of the filters in the
stack doesn't respect the FLUSH bucket there is not much your filter can do.
Your filter can also add FLUSH buckets, though you will need to work with
bucket brigades and not the simplified streaming API.
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: [MP2] Bandwidth Meterer
Posted by Raul Dias <ra...@dias.com.br>.
On Wed, 2003-12-10 at 17:09, Stas Bekman wrote:
> Raul Dias wrote:
> > Hi,
> >
> > I am trying to write a Bandwidth Meter with mod_perl 2.
> >
> > However, the speed which a filter reads/write the data does not
> > correspond to the speed which the data will flow thru the network.
> >
> > Is there a way to let $f->print($buffer) BLOCK until the data has flow
> > thru the network? Or some similar process to get the actual delay which
> > the data flows?
>
> I don't think I understand your question. How a filter can emulate the delay
> of the network which is an unknown factor which it's supposed to measure?
AFAIU the way that the apache 2 filter work, there is a core filter that
is the last one to receive the buckets and is responsible to deploy it
to the network socket.
I am assuming that apache2 filter model can work like regular shell
pipes like:
reader | filter1 | filter_n | core_out
In this traditional model, filter_n will write to STDOUT and block until
core_out reads the data from STDIN.
core_out will start by reading from the STDIN (and BLOCKING until there
is data to read), and the send them to the network socket.
In a normal operation, writing to a TCP socket will also block until an
ACK has being received.
Until the ACK is gotten, core_out will not read from the STDIN and so
filter_n will be BLOCKED when it tries to write to STDOUT.
(of course, core_out could be doing select to avoid blocking and
buffering the STDIN).
In a model like this, it becomes easier to measure the bandwith.
Now, using $f->read() / $f->print($buffer) it seems that the generated
buckets are buffered regardless of how many are generated.
This way even a large file passes thru the filter in a few miliseconds
while it might take some seconds to be fully downloaded in the
destination.
So a mechanism for signaling when the output bucket brigade has being
consumed by the next filter (core out) would be enought (or a start for
doing what is needed).
By reading the filters chapter in the user's manual, it looks like that
$r->rflush() sould be the answer. However It did not seem to resolve
and by this message
http://marc.theaimsgroup.com/?l=apache-modperl&m=103847990813285&w=2 it
is not working yet.
Regards,
Raul Dias
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: [MP2] Bandwidth Meterer
Posted by Stas Bekman <st...@stason.org>.
Raul Dias wrote:
> Hi,
>
> I am trying to write a Bandwidth Meter with mod_perl 2.
>
> However, the speed which a filter reads/write the data does not
> correspond to the speed which the data will flow thru the network.
>
> Is there a way to let $f->print($buffer) BLOCK until the data has flow
> thru the network? Or some similar process to get the actual delay which
> the data flows?
I don't think I understand your question. How a filter can emulate the delay
of the network which is an unknown factor which it's supposed to measure?
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html