themarshallproject / klaxon

Klaxon enables reporters and editors to monitor scores of sites on the web for newsworthy changes.
https://newsklaxon.org
MIT License
646 stars 199 forks source link

Attempting to delete a watched item fails, crashes Heroku #458

Closed immewnity closed 3 years ago

immewnity commented 3 years ago

This only seems to happen if there are a lot of snapshots logged. Same thing happens if I try to delete from the watch list or from the watched item's page.

tommeagher commented 3 years ago

Can you share what it says in your Heroku logs, @immewnity? How many is "a lot" of snapshots?

immewnity commented 3 years ago

723 total snapshots. Looks like it ran out of memory:

2021-03-26T21:01:11.325112+00:00 app[web.1]: Started DELETE "/watching/pages/376-placeholder" for 73.36.186.33 at 2021-03-26 21:01:11 +0000

2021-03-26T21:01:11.678937+00:00 app[web.1]: Processing by PagesController#destroy as HTML

2021-03-26T21:01:11.679439+00:00 app[web.1]:   Parameters: {"authenticity_token"=>"w7cSDJxObsZeEE4kuYAX15Ot+pTbnflNjSmUkvH/xl5GtK7R/WbuuIAsblOVuX4ZtL3t88Ermm7DNlxbuOY4xw==", "id"=>"376-placeholder"}

2021-03-26T21:01:11.975380+00:00 app[web.1]:   AppSetting Exists (3.0ms)  SELECT  1 AS one FROM "app_settings" WHERE "app_settings"."key" = $1 LIMIT $2  [["key", "default_host"], ["LIMIT", 1]]

2021-03-26T21:01:12.003635+00:00 app[web.1]:   User Load (3.2ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]

2021-03-26T21:01:12.120837+00:00 app[web.1]:   Page Load (1.8ms)  SELECT  "pages".* FROM "pages" WHERE "pages"."id" = $1 LIMIT $2  [["id", 376], ["LIMIT", 1]]

2021-03-26T21:01:12.322325+00:00 app[web.1]:    (2.9ms)  BEGIN

2021-03-26T21:01:20.850021+00:00 heroku[web.1]: Process running mem=1116M(218.0%)

2021-03-26T21:01:20.857851+00:00 heroku[web.1]: Error R15 (Memory quota vastly exceeded)

2021-03-26T21:01:20.868952+00:00 heroku[web.1]: Stopping process with SIGKILL

2021-03-26T21:01:21.098690+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/watching/pages/376-placeholder" host=onbs.herokuapp.com request_id=7b832a78-ef03-45f5-9c61-c11cba2ddebe fwd="73.36.186.33" dyno=web.1 connect=1ms service=11978ms status=503 bytes=0 protocol=https

2021-03-26T21:01:21.306340+00:00 heroku[web.1]: Process exited with status 137

2021-03-26T21:01:21.390620+00:00 heroku[web.1]: State changed from up to crashed

Maybe there's a way to run the processes in chunks, so as to not use so much memory? Looks like it's going above 1GB of RAM usage, and the only Heroku plans that allow for that start at $250/month...

tommeagher commented 3 years ago

Hmmm. OK. that is problematic. Will have to see what @GabeIsman thinks about a solution for this.

GabeIsman commented 3 years ago

Yea this is a known issue. We should be deleting the associated change records in constant-sized batches. The easiest workaround for now is to upgrade your Heroku dyno temporarily, perform the expensive operation, and then scale it down again. Heroku charges are prorated in very small increments so this would be cheap. There was some more discussion of this on the user group: https://groups.google.com/g/news-klaxon-users/c/TvJyOJwqC54/m/uztRGvo1AQAJ.

Note that Heroku only shuts down if you exceed 200% of memory capacity. So a standard dyno aught to do the trick.

immewnity commented 3 years ago

That workaround will do! Thanks.