Logging to one process from thousands: How does it work?
Scott Lystig Fritchie
fritchie@REDACTED
Wed Jan 4 23:37:49 CET 2006
>>>>> "uw" == Ulf Wiger <ulf@REDACTED> writes:
>> How do you implement a bounded queue in Erlang without
>> busy-waiting?
uw> Difficult, but you can achieve back-pressure by making the
uw> communication with the logger synchronous.
How about an unbounded queue that can raise its own priority? Then we
take advantage of the 'high' vs. 'normal' scheduling behavior. I
haven't actually tried *compiling* this code, but hopefully it gets
the idea across.
One potential problem could be that my_recursive_func() stops calling
itself before the number of messages in the queue falls below the low
water mark and then keeps its high priority.
-define(WATERMARK_HIGH, 100).
-define(WATERMARK_LOW, 5).
my_recursive_func(MyState) ->
{message_queue_len, Msgs} = process_info(self(), message_queue_len),
if Msgs > ?WATERMARK_HIGH -> process_flag(priority, high);
Msgs < ?WATERMARK_LOW -> process_flag(priority, normal);
true -> ok
end,
%% Do real stuff here....
-Scott
More information about the erlang-questions
mailing list