apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@covalent.net
Subject Re: [PATCH] allocate properly-sized buffer for header
Date Thu, 25 Jan 2001 18:27:04 GMT

> Can you put in words and some simple examples what's wrong with the API?

The problem is that it is impossible to do a lot of small writes to a
brigade efficiently.  Take as an example, code that needs to add 20 five
byte buffers to brigade.  There are two options:

1)  bigbuff = apr_pstrcat(p, buf1, buf2, buf3, buf4, buf5, ...);
    b = apr_bucket_make_pool(p, bigbuff);

2)  b = apr_bucket_make_heap(buf1);
    b = apr_bucket_make_heap(buf2);
    b = apr_bucket_make_heap(buf3);

Neither one of these is very good.  The first requires that the person
writing the code do far too much, and it especially falls apart when those
buf's are in different locations in the code.

The second will create 20 small buckets that can't be written to disk or
network efficiently, because we only allow for 16 element iovec's.

The solution the web server has come up with, is to coalesce the buckets
together with a coalesce filter, but we malloc/free each bucket, so that
isn't really a great solution.  Even if we allow for a free list of
buckets, it just isn't a great solution.

A better solution, IMHO, is to allow the brigade code to do the buffering
itself.  Basically, allow a set of functions:


Which allow the programmer to just write

apr_brigade_puts(bb, buf1);
apr_brigade_puts(bb, buf2);

This would create a single bucket that has all 100 bytes from the twenty
buckets.  They would need to be copied, but that is part of buffering.  I
can supply a quick patch, I wrote it for httpd, and it needs to be
modified a bit, because there is some stuff I don't like about it.

Part of the patch that some don't like, is that the buffer is a part of
the brigade, instead of being in the bucket itself.  The reason for this
is simple.  In our current definition, buckets are read-only.  I dislike
creating exceptions for definitions.  For example, putting the data
directly into a bucket, means our defintion becomes:

buckets are read-only, except for this special bucket, which is

The patch will explain it better than I can, so expect it later today.

> I'm asking here as the buckets are part of APR aren't they?


Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131

View raw message