Copyright © 2015-2016 Takeru Ohta <phjgt308@gmail.com>
A sink which limits message flow rate of underlying sink
> error_logger:tty(false). % Suppresses annoying warnings for the sake of brevity
> Sink = logi_sink_flow_limiter:new(limiter, logi_sink_console:new(console), [{write_rate_limits, [{1024, 1000}]}]).
> {ok, _} = logi_channel:install_sink(Sink, debug).
> logi:notice("hello world").
2015-11-04 08:59:29.269 [notice] nonode@nohost <0.98.0> erl_eval:do_apply:673 [] hello world
> lists:foreach(fun (I) -> logi:info("hello: ~p", [I]) end, lists:seq(1, 1000)).
2015-11-04 08:59:53.364 [info] nonode@nohost <0.98.0> lists:foreach:1337 [] hello: 1
2015-11-04 08:59:53.365 [info] nonode@nohost <0.98.0> lists:foreach:1337 [] hello: 2
2015-11-04 08:59:53.366 [info] nonode@nohost <0.98.0> lists:foreach:1337 [] hello: 3
2015-11-04 08:59:53.366 [info] nonode@nohost <0.98.0> lists:foreach:1337 [] hello: 4
2015-11-04 08:59:53.366 [info] nonode@nohost <0.98.0> lists:foreach:1337 [] hello: 5
2015-11-04 08:59:53.367 [info] nonode@nohost <0.98.0> lists:foreach:1337 [] hello: 6
2015-11-04 08:59:53.367 [info] nonode@nohost <0.98.0> lists:foreach:1337 [] hello: 7
2015-11-04 08:59:53.368 [info] nonode@nohost <0.98.0> lists:foreach:1337 [] hello: 8
2015-11-04 08:59:53.368 [info] nonode@nohost <0.98.0> lists:foreach:1337 [] hello: 9
2015-11-04 08:59:53.368 [info] nonode@nohost <0.98.0> lists:foreach:1337 [] hello: 10
2015-11-04 08:59:53.369 [info] nonode@nohost <0.98.0> lists:foreach:1337 [] hello: 11
2015-11-04 09:00:45.551 [warning] nonode@nohost <0.113.0> logi_sink_flow_limiter_server:report_omissions:203 [id=sample_limiter] Over a period of 60 seconds, 989 info messages were omitted: channel=logi_default_log, reason=rate_exceeded (e.g. [{pid,module,line},{<0.98.0>,lists,1337}])
option() = {logger, logi:logger()} | {max_message_queue_len, non_neg_integer()} | {write_rate_limits, [write_rate()]}
logger
:
- The logger instance which is used to report internal events (e.g., message discarding) of the sink process
- Default: logi:default_logger()
max_message_queue_len
:
- Maximum message queue length of the writee process of the underlying sink
- While the queue length exceeds the value, messages will be discarded
- default: 256
write_rate_limits
:
- Log messages write rate limit specification
- If all write_rate()
are satisfied, new arrival message will be outputed
- e.g., [{10*1024*1024, 1000}, {500*1024*1024, 60*60*1000}]
: 10MB/seconds and 500MB/seconds
- default: []
options() = [option()]
pos_milliseconds() = pos_integer()
Positive milliseconds
write_rate() = {Bytes::non_neg_integer(), Period::pos_milliseconds()}
Write rate limit specification
InPeriod
milliseconds, it is allowed to write messages of up to Bytes
bytes.
new/2 | Equivalent to new(Sink, BaseSink). |
new/3 | Creates a new sink. |
new(SinkId::logi_sink:id(), BaseSink::logi_sink:sink()) -> logi_sink:sink()
Equivalent to new(Sink, BaseSink).
new(SinkId::logi_sink:id(), BaseSink::logi_sink:sink(), Options::options()) -> logi_sink:sink()
Creates a new sink
Generated by EDoc, Sep 27 2018, 23:13:24.