nthacker February 2016

pubnub calculate publish latencies

I'd like to calculate PubNub publish latencies for PubNub clients before they actually begin publishing. Is there a preferred way to to this for PubNub?

To make my use case more clear, Im trying to synchronize clients, and these clients do not need to be synchronized at a wall-clock time, since they could be global. Hence this solution, wouldnt be necessary in my case (but it did point me in the right direction)

So I could still obtain a per-client latency calculation based on the above link, but that's for fetching the timestoken using the Time API. This was relevant for the above use-case which depended on clients syncing to a particular wall-clock time, hence a time-token was anyways required to be fetched

However in my case I dont need a timetoken. All clients can be synced using a simple wait for (k - latency) interval where k is a constant for all clients .

Therefore while I can use the timetoken method of calculating latency, I would prefer to know the actual publish latencies (unless there is no vast difference between the two)


nthacker February 2016

Here are some steps I worked out myself to determine latency for publish

  1. determine the local time (in milliseconds): start = now()
  2. Client sends out a message with payload[ {"Type" = "latencyCheck"}, {"me" = "MyPubNubUUID" }]
  3. When Client receives message of the above signature with its own Id, it sets another variable end = now()
  4. latency to send a message and receive it yourself was : end - start

Post Status

Asked in February 2016
Viewed 3,346 times
Voted 6
Answered 1 times


Leave an answer