One of the ways that RoboSwarm keeps it’s costs down is by spinning up infrastructure to run load tests on-demand. While great for our customers and us, it does lead to some annoying behavior when it comes to startup times. Very recently we released a feature to help customers understand when their load test will start.

To get the “~121 seconds” and descending number we do a little bit of fancy SQL to determine the average time to create a load testing cluster.
SELECT AVG(
EXTRACT(
EPOCH FROM (
ready_at - created_at
)
)
) as avg_time
FROM swarm
WHERE
ready_at IS NOT NULL
AND
destroyed_at IS NOT NULL
AND id < ?
AND id >= (? - 10)
The above code subtracts the created_at
datetime from the ready_at
datetime, generates the time in seconds, and averages that across the previous 10 load tests from the point where this current load test was created. So why not averaging the last 50 or 100 test startup times? Mainly because the time to create tests has trended down in the past year and we want to give you the most accurate representation.
Generating this with a single query to PostgreSQL is fantastic and removes a lot of overhead and complication from the code base.