Is allocations?filter=... API faster than job/{}/allocation?

Hi. Which one of these APIs are expected to be faster?

 job/{}/allocations

or

allocations?filter=JobID="{}"

?

In other words, are all allocations indexed by JobID and job/{} api uses that index, or it doesn’t matter?

Spoke to one of our engineers (who implemented the recent /statuses endpoint and has spent a lot of time thinking about perf here) and this is what they had to say:

I believe /job/{}/allocations is more efficient, because it first finds the job, then uses it to look through a “job” index on the “allocs” table, so it should only traverse the subset of allocs that have that job id. filter is almost always less efficient, because it scans the whole table and only keeps what matches the filter

/allocations can be made somewhat more efficient if you give it a prefix, or a namespace, but otherwise it looks like it scans the whole allocs table

to put it differently, filter doesn’t know anything about indexes. it just looks at all the structs and keeps those that match

Hope this helps!

1 Like