Skip to content

perf: cache workspace monitoring profile (30s TTL) - #191

Open
quinneydavid wants to merge 1 commit into
DartSteven:mainfrom
quinneydavid:fix/cache-workspace-monitoring-profile
Open

perf: cache workspace monitoring profile (30s TTL)#191
quinneydavid wants to merge 1 commit into
DartSteven:mainfrom
quinneydavid:fix/cache-workspace-monitoring-profile

Conversation

@quinneydavid

Copy link
Copy Markdown

get_workspace_monitoring_profile() is called once per data row by the energy/power/battery history builders, and each call created a fresh SQLAlchemy engine and reflected the entire schema (get_table_names) before reading one row. On a populated DB, single-day history requests took 5-13s and concurrent requests fully serialized.

Cache the result for 30s and invalidate it from the only write path that changes monitoring_profile (update_initial_setup_options).

Measured on a 41k-row single-UPS install:
/api/energy/data?period=today 6.8s -> 0.11s
4 concurrent requests 27.5s -> 0.45s

get_workspace_monitoring_profile() is called once per data row by the
energy/power/battery history builders, and each call created a fresh
SQLAlchemy engine and reflected the entire schema (get_table_names)
before reading one row. On a populated DB, single-day history requests
took 5-13s and concurrent requests fully serialized.

Cache the result for 30s and invalidate it from the only write path
that changes monitoring_profile (update_initial_setup_options).

Measured on a 41k-row single-UPS install:
  /api/energy/data?period=today  6.8s -> 0.11s
  4 concurrent requests          27.5s -> 0.45s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant