After reviewing the source code, I am still not 100% sure how write_expire is implemented.
Basically, I want to know if I have a table with n elements, and each element should expire 1 minute after its insertion - will bro loop over all elements in the list checking if they are expired ?
if this is the case then write_expire should be O(n), is this correct ?
the main function implementing expiry is TableVal::DoExpire in Val.cc
(approximately line 2175).
Basically, I want to know if I have a table with n elements, and each
element should expire 1 minute after its insertion - will bro loop over all
elements in the list checking if they are expired ?
Yes, Bro will loop over all elements from time to time, setting internal
timeouts that cause a loop over the whole table removing expired elements.
Note that elements are not guaranteed to expire after the expiration time;
they will be removed sometime after expiration time, but it can take a
bit.
if this is the case then write_expire should be O(n), is this correct ?
To clarify because there could be different interpretations here: it's
indeed O(n) for the whole expire operation, however that is amortized
over a longer time frame: when Bro iterates over the table, it works
on short slices at a time (which is the reason that it can take longer
to expire an element, as Johanna wrote). So it's not O(n) for each
table operation or such.
I have a couple of bro policies in production where I store/expire/extend hundreds of thousands (if not million+) elements/records from table(s). SO far has been operationally workable. Offcourse, the expirations don't happen at the dot on the clock but often little later but that doesn't concern much.