Skip to content

feat(api): Speedier streaming of forecast data#162

Merged
devsjc merged 2 commits into
mainfrom
devsjc/faster-streaming
May 5, 2026
Merged

feat(api): Speedier streaming of forecast data#162
devsjc merged 2 commits into
mainfrom
devsjc/faster-streaming

Conversation

@devsjc
Copy link
Copy Markdown
Contributor

@devsjc devsjc commented May 5, 2026

Contribution Checklist

  • Have you followed the Open Climate Fix Contribution Guidelines?
  • Have you referenced the Issue this PR addresses, where applicable?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added a summary of the changes?
  • Have you written new tests for your changes, where applicable?
  • Have you successfully run make lint with your changes locally?
  • Have you successfully run make test with your changes locally?

Warning

PRs may be closed if all the above boxes are not checked.

Changes in this Pull Request

Modifies the index on the sources materialized view, and updates the underlying sql of the StreamForecastData implementation. Also modifues the schema to take a list of location uuids, and uses the connection pool directly, to enable controllable parallelisation of the query in-api, as opposed to by-client.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

Benchmark Results

Benchmark results
?   	github.com/openclimatefix/data-platform/cmd	[no test files]
?   	github.com/openclimatefix/data-platform/internal/gen/ocf/dp	[no test files]
?   	github.com/openclimatefix/data-platform/internal/interceptors	[no test files]
PASS
ok  	github.com/openclimatefix/data-platform/internal/server/dummy	0.005s
{"level":"debug","time":"2026-05-05T14:10:57Z","message":"Completed migrations"}
goos: linux
goarch: amd64
pkg: github.com/openclimatefix/data-platform/internal/server/postgres
cpu: AMD EPYC 7763 64-Core Processor                
BenchmarkPostgresClient/small/GetForecastAsTimeseries-4         	      68	  16130566 ns/op
BenchmarkPostgresClient/small/GetForecastAtTimestamp-4          	     274	   4220812 ns/op
BenchmarkPostgresClient/small/GetObservationsAsTimeseries-4     	     903	   1262189 ns/op
BenchmarkPostgresClient/small/CreateForecast-4                  	      88	  13040860 ns/op
BenchmarkPostgresClient/small/StreamForecastData-4              	      12	 112371981 ns/op
PASS
ok  	github.com/openclimatefix/data-platform/internal/server/postgres	71.592s
?   	github.com/openclimatefix/data-platform/internal/server/postgres/gen	[no test files]
Benchmark vs base branch
goos: linux
goarch: amd64
pkg: github.com/openclimatefix/data-platform/internal/server/postgres
cpu: AMD EPYC 7763 64-Core Processor                
                                                   │ bench-main.txt │  bench-devsjc-faster-streaming.txt   │
                                                   │     sec/op     │    sec/op     vs base                │
PostgresClient/small/GetForecastAsTimeseries-4         16.51m ± ∞ ¹   16.13m ± ∞ ¹       ~ (p=1.000 n=1) ²
PostgresClient/small/GetForecastAtTimestamp-4          4.200m ± ∞ ¹   4.221m ± ∞ ¹       ~ (p=1.000 n=1) ²
PostgresClient/small/GetObservationsAsTimeseries-4     1.273m ± ∞ ¹   1.262m ± ∞ ¹       ~ (p=1.000 n=1) ²
PostgresClient/small/CreateForecast-4                  13.00m ± ∞ ¹   13.04m ± ∞ ¹       ~ (p=1.000 n=1) ²
PostgresClient/small/StreamForecastData-4                             112.4m ± ∞ ¹
geomean                                                5.821m         10.47m        -0.60%
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05

@devsjc devsjc merged commit b25ddbe into main May 5, 2026
4 checks passed
@devsjc devsjc deleted the devsjc/faster-streaming branch May 5, 2026 14:12
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