publiclab / plots2

a collaborative knowledge-exchange platform in Rails; we welcome first-time contributors! :balloon:
https://publiclab.org
GNU General Public License v3.0
957 stars 1.83k forks source link

Typeahead on [srch/notes] paralyzes app #4661

Closed icarito closed 5 years ago

icarito commented 5 years ago

@steviepubliclab reported this afternoon that the website was slow, and referenced Skylight. Analysis shows the relevant is srch/notes. @milaaraujo let me know if I can help debug.

image image

milaaraujo commented 5 years ago

Code:

milaaraujo commented 5 years ago

Do you know where the endpoint is used on the site?

jywarren commented 5 years ago

Thanks I'll try to look more into this soon... Saw another potential instance of this today reported by @skillfullycurled

https://oss.skylight.io/app/applications/GZDPChmcfm1Q/1548196200/57m/endpoints

jywarren commented 5 years ago

Could it have been a direct search at /search/notes?

jywarren commented 5 years ago

Oh sorry @skilfullycurled, misspelled

skilfullycurled commented 5 years ago

@jywarren That's on me. It's what happens when it's 2008, get your first domain, and then make everything consistent without realizing the implications for your future. I've been meaning to change it.

icarito commented 5 years ago

image image

Indeed same issue I think. I agree with @milaaraujo we should look into reducing our database of inactive users or only query those. @skilfullycurled - certainly not all things work all the time, thanks for the positive input!

skilfullycurled commented 5 years ago

not all things work all the time

Actually, now that I think on it, that'd probably make for a good 500 error page.

I'm going to go submit a feature request.

Brb.

jywarren commented 5 years ago

Found the endpoint: it's on https://publiclab.org/post

image

I think this has potential for optimization in both JavaScript and in the back-end, and has a lot in common with: https://github.com/publiclab/plots2/issues/4670

icarito commented 5 years ago

Today we had another dramatic slowdown for about an hour at 6:30PM - 7:30PM UTC. image.

icarito commented 5 years ago

I have checked the logs and found that the flurry of searches stems from typeahead search indeed!

icarito commented 5 years ago
[379a8f91-10e2-455a-b7f0-8df2f702f782] Started GET "/api/srch/notes?query=Soil%20Contm" for REDACTED at 2019-02-11 18:14:09 +0000
[2901cf71-76e8-478b-b9f1-3adf97080251] Started GET "/api/srch/notes?query=Soil%20Cont" for REDACTED at 2019-02-11 18:14:13 +0000
[fea79ecd-0375-454f-9ec0-141a29100b1d] Started GET "/api/srch/notes?query=Soil%20Conta" for REDACTED at 2019-02-11 18:14:13 +0000
[743a9606-c694-4f47-867f-0ac58ea6b8eb] Started GET "/api/srch/notes?query=Soil%20Contam" for REDACTED at 2019-02-11 18:14:14 +0000
[564a2877-ae95-4992-8c75-5a60e59d389d] Started GET "/api/srch/notes?query=Soil%20Contami" for REDACTED at 2019-02-11 18:14:17 +0000
[9ae08d81-5486-4d62-9003-32035186d299] Started GET "/api/srch/notes?query=Soil%20Contamin" for REDACTED at 2019-02-11 18:14:17 +0000
[a9dca184-9a03-4db6-82a8-599afe62ac5a] Started GET "/api/srch/notes?query=Soil%20Contamina" for REDACTED at 2019-02-11 18:14:21 +0000
icarito commented 5 years ago

As a workaround to prevent user experience degradation we might want to throttle the API endpoint?

I also like the idea of issuing typeahead requests every few seconds if the entry input has changed, rather than onChange.

icarito commented 5 years ago

image

This is happening now on any keypress, even arrow keys!

I've made https://github.com/publiclab/plots2/pull/4841 hopefully it will help!

icarito commented 5 years ago

image

The more one types the longer it takes for the API to respond I guess it's slowing down due to the many requests. It'd be cool to cache responses in Javascript. Also I noticed even empty string and one or two chars are being queried (I thought minLength: 3 was meant to avoid this?).

jywarren commented 5 years ago

Thanks, @icarito i'm traveling now so didn't see this. Merged https://github.com/publiclab/plots2/pull/4841 and thanks -- remaining tasks for optimizing are listed at:

Closing this now to focus on those!