[erlang-questions] Measuring message queue delay

Sergej Jurečko sergej.jurecko@REDACTED
Wed Apr 29 13:56:10 CEST 2015


Perhaps a crazy idea, but it should work and perform quite well....

Non 18+ compatible solution:
- Keep track of refs. They are monotonically increasing across all
schedulers. Create a timer somewhere that periodically saves to an ets
table {make_ref(),os:timestamp()} (or some other data structure). When
checking how old a message is, find which two refs in ETS your ref belongs
to. That was the timeframe of that message.

18+ compatible solution:
- Do this for every scheduler in the system, because make_ref will be per
scheduler then. For every message, you must call
erlang:system_info(scheduler_id)


Sergej

On Wed, Apr 29, 2015 at 11:12 AM, Roger Lipscombe <roger@REDACTED>
wrote:

> For various reasons, I want a metric that measures how long messages
> spend in a process message queue. The process is a gen_server, if that
> has any bearing on the solution. Also, this is for production, so it
> will be always-on and must be low-impact.
>
> I could do this by timestamping _every_ message sent to the process
> and then reporting the deltas, but I think that's ugly.
>
> I thought of posting a message to self(), with a timestamp and then
> measuring the delta. I could then post another one as soon as that
> message is processed. Obviously, this leaves the process continually
> looping, which is not good.
>
> So, instead, I could use erlang:send_after, but that requires two
> messages: a delayed one triggered by erlang:send_after, and an
> immediate one for measuring the delay.
>
> That's a bit complicated.
>
> Would it be sensible to send a message, with erlang:send_after, with
> the _expected_ timestamp, and then compute the delta from that?
>
> Or, alternatively, what other ways could I measure how long a process
> is taking to handle its message queue?
>
> Thanks,
> Roger.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150429/c8749725/attachment.htm>


More information about the erlang-questions mailing list