Currently in the process of converting an erlang application from version 17 to 18. Scalability and performance are prime directives in the design. The program needs a way to differentiate and sort new input coming in, either with lots of unique monotonically increasing numbers (a continuous stream of them), or some other mechanism. The current version (17) did not use now() for this because it is a scalability bottleneck (global lock), so it made due with reading the clock and doing other things to generate the tags for the data coming in. I'm trying to figure out the best way to do this in 18 and have some interesting results from the tests I've run.
I expected erlang:unique_integer([monotonic]) to have poor results, because I expected it to have a global lock like now(). I expected one of the clock functions to have the best results, assuming the clock could be read in parallel. Instead, erlang:unique_integer([monotonic]) gets the best results out of all the functions I benchmarked, and the clock functions do worse.
Could someone explain the results, tell me which erlang functions SHOULD give the best results, and which things (clocks, number generators, etc) are or are not globally locked in 18? Also, if you see any issues with my test methodology, by all means point them out.
TEST PLATFORM/METHODOLOGY
windows 7 64 bit
erlang otp 18 (x64)
2 intel cores (celeron 1.8GHz)
2 erlang processes spawned to run each test function concurrently 500000 times
for a total of 1000000 times, timed with timer:tc
each test run 10 times in succession and all results recorded
BASELINE TEST, SEQENTIAL
erlang:unique_integer([monotonic])
47000-94000
PARALLEL TIMES
erlang:unique_integer([monotonic])
~94000
ets:update_counter
450000-480000
erlang:monotonic_time
202000-218000
erlang:system_time
218000-234000
os:system_time
124000-141000
calendar:universal_time
453000-530000