nickva commented on issue #4650:
URL: https://github.com/apache/couchdb/issues/4650#issuecomment-1603005683

   The basic idea for preserving the windowed updates with 10 second windows, 
and 1 second granularity, like we have currently, could be to use at 10 counter 
arrays (in a tuple for instance, to allow quick iteration), one per second:
   
   ```
   Counters = {counters:new(NumberOfBins), counters:new(NumberOfBins), ....}
   ```
   
   So `update(#hist{}, Val)` would do something like `TimeIndex = 
erlang:monotonic_time(second) rem tuple_size(Counters) + 1`, `CounterRef = 
element(TimeIndex, Counters)`.
   
   In order to for the trimmer/cleaner process to not step on the toes of 
current updaters, we'd create 15 or 20 counters, to allow plenty of time in 
between when the trimmer process resets the old counters and some delayed 
updaters still updating it. Using monotonic time prevents the updaters from 
going backwards but there could be some time between them reading the monotonic 
time and the update itself.
   
   In this way we avoid the need to modify (delete old and create new) counter 
arrays in a persistent term. The persistent histogram term structure remains 
immutable. The only thing that gets updated are the counter values themselves 
which should be efficient.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to