December 13th Tuesday (十二月 十三日 木曜日)

Buckets and Brigades

  Buckets and brigades is a kind of stream representation in Apache.  It can be passed through a layered I/O system
without unnecessary copying.  It forms the basis of Apache's data handling, I/O, and filter chain.

  A Bucket brigade is a doublely linke list (ring) of buckets.  Buckets are passed around only as members of a brigade,
although singleton buckets can occur for short periods of time.

  Buckets are data stores of various types. They can refer to data in memory, or part of a file or mmap area, or the output
of a process, among other things.

  The following bucket types are supported natively in APR:

* File--bucket contents are a file. Commonly used when serving a static file.
* Pipe--bucket contents are a pipe (filesystem FIFO).
* Socket--bucket contents are a socket. Most commonly used by the network filters. stdio-like buffered I/O.
* Heap--bucket contents are heap memory. Used for
* Mmap--bucket contents are an mmapped file.
* Immortal--bucket contents are memory, which is guaranteed to be valid for at least the lifetime of the bucket.
* Pool--bucket contents are allocated on a pool.
* Transient--bucket contents may go out of scope and disappear.
* Flush(metadata)--the brigade’s contents should be flushed before continuing. In Apache, that means passing whatever data
is available to the next filter in the chain.
* EOS (metadata)--end of data.The following bucket types are supported natively in APR:
* File--bucket contents are a file. Commonly used when serving a static file.
* Pipe--bucket contents are a pipe (filesystem FIFO).
* Socket--bucket contents are a socket. Most commonly used by the network filters. stdio-like buffered I/O.
* Heap--bucket contents are heap memory. Used for
* Mmap--bucket contents are an mmapped file.
* Immortal--bucket contents are memory, which is guaranteed to be valid for at least the lifetime of the bucket.
* Pool--bucket contents are allocated on a pool.
* Transient--bucket contents may go out of scope and disappear.
* Flush(metadata)--the brigade’s contents should be flushed before continuing.  In Apache, that means passing whatever data
is available to the next filter in the chain.
* EOS (metadata)--end of data.

  Other types may also be implemented--indeed, additional metadata types are used internally in Apache.  This author has implemented
bucket types for SQL queries (using apr_dbd) and for script fragments; both of these types execute and convert data to another bucket
type when read.

  Buckets also have some type-dependent accessor functions:

  Thereadfunction returns the address and size of the data in the bucket. If the data isn’t in memory, then it is read in and the bucket
changes type so that it can refer to the new location of the data. If all of the data cannot fit in the bucket, then a new bucket is inserted
into the brigade to hold the rest of it.

  The split function divides the data in a bucket into two regions. After a split, the original bucket refers to the first part of the data
and a new bucket inserted into the brigade after the original bucket refers to the second part of the data.  Reference counts are maintained
as necessary.

  Thesetasidefunction ensures that the data in the bucket has an adequate lifetime. For example, sometimes it is convenient to create a bucket
referring to data on the stack in the expectation that it will be consumed (e.g., output to the network) before the stack is unwound. If that
expectation turns out not to be valid, the setaside function is called to move the data somewhere safer.

  Thecopyfunction makes a duplicate of the bucket structure as long as it’s possible to have multiple references to a single copy of the data
itself.  Not all bucket types can be copied.

  The destroy function maintains the reference counts on the resources used by a bucket and frees them if necessary.

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值