# How to measure the delay in node red between the mqtt gateway

**URL:** <https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396>\
**Category:** General\
**Tags:** node-red-dashboard, mqtt\
**Created:** [28 November 2022 18:10 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396 "2022-11-28T18:10:14Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Johnson](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@Johnson](https://discourse.nodered.org/u/Johnson)\
**Post date:** [28 November 2022 18:10 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396/1 "2022-11-28T18:10:14Z")

</div>

I am new to node red .  
I would like to know if there is a node that can be used to measure the delay between the nodes in node red flow

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [28 November 2022 18:45 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396/2 "2022-11-28T18:45:31Z")

</div>

There is a nice simple subflow you can import and use to measure time between 2 points...

[https://flows.nodered.org/flow/63f29373e826a9fd4943d679d43e725f](https://flows.nodered.org/flow/63f29373e826a9fd4943d679d43e725f)

---

<div class="post-metadata">

**Author:** ![Johnson](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@Johnson](https://discourse.nodered.org/u/Johnson)\
**Post date:** [29 November 2022 08:36 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396/3 "2022-11-29T08:36:38Z")

</div>

Thank you for your reply. I will work with it .

---

<div class="post-metadata">

**Author:** ![Johnson](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@Johnson](https://discourse.nodered.org/u/Johnson)\
**Post date:** [29 November 2022 12:42 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396/4 "2022-11-29T12:42:50Z")

</div>

Is it possible to store the values of the start and end values from the flow timer

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [29 November 2022 13:53 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396/5 "2022-11-29T13:53:01Z")

</div>

sure, you can do anything.

As it states in the readme the results are delivered in the `msg` and stored in `global` context...

> ### The results (msg)...
> 
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/a/0a6edfb646472b2d3a02e42e837c79e975e7a308.png)
> 
> ### The results (global)...
> 
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/7/5726c433d4b5225942d20f7bac0b7a2c827374c4.png)

You can do whatever you want with them

---

<div class="post-metadata">

**Author:** ![Johnson](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@Johnson](https://discourse.nodered.org/u/Johnson)\
**Post date:** [30 November 2022 08:32 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396/6 "2022-11-30T08:32:00Z")

</div>

Thank you .i will try it

---

<div class="post-metadata">

**Author:** ![Johnson](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@Johnson](https://discourse.nodered.org/u/Johnson)\
**Post date:** [30 November 2022 09:27 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396/7 "2022-11-30T09:27:08Z")

</div>

I have one more question regarding the flow timer , when it measure the start time and stop time does it inputs any delay ?  
ie,the duration is the time taken just to complete the flow or does the flow timer node add any extra time.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [30 November 2022 10:07 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396/8 "2022-11-30T10:07:36Z")

</div>

> [@Johnson](#):
>
> ie,the duration is the time taken just to complete the flow or does the flow timer node add any extra time

I am 100% certain this node will add some time (it is code after all) but is likely immeasurable (like 1 ms or less). Why not give it a go? Put a start and a stop without anything in between. Run it a few times. What value do you get? If you consistently get 2ms then either deduct 2ms from other results or accept it is good for +/- 2ms.

If you are after solid accuracy with zero jitter and determinism, then you are on the wrong platform 😉

My recommendation is when assessing the performance of a piece of code is first - don't (unless you know you have a problem). Next, run the timer against multiple (hundreds/thousands) of iterations several times over (to get an average).

---

<div class="post-metadata">

**Author:** ![Johnson](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@Johnson](https://discourse.nodered.org/u/Johnson)\
**Post date:** [30 November 2022 10:52 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396/9 "2022-11-30T10:52:24Z")

</div>

Ok .Thank you once again for explaining in detail.

---

<div class="post-metadata">

**Author:** ![Johnson](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@Johnson](https://discourse.nodered.org/u/Johnson)\
**Post date:** [1 December 2022 13:43 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396/10 "2022-12-01T13:43:49Z")

</div>

I have 1 more question ,in the document it is given the time is measured in MS but is there any way to measure it in microseconds?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 December 2022 14:14 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396/11 "2022-12-01T14:14:27Z")

</div>

Sure, if you modify it to use [performance hooks](https://nodejs.org/docs/latest-v16.x/api/perf_hooks.html) or [process.hrtime.](https://nodejs.org/docs/latest-v16.x/api/process.html#processhrtimetime)

But seriously, what are you trying to measure?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [1 December 2022 14:14 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396/12 "2022-12-01T14:14:30Z")

</div>

Not with that node. In theory you could create your own functions and use the [nodejs hrtime](https://nodejs.org/api/process.html#processhrtimetime) capability to do it - but then you really will be into the timing of the actual measurement calls affecting the result. And given that nodejs is running async processes on top of a non-realtime operating system there will potentially be lots of other things occurring in the system that would affect the accuracy tolerance of any measurement. As @Steve-Mcl suggested the simplest way would really to measure many thousands of operations and then divide... but one has to ask why do you need such accuracy ?

---

<div class="post-metadata">

**Author:** ![Johnson](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@Johnson](https://discourse.nodered.org/u/Johnson)\
**Post date:** [1 December 2022 15:43 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396/13 "2022-12-01T15:43:57Z")

</div>

So i am trying to find delay in a mqtt gateway .

---

<div class="post-metadata">

**Author:** ![Johnson](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@Johnson](https://discourse.nodered.org/u/Johnson)\
**Post date:** [1 December 2022 15:47 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396/14 "2022-12-01T15:47:29Z")

</div>

thank you for your reply. It is just that i wanted to know how much accurate it is .But as @Steve-Mcl answered i tried as he said and understood that the node will add some time .

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 December 2022 16:06 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396/15 "2022-12-01T16:06:38Z")

</div>

> [@Johnson](#):
>
> i am trying to find delay in a mqtt gateway

Do you mean between a publish and receiving the new value?

How consistent are the figures that you are getting? There is no point going to microseconds unless the millisecond figure is consistent.

---

<div class="post-metadata">

**Author:** ![Johnson](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@Johnson](https://discourse.nodered.org/u/Johnson)\
**Post date:** [5 December 2022 17:32 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396/16 "2022-12-05T17:32:44Z")

</div>

Sorry for the late response.  
Actually i have not started with mqtt part .  
As a beginner ,i am just trying with some samples flows and trying to understand the working.

---

<div class="post-metadata">

**Author:** ![Johnson](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@Johnson](https://discourse.nodered.org/u/Johnson)\
**Post date:** [5 December 2022 17:35 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396/17 "2022-12-05T17:35:39Z")

</div>

i have one question regarding the storing of data. As you mentioned that values can be stored in global context.  
is it possible to export into the excel .  
I did some research and found a node called csv .But is it possible to get the start,stop and duration values into the excel.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 December 2022 17:49 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396/18 "2022-12-05T17:49:38Z")

</div>

Please start a new thread since this is a new topic.

---

<div class="post-metadata">

**Author:** ![Johnson](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@Johnson](https://discourse.nodered.org/u/Johnson)\
**Post date:** [5 December 2022 18:55 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396/19 "2022-12-05T18:55:23Z")

</div>

Okay .i shall start a new thread

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 February 2023 18:55 UTC](https://discourse.nodered.org/t/how-to-measure-the-delay-in-node-red-between-the-mqtt-gateway/71396/20 "2023-02-03T18:55:40Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
