[squid-dev] [RFC] Refactor HttpHeader

Amos Jeffries squid3 at treenet.co.nz
Wed Jul 29 21:31:58 UTC 2015


On 30/07/2015 9:10 a.m., Kinkie wrote:
> Hi all,
>    I'm starting to work on refactoring HttpHeader to use LookupTable, and
> boy that code is a mess..
> 
> Since it's going to take significant effort, I'd like to get feedback on
> the changes I'd like to implement, so not to end in long discussions later.
> 
> Current data structures:
> HeadersAttrs: static declaration of header name, header ID, header type
> (string/int/etc). Must be sorted by numeric value of ID
> Headers: built at initialization time from HeadersAttrs, it's an array of
> (name, id, type, stats) structs
> ListHeadersArr, GeneralHeadersArr, EntityHeadersArr, RequestHeadersArr,
> ReplyHeadersArr, etc: lists of headers ID (possibly overlapping) which are
> used to generate..
> ListHeadersMask, GeneralHeadersArr, EntityHeadersArr etc: bitmaps used
> (only) by HttpHeaderStats to assemble different stats sets

I seem to recall a hop-by-hop headers lists as well and the
request/reply lists being used by message filtering logic to strip away
invalid and hop-by-hop headers ?

> 
> I would like to turn these into:
> headerTable: LookupTable<>::Record mapping header name to header ID, used
> to generate ...
> headerLookupTable: a fast lookup table of header names to ids
> headerStatsTable: a std::vector<HttpHeaderFieldStat> indexed by header ID
> to collect the statistics currently in Headers[id].stats.
> headerDescription: a std::vector keyed by header ID containing header type
> (currently in Headers[id].type), possibly header name (if useful), a
> bitfield noting if HTTP_HDR{LIST,GENERAL,REQUEST,REPLY,...}.
> 
> There are some possible optimizations, but at a minimum this should help
> keep information more organized while introducing no performance
> regressions.
> What do you think?
> 

In my brief look the other day I thought a small struct {ID, type, group
bitmask} could be used as the EnumType on LookupTable.

LookupTable really only needs a POD type that can be copied cheaply for
its stored type. Enum / int is the simplest of those but not mandatory.

If that works then you can collapse headerLookupTable and
headerDescription into one list that efficiently looks up all data for
the header. Getting rid of the multiple sub-list type arrays.

Amos


More information about the squid-dev mailing list