call times

So I was curious how long the various Spark.* cloud calls take, and thought that other people may be interested as well. I wrote a quick script to test the time for the Spark.publish function, and in general I was seeing an average of around 470 µs. This seems to be connection dependent however, as when I mess with the connection by hammering my internet connection with other data, the times sometimes jump up to a second or so.

I’m not entirely sure of the best way to test Spark.variable. I wrote this bit to monitor the times outside of the loop() function, because it’s my understanding that the updates to the cloud occur outside the loop. With this I’m seeing a pretty consistent time of about 2000-5000 µs, with no change when a call to the API is made. I also don’t see a change within the loop either, it’s pretty consistently ~1000 µs+ 1s delay. If someone has a better way to test this, I’m all ears.

I didn’t bother trying to test Spark.function, as it would seem to me to be highly dependent on what the function does.

Great investigation! For testing Spark.function() you could create a function that simply does nothing other than log the time. Then you can measure the function call latency from issuing the REST request to the spark receiving the response.

1 Like

I could be mistaken, but isn’t this rather similar to this:

1 Like

@Moors7 I don’t think so. The latency described there is “The amount of time for a Spark.function or Spark.variable style API request to return. (i.e. this number subtracts time associated with DNS or Internet hops outside of the Spark Cloud.)” Which I interpret as the time for the cloud to return a request within itself. So total time for a Spark.function call would be:

  1. One way latency from REST client to Spark Cloud +
  2. Spark cloud Latency +
  3. One way Latency from Spark cloud to Spark core +
  4. Time for Spark core to process function call +
  5. One way Latency from Spark core back to cloud +
  6. latency from cloud back to rest client

Items 1,3,5, and 6 depend on network traffice, item 2 is my understanding of what the status page quotes, and I’m mainly interested in item 4, which depends on the code. Could be wrong though.

1 Like