Skip to content

Instantly share code, notes, and snippets.

@cnolanminich
Last active October 1, 2025 14:15
Show Gist options
  • Select an option

  • Save cnolanminich/23739d22f310eb71d8a24ab9e639febd to your computer and use it in GitHub Desktop.

Select an option

Save cnolanminich/23739d22f310eb71d8a24ab9e639febd to your computer and use it in GitHub Desktop.
Get historical concurrency for Dagster OSS instance
with seconds_in_day as (
select generate_series(0, 86400 - 1) as sec
)
, base_days as (
select generate_series(current_date - 7,current_date,'1 day'::interval) as days
),
days_and_seconds as (
select
base_days.days,
base_days.days + (seconds_in_day.sec || ' seconds')::interval as start_bucket,
--dateadd(second, seconds_in_day.sec, base.d) as start_time,
base_days.days + (seconds_in_day.sec + 5 || ' seconds')::interval as end_bucket
-- dateadd(second, seconds_in_day.sec + 5, base.d) as end_time,
from base_days
join seconds_in_day on seconds_in_day.sec % 5 = 0
),
concurrency_times as (
select
days_and_seconds.days,
days_and_seconds.start_bucket,
--dateadd(second, seconds_in_day.sec, base.d) as start_time,
days_and_seconds.end_bucket,
-- dateadd(second, seconds_in_day.sec + 5, base.d) as end_time,
count(runs.run_id) as runs_running
from days_and_seconds
left join runs
on to_timestamp(runs.start_time) < days_and_seconds.end_bucket
and (to_timestamp(runs.end_time) > days_and_seconds.start_bucket or runs.end_time is null)
and date_trunc('day', to_timestamp(runs.end_time) ) = days_and_seconds.days
group by 1,2,3
)
select
days::date as run_date,
percentile_cont(.05) within group (order by runs_running)::int as _5th_percentile,
percentile_cont(.25) within group (order by runs_running)::int as _25th_percentile,
percentile_cont(.5) within group (order by runs_running)::int as _50th_percentile,
percentile_cont(.75) within group (order by runs_running)::int as _75th_percentile,
percentile_cont(.9) within group (order by runs_running)::int as _90th_percentile,
percentile_cont(.95) within group (order by runs_running)::int as _95th_percentile,
max(runs_running) as max_concurrent_runs
from concurrency_times
group by days
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment