Partition counter and spiral writes by erlang:system_info(scheduler_id)
and a bitwise mask. There is also potential for better cache behavior
given the fixed mapping between Erlang scheduler thread and partitioned
key.
Switch spiral and slide_uniform from ordered_set to set. Set supports
fine grained locking whereas ordered_set requires a full-table lock.
Combining set and separating values greatly reduces ETS contention.
Change histogram to avoid an ETS insert if the sample passed into the
histogram update function matches the result.
There are 2 places in folsom where an ets:insert_new is done immediately
followed by an ets:update_counter on the same key. Since, in the normal
case, the key is likely to already exist, this can be optimized by
trying the update_counter first in a try/catch and only do the
insert_new if needed. This is provided as a utility function called
folsom_utils:update_counter().
There is a bug in slide_uniform where it would not decrease the
probability of doing a write the more updates it received in a
particular moment. Effectively slide_uniform updates would always result
in a write. This bug has been corrected, along with the Quickcheck test.
Lots of credit here goes to @jtuple, who did a lot of this work, particularly around partitioning writes to avoid contention. He also wrote the benchmarking code below.
It is also important to note that these speedups are more apparent when you have many concurrent processes writing to a folsom stat. There are also improvements in the single-writer case, but they are not as profound.
Microbenchmark results for folsom master vs adt-speedups (time in seconds):
Changes include:
Partition counter and spiral writes by erlang:system_info(scheduler_id) and a bitwise mask. There is also potential for better cache behavior given the fixed mapping between Erlang scheduler thread and partitioned key.
Switch spiral and slide_uniform from ordered_set to set. Set supports fine grained locking whereas ordered_set requires a full-table lock. Combining set and separating values greatly reduces ETS contention.
Change histogram to avoid an ETS insert if the sample passed into the histogram update function matches the result.
There are 2 places in folsom where an ets:insert_new is done immediately followed by an ets:update_counter on the same key. Since, in the normal case, the key is likely to already exist, this can be optimized by trying the update_counter first in a try/catch and only do the insert_new if needed. This is provided as a utility function called folsom_utils:update_counter().
There is a bug in slide_uniform where it would not decrease the probability of doing a write the more updates it received in a particular moment. Effectively slide_uniform updates would always result in a write. This bug has been corrected, along with the Quickcheck test.
Lots of credit here goes to @jtuple, who did a lot of this work, particularly around partitioning writes to avoid contention. He also wrote the benchmarking code below.
It is also important to note that these speedups are more apparent when you have many concurrent processes writing to a folsom stat. There are also improvements in the single-writer case, but they are not as profound.
Microbenchmark results for folsom
master
vsadt-speedups
(time in seconds):40,000 workers doing 100 writes each:
80,000 workers doing 100 writes each:
Benchmark: