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