Skip to main content Skip to footer

Search Crosser Knowledge Base

Calculating time differences across messages

Sometimes you want to check the time used by some processing steps, or the time of an external request. This can be done by adding a Time Stamp module before and after the modules you want to measure. Then the Time Difference module can be used to calculate the difference between the two timestamps. This is easy when the two timestamps appear in the same message.

But what if you want to measure the difference between two timestamps that appear in different messages? For example, you want to check the time between messages received through an MQTT Subscriber module. Then you will have a timestamp in each received message, but to calculate the difference you need to get them into the same message.

For the special case where the time is monotonically increasing, which is the case if we for example look at reception times from an external source, there is a trick you can use. It works also for any data, if you are only interested in the absolute difference.

To get the two timestamps into the same message we can use the Statistics module. This module uses a rolling window and calculates some statistics over these windows, like average/min/max. If we set it up to use a window of 2 (two messages), the ‘max’ value will contain the most recent timestamp and the ‘min’ value the previous timestamp. We now have the two timestamps in the same message and can use e.g. the Time Difference module, or the Math module to calculate the difference. Note that the Statistics module only works with numerical data, so you have to generate, or convert, your timestamps as ‘Unix timestamps’, which can be configured in the Time Stamp module.

Crosser Flow Example_Time Modules

About the author

Goran Appelquist

Göran has 20 years experience in leading technology teams. He’s the lead architect of our end-to-end solution and is extremely focused in securing the lowest possible Total Cost of Ownership for our customers.

"Hidden Lifecycle (employee) cost can account for 5-10 times the purchase price of software. Our goal is to offer a solution that automates and removes most of the tasks that is costly over the lifecycle.

My career started in the academic world where I got a PhD in physics by researching large scale data acquisition systems for physics experiments, such as the LHC at CERN. After leaving academia I have been working in several tech startups in different management positions over the last 20 years.

In most of these positions I have stood with one foot in the R&D team and another in the product/business teams. My passion is learning new technologies, use it to develop innovative products and explain the solutions to end users, technical or non-technical."