TPS (throughput) calculation

Hi all,

I’m looking for the solution to calculate the Throughput = (number of requests) / (total time).

I have no issue with the calculation of the requests count

But what is the solution to get the total time and put it into the target formula Throughput = (number of requests) / (total time).?


It seems duration type has constraint → the String type only can be used as a field (had also issues to fetch the duration).

Very much appreciated your support, I will be able to move on with my public project.

I don’t quite follow this point, but in any case to get tps it comes down to how accurate you need this info. The quick and dirty way is to window your data by 1 second intervals, then group and sum as you have. This page is quite long, but covers the entire process quite well.

The harder and more accurate way is to calculate tps as a rolling second . If you go this route, if you are dealing with a lot of data, you probably won’t want to do this operation within a dashboard/query window, since the processing load will grow with number of users viewing the dashboard. Instead, do this process once via a task, and add the output as another measurement, or to another bucket even.

Thanks @FixTestRepeat let me describe with details.

I’m looking for the table like this, I do not need any charts

Request name                             |  TPS  | 
DELETE->Remove Specific Item             |   10  |
GET->Get All Items                       |   20  |

Where TPS = (number of requests) / (total time)

number of requests → count of the items for the specific time range.
total time → the duration in seconds for the specific time range

The specific time range can be

  1. Raw total time. Why raw? → as a total time we are taking the 10 minutes (from user end it is difference between v.timeRangeStart and v.timeRangeStop)

For example in 10 minutes we have the data.

Request name                             | Number of requests | 
DELETE->Remove Specific Item             |         650        |
GET->Get All Items                       |         1200       |

So I need the final result table with calculation

total time in seconds → 10 min * 60 = 600 seconds

Request name                             |   Number of requests/Total time   | 
DELETE->Remove Specific Item             |            650/600                |
GET->Get All Items                       |           1200/600                |
  1. Exact total time. As a total time we are taking the difference between two date time points

Total time = last request "_time" - first request "_time".

Further more, for both cases (1 and 2) total time we need to convert duration to seconds and then to int → to have the possibility to do math deviation.
Any option (1 or 2) is acceptable.

So I do not see the huge complexity here at the first look. The problem that I’m not really understand now to implement the “total time” calculation and type conversion (duration to seconds to int) to have the proper math. One again, the goal is to have one query to build the table.

Hope now I described more clear, many thanks.

BR,
Mike

If you’re looking more at TPS as some average over a longer period like 10mins, maybe take a look at this page

if I understand you I gather it’s not exactly 10mins or you would have just hard coded 600 in there already. So from the example, the time1 and time2 variables could either be input by you , or they could be determined by queries using first() and last() perhaps.

If you then skip step 3 which converts to a duration , then you’ll have a difference between the two Unix seconds timestamps. That should the plug-in to youre existing code? (After converting from nanoseconds to seconds)

time1 = uint(v: 2019-09-17T21:12:05Z)
time2 = uint(v: 2019-09-18T22:16:35Z)
TotalTime = time2 - time1

Thanks I have read this one https://docs.influxdata.com/influxdb/cloud/query-data/flux/manipulate-timestamps/#calculate-the-duration-between-two-timestamps before this topic creation.

I understood that to have a 10 minutes in nanoseconds at least (but I need in seconds) I need to

time1 = uint(v: v.timeRangeStart)
time2 = uint(v: v.timeRangeStop)

TotalTime = time2 - time1

OK if we taking option “1. Raw total time” to take average TPS.

I know how to get count. Then we can play with “map” solution and do the math … or “map” with “join” if we can have calculated the raw TotalTime.

Can you give me advise/example how query should look like at least to execute the code below and get TotalTime with type which is supporting the division?

Hey @FixTestRepeat,

Finally, I have made the query

tpsCalculator = () => {

  count = from(bucket: v.bucket)

  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)

  |> filter(fn: (r) => r["_measurement"] == "requestsRaw")

  |> filter(fn: (r) => r["_field"] == "count")

  |> group(columns: ["requestName"])

  |> count()

  |> toFloat()

  |> group()

  |> keep(columns: ["_value", "requestName"])

  

first = from(bucket: v.bucket)

  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)

  |> filter(fn: (r) => r["_measurement"] == "requestsRaw")

  |> filter(fn: (r) => r["_field"] == "count")

  |> group(columns: ["requestName"])

  |> first()

  |> toFloat()

  |> group()

  |> keep(columns: ["_time", "requestName"])

 last = from(bucket: v.bucket)

  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)

  |> filter(fn: (r) => r["_measurement"] == "requestsRaw")

  |> filter(fn: (r) => r["_field"] == "count")

  |> group(columns: ["requestName"])

  |> last()

  |> toFloat()

  |> group()

  |> keep(columns: ["_time", "requestName"])

  time = join(

      tables:{first:first, last:last},

      on:["requestName"]

    )

    |> map(fn:(r) => ({

             requestName: r.requestName,

             duration: float(v:(int(v:(uint(v: r._time_last) - uint(v: r._time_first))))/1000000000)

                                

    }))   

     return join(

      tables:{time:time, count:count},

      on:["requestName"]

    )

    |> map(fn:(r) => ({

             requestName: r.requestName,

             TPS: float(v: (r._value/r.duration))

                                

    }))   

}

 tpsCalculator()

Thanks for the help anyway.
BR,
Mike

1 Like

Nice one, and thanks for sharing your final result there. Just curious, what your use case is for this function? Are you calling it from grafana or another external script?