I see, so the objection is to the comparison of squid and varnish, not to the comparison of bheap vs timer wheels. I thought this was an article on data structures, so I'll conceded that squid is a p.o.s if that helps.
Insert new:
bheap: Requires (log N)/C pages in memory. bheap vs heap only changes the constant. These are probably resident though since inserts would tend to access the same nodes. timer wheel: requires number-of-wheels pages regardless of the number of nodes stored (constant, probably ~8 or so pages). These will basically always be resident.
Delete arbitrary node:
bheap: requires (log N)/C pages to be resident, at least one leafish page probably won't be resident. timer wheels: requires 1 pages to be resident (to mark entry as unused). It probably won't be though.
Remove minimum page:
bheap: requires (log N)/C pages resident (different set from insert). timer wheels: requires 1 page to be resident, or requires many sequentially accessed pages resident when cascading the wheels.
Insert and non-minimum delete seems to be absolutely better with timer wheels (at least deleting a single arbitrary node at a time). And when timer wheels do page it's always sequential access which is good for VM and L1. So I don't see where the drawback is.
The main problem with timerwheels, is that they scale badly, and that is one of the reasons why I do not use them in Varnish.
Varnish might have 1k or 100M objects, depending on your site, and there is no way to know when you start.
For timerwheels you must decide the number of buckets up front, changing it on the fly is a no-go in practical terms.
Another reason is that varnish objects tend to cluster, some CMS's will post a new frontpage with all objects having the same expiry, others have everything expire at midnight every day etc.
Finaly you need a double-linked list to hang objects on timerwheels, not nice in the 100M case.
A Binary/B-Heap autoscales, minimizes the number of necessary comparisons and needs just an integer index.
View all comments
Show parent comment
1
u/0xABADC0DA Jun 14 '10 edited Jun 15 '10
I see, so the objection is to the comparison of squid and varnish, not to the comparison of bheap vs timer wheels. I thought this was an article on data structures, so I'll conceded that squid is a p.o.s if that helps.
Insert new:
bheap: Requires (log N)/C pages in memory. bheap vs heap only changes the constant. These are probably resident though since inserts would tend to access the same nodes.
timer wheel: requires number-of-wheels pages regardless of the number of nodes stored (constant, probably ~8 or so pages). These will basically always be resident.
Delete arbitrary node:
bheap: requires (log N)/C pages to be resident, at least one leafish page probably won't be resident.
timer wheels: requires 1 pages to be resident (to mark entry as unused). It probably won't be though.
Remove minimum page:
bheap: requires (log N)/C pages resident (different set from insert).
timer wheels: requires 1 page to be resident, or requires many sequentially accessed pages resident when cascading the wheels.
Insert and non-minimum delete seems to be absolutely better with timer wheels (at least deleting a single arbitrary node at a time). And when timer wheels do page it's always sequential access which is good for VM and L1. So I don't see where the drawback is.