Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adaptation options can be slow to load #160

Open
eatyourgreens opened this issue Oct 14, 2024 · 4 comments
Open

Adaptation options can be slow to load #160

eatyourgreens opened this issue Oct 14, 2024 · 4 comments

Comments

@eatyourgreens
Copy link
Contributor Author

I've been testing this to see if #159 slowed down the Adaptation tab, but I also see the same slow performance prior to that PR (v0.4.12.)

@eatyourgreens
Copy link
Contributor Author

eatyourgreens commented Oct 15, 2024

The request for a single page (20 items) of adaptation options is taking 36s, for this particular query.

The Chrome dev console showing the response timings for a single page of the adaptation options table. Waiting for the server takes up 36s.

This is the slow request in the code. It's only slow when the total number of items is large, so maybe this is a slow table scan in Postgres?

const response = await apiClient.features.featuresReadSortedFeatures({
...layerSpec,
fieldGroup,
field,
dimensions: JSON.stringify(fieldDimensions),
parameters: JSON.stringify(fieldParams),
page,
size: pageSize,
});

The same query takes 395ms in the backend running locally, so I'm inclined to think the deployed database is missing an index somewhere.

@tomalrussell
Copy link
Member

Just had a quick look from here, can confirm the above. There are two main API calls for data here:

@eatyourgreens
Copy link
Contributor Author

eatyourgreens commented Oct 15, 2024

POST /api/attributes/adaptation

data loader triggered multiple times from the map, posts a list of feature IDs, returns values to map to feature colour
timings look relatively slow from 100ms up to ~15s waiting on server response
visible change is as the map features turn from grey to shades of blue
https://jamaica.infrastructureresilience.org/api/attributes/adaptation?layer=road_edges_metro&field=avoided_ead_mean&dimensions=%7B%22hazard%22%3A%22flooding%22%2C%22rcp%22%3A%224.5%22%2C%22adaptation_name%22%3A%22Elevate%20the%20roads%22%2C%22adaptation_protection_level%22%3A2.5%7D&parameters=%7B%7D

I've rolled the deployed Docker image back to 0.4.12, to remove changes I made to the data loaders yesterday. I'm still seeing these POST requests taking a long time, so I don't think I broke anything in #159. Loading large numbers of features seems to be intrinsically slow.

This URL should work with 0.4.12 (there was a bug in 0.4.12 that broke the map for the URL that I posted at the top of this issue.)
https://jamaica.infrastructureresilience.org/adaptation?lat=18.00478&lon=-76.88483&zoom=10.98&assets=true&hazards=false&buildings=false&buildingsStyle=type&regions=false&regionsStyle=boundaries&terrestrialStyle=landuse&droughtStyle=adaptation&hazardsStyle=&marineStyle=habitat&assetsStyle=adaptation&drought=false&terrestrial=false&marine=false&netTree=11,11

Running the backend locally, with docker compose, those same POST requests to get the adaptation colours take between 8ms and ~200ms.

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

No branches or pull requests

2 participants