apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject Re: how to make apr_bucket_read() read only as much as I need?
Date Fri, 19 Aug 2005 20:56:30 GMT
Joe Orton wrote:
> On Fri, Aug 19, 2005 at 12:07:37AM -0700, Stas Bekman wrote:
>>Joe Orton wrote:
>>>On Thu, Aug 18, 2005 at 06:25:23PM -0700, Stas Bekman wrote:
>>>>when reading from most bucket types you want to read all the data. This 
>>>>is not the case with socket buckets, since the amount of data on the 
>>>>socket can be anything. At the moment the code hardcodes 8K of data is to

>>>>be read. What do I do if I want to control how much data is read from the

>>>Why do you need to do that?  You shouldn't really care.
>>We do care, because we write a throttling filter for the smtp module, so 
>>we want to slow down the spammers, reading 8K defeats the purpose of the 
>>throttling filter (we read like 32B and then sleep), since most spam 
>>messages will be consumed by the server side. that filter will be 
>>available on CPAN once completed.
> Hmmm, tricky.  I would suspect it would be better to achieve this using 
> socket options, though I'm not sure how feasible that is; e.g. try 
> setting SO_RCVBUF to 32.  You really want to prevent the TCP stack from 
> buffering and ACKing the data as well if you want to throttle the sender 
> from the word go.

But that still won't prevent from the bucket socket read function to read 
more than 32, if while it cleans the buffer the OS level keeps on reading 
the data in, is that correct? or is it absolutely sure that the smaller 
buffer size will make sure that the socket buffer will never read more 
than that?

Also while we are at it, do you remember why 8000 was chosen as the size 
of the buffer (I remember why it wasn't 8K, but I wonder why not 2k or 
4k?) is it because it perfectly fits the memory page? but how do you 
ensure that it always starts at the page boundary and not hanging over the 
end of the previous page?

> Otherwise, I guess what you could do here is implement a new bucket 
> type, which is a clone of SOCKET, except it stores a length parameter 
> which is used in the place of APR_BUCKET_BUFF_SIZE on each ->read() 
> invocation; allowing the caller to change the length as necessary using 
> an accessor function.

Right I could do that. But I'll also need to replace the core_in filter, 
since it will use the current socket bucket functionality.

> You can't change the apr_bucket_read() interface itself so I'm not sure 
> exactly what you were trying to do with the changes you mention.

I wasn't trying to, I was just hoping for a quick hack before a clean 
solution is introduced. But never mind, I'll just work on the clean 
solution when we will have time for that.

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

View raw message