0

I'm trying to calculate the time between the data sending from my device to azure service bus topic. I have azure function to listen topic. Also, the data I sent to the topic has a DateTime. In azure function, I create new DateTime and minus the DateTime from topic data. it should be give me the time between sending to receiving. However, I got lots of negative data.

    try
    {
        await client.PostAsJsonAsync("api/device", device);
        releaseLoop= true;

    }
    catch (Exception e)
    {
        log.Info("Exception Message: "+e);
    }

    finally
    {
        log.Info($"{data.DeviceName} Total runing time "+(DateTime.UtcNow-data.timerInfo).Milliseconds+"ms");
    }



logInfo from azure function.
2017-11-13T04:44:36.976 3060 ipad Total runing time 412ms
2017-11-13T04:44:36.976 Function completed (Success, Id=57c528fe-589d-4edc-b285-4dfe481f2aee, Duration=119ms)
2017-11-13T04:44:37.427 Function started (Id=33469551-3873-468d-8ecf-df0b72d8e951)
2017-11-13T04:44:36.352 3049 iphone Total runing time 910ms
2017-11-13T04:44:36.352 Function completed (Success, Id=d233a8e7-1852-4d72-a8f6-5ebc9c4b3d36, Duration=130ms)
2017-11-13T04:44:36.368 Function started (Id=ed19f6e8-7db2-440c-872f-205078a6c0f5)
2017-11-13T04:44:36.477 3061 ipad Total runing time -188ms
2017-11-13T04:44:36.477 Function completed (Success, Id=ed19f6e8-7db2-440c-872f-205078a6c0f5, Duration=109ms)
2017-11-13T04:44:36.687 Function started (Id=feee0174-7461-4ab4-939d-48ca8377ae10)
2017-11-13T04:44:36.793 3064 ipad Total runing time -179ms
2017-11-13T04:44:36.793 Function completed (Success, Id=feee0174-7461-4ab4-939d-48ca8377ae10, Duration=117ms)
2017-11-13T04:44:37.191 Function started (Id=487d5657-5433-48f0-b4bb-e24e80375d5a)
2017-11-13T04:44:37.301 3069 surface pro Total runing time -181ms
2017-11-13T04:44:37.301 Function completed (Success, Id=487d5657-5433-48f0-b4bb-e24e80375d5a, Duration=108ms)
2017-11-13T04:44:36.726 3063 iphone Total runing time -143ms
Lawrence song
  • 158
  • 1
  • 15
  • 1
    That's a challenging task. Your device is using its own clock that might not be synchronized in the same manner and precision as the servers executing ASB broker / Functions. May I ask what are you trying to measure? What is it that you're trying to achieve. – Sean Feldman Nov 16 '17 at 00:21
  • We are trying to use azure function to trigger service bus topic. We have lots of devices running on different place. We want to know the time delay between the device sending data and the data save to our database. – Lawrence song Nov 16 '17 at 00:40
  • This will never be accurate for the reason I've mentioned above. Your calculation is based on two different clocks. The closest you'll get is the difference between time (UTC) Functions will report when code is triggered and the [EnqueuedTimeUtc](https://learn.microsoft.com/en-us/dotnet/api/microsoft.servicebus.messaging.brokeredmessage.enqueuedtimeutc?view=azure-dotnet#Microsoft_ServiceBus_Messaging_BrokeredMessage_EnqueuedTimeUtc) on the Brokered Message. Is that what you're doing currently? – Sean Feldman Nov 16 '17 at 01:02
  • Yes,but in this case. I got some negative value. – Lawrence song Nov 16 '17 at 01:19
  • How much negative? Could you add a code example and samples of actual results you got? – Mikhail Shilkov Nov 16 '17 at 06:12
  • maybe 1/4 of total – Lawrence song Nov 16 '17 at 20:43

1 Answers1

0

One approach is to setup a test with both the sender and the listener on the same machine - that avoids clock skew issues.

Mike S
  • 3,058
  • 1
  • 22
  • 12
  • But I need to test the time send to azure service bus from my local. how can i setup the test on the same machine – Lawrence song Nov 16 '17 at 20:37
  • From the network perspective, running from your local machine is the same as running from a device - they're both a hop over the same network. You can run Azure Functions locally (official instructions are at https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local). – Mike S Nov 16 '17 at 20:48
  • Thanks Mike, I'll try run azure function locally. – Lawrence song Nov 16 '17 at 21:21